diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d47aa..b5b0551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ As documented in the README's [adopting](README.md#how-to-adoptcustomize-the-scr For those who follow this repo, here's the changelog for ease of adoption: +### 1.0-39 + +* Introduced [a new script](scripts/cleanup-browser-profiles.sh) to cleanup browser profiles folders. +* *[fresh-install-of-osx.sh]* Minor refactoring to enhance `clone_repo_into` to handle an optional target git branch which is also validated. + ### 1.0-38 * *[.aliases]* Added extra checks for the `status_all_repos` and `count_all_repos` utility functions. @@ -53,7 +58,7 @@ For those who follow this repo, here's the changelog for ease of adoption: ### 1.0-32 -* *[fresh-install-of-osx]* Added date calculation in `fresh-install-of-osx.sh` to track total execution time. +* *[fresh-install-of-osx.sh]* Added date calculation in `fresh-install-of-osx.sh` to track total execution time. ### 1.0-31 diff --git a/Extras.md b/Extras.md index bc497ff..f534a14 100644 --- a/Extras.md +++ b/Extras.md @@ -19,6 +19,10 @@ Note: This script is useful to capture the preferences of the known applications (both system-installed and custom-installed applications) using the `defaults read` command. It can be used to both export the preferences/settings (from the old system) or import them (into the new system) +## cleanup-browser-profiles.sh + +This script is used to cleanup browser profiles folders (delete cache, session and other files that will anyways be recreated when you restart that browser). It can be safely invoked even if that browser is running (in which case it will skip processing after printing a warning to quit that application) + ## osx-defaults.sh This script is the erstwhile script to codify the macos setup. It can be used to setup some options, but it hasn't been maintained for newer versions of macos. Though the system will not get corrupted, there might be cruft introduced into the system preferences which might not be easy to identify and remove at a later point in time. Use caution and YMMV. diff --git a/files/--HOME--/.aliases b/files/--HOME--/.aliases index 3eef6ae..b9a72ad 100644 --- a/files/--HOME--/.aliases +++ b/files/--HOME--/.aliases @@ -33,20 +33,18 @@ command_exists ncdu && alias du='ncdu --color dark -r -x --exclude .git --exclud # git commands # Note: Use a function so that it can accept parameters +_git_cmd() { + section_header "Processing ${1}" + git -C "${1}" "${2}" +} st() { - local target="${1:-$(pwd)}" - section_header "Processing ${target}" - git -C "${target}" st + _git_cmd "${1:-$(pwd)}" st } cc() { - local target="${1:-$(pwd)}" - section_header "Processing ${target}" - git -C "${target}" cc + _git_cmd "${1:-$(pwd)}" cc } count() { - local target="${1:-$(pwd)}" - section_header "Processing ${target}" - git -C "${target}" count + _git_cmd "${1:-$(pwd)}" count } if command_exists 'run_all.sh'; then diff --git a/files/--HOME--/.shellrc b/files/--HOME--/.shellrc index 3cd75df..11fb303 100644 --- a/files/--HOME--/.shellrc +++ b/files/--HOME--/.shellrc @@ -113,7 +113,23 @@ blue() { printf "${BLUE}${1}${NC}" } +light_blue() { + printf "${LIGHT_BLUE}${1}${NC}" +} + +purple() { + printf "${PURPLE}${1}${NC}" +} + +light_purple() { + printf "${LIGHT_PURPLE}${1}${NC}" +} + cyan() { + printf "${CYAN}${1}${NC}" +} + +light_cyan() { printf "${LIGHT_CYAN}${1}${NC}" } @@ -121,10 +137,18 @@ green() { printf "${GREEN}${1}${NC}" } +light_green() { + printf "${LIGHT_GREEN}${1}${NC}" +} + red() { printf "${RED}${1}${NC}" } +light_red() { + printf "${LIGHT_RED}${1}${NC}" +} + yellow() { printf "${YELLOW}${1}${NC}" } @@ -148,7 +172,7 @@ error() { } section_header() { - echo "$(blue "==> ${1} <==")" + echo "$(blue '==>') $(purple "${1}")" } is_non_zero_string() { @@ -255,6 +279,10 @@ build_keybase_repo_url() { echo "keybase://private/${KEYBASE_USERNAME}/${1}" } +folder_size() { + echo $(cyan "$(\du -sh "${1}" | cut -f1)") +} + # if is_macos; then # Uninstall and reinstall xcode (useful immediately after upgrade or if reinstalling the OS) # TODO: Kept for reference purposes diff --git a/files/--HOME--/Brewfile b/files/--HOME--/Brewfile index c8fd145..42f0e03 100644 --- a/files/--HOME--/Brewfile +++ b/files/--HOME--/Brewfile @@ -11,7 +11,6 @@ # Upgrades and cleans up all regular outdated casks and libs (non-greedy) # TODO: Need to find cask for: -# Ghostty # Tinkertool # ZoomHider @@ -90,7 +89,6 @@ cask 'vscodium@insiders' # TODO: Doesn't handle 'Remote Containers' and GH-bas cask 'zen-browser@twilight' cask 'zoom' - brew 'mas' mas 'PDFgear', id: 6469021132 @@ -182,6 +180,7 @@ end # ---- casks # cask 'cloudflare-warp' # cask 'dbeaver-community' +# cask 'ghostty' # cask 'git-credential-manager' # https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git # cask 'intellij-idea-ce' # cask 'kdiff3' diff --git a/files/--PERSONAL_PROFILES_DIR--/.envrc b/files/--PERSONAL_PROFILES_DIR--/.envrc index 041d240..ab31da4 100644 --- a/files/--PERSONAL_PROFILES_DIR--/.envrc +++ b/files/--PERSONAL_PROFILES_DIR--/.envrc @@ -8,7 +8,7 @@ type is_non_zero_string &> /dev/null 2>&1 || source "${HOME}/.shellrc" replace_dir_if_exists_and_is_not_symlinked() { local target="${PERSONAL_PROFILES_DIR}/${2}" - ! is_directory "${1}" && ! is_directory "${target}" && warn "skipping symlinking $(basename "${2}") since either source or target don't exist!!!" && return + ! is_directory "${1}" && ! is_directory "${target}" && warn "skipping symlinking '${2}' since either source or target don't exist!!!" && return mkdir -pv "$(dirname "${1}")" "${target}" diff --git a/scripts/capture-defaults.sh b/scripts/capture-defaults.sh index 0c34b6d..59b36e5 100755 --- a/scripts/capture-defaults.sh +++ b/scripts/capture-defaults.sh @@ -55,6 +55,7 @@ ensure_dir_exists "${target_dir}" # PDFgear app_array=( + 'app.zen-browser.zen' 'ch.protonvpn.mac' 'com.0804Team.KeyClu' 'com.abhishek.Clocker' @@ -158,6 +159,7 @@ app_array=( 'com.macpaw.site.theunarchiver' 'com.microsoft.rdc.macos' 'com.microsoft.VSCodeInsiders' + 'com.mitchellh.ghostty' 'com.mowglii.ItsycalApp' 'com.piriform.ccleaner' 'com.raycast.macos' diff --git a/scripts/cleanup-browser-profiles.sh b/scripts/cleanup-browser-profiles.sh new file mode 100755 index 0000000..a6d81b9 --- /dev/null +++ b/scripts/cleanup-browser-profiles.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env zsh + +# vim:filetype=zsh syntax=zsh tabstop=2 shiftwidth=2 softtabstop=2 expandtab autoindent fileencoding=utf-8 + +# This script is used to cleanup browser profiles folders (delete cache, session and other files that will anyways be recreated when you restart that browser). It can be safely invoked even if that browser is running (in which case it will skip processing after printing a warning to quit that application) + +type is_non_zero_string &> /dev/null 2>&1 || source "${HOME}/.shellrc" + +check_app() { + if is_non_zero_string "$(pgrep "${1}")"; then + warn "Shutdown '${1}' first!; skipping processing of files for ${1}" + return 1 + else + return 0 + fi +} + +find_and_destroy() { + find "${1}" -type "${2}" -iname "${3}" -delete +} + +vacuum_browser_profile_folder() { + local profile_folder="${2}" + ! is_directory "${profile_folder}" && warn "skipping processing of '${profile_folder}' since it doesn't exist" && return + + section_header "Vacuuming '${1}' in '${profile_folder}'..." + echo "--> Size before: $(folder_size "${profile_folder}")" + + command_exists sqlite && find "${profile_folder}" -type f -iname '*.sqlite' -exec sqlite3 -line {} "VACUUM; REINDEX;" \; + + file_array=( + '.DS_Store' + '.localized' + '.parentlock' + '*.log' + '*.sqlite-shm' + '*.sqlite-wal' + '*.bak*' + 'compatibility.ini' + 'extensions.rdf' + 'msgFilterRules.dat' + 'popstate.dat' + 'sessionstore.bak' + 'signons*.txt' + '*healthreport*' + 'global-messages-db.sqlite' + ) + for file in "${file_array[@]}"; do + find_and_destroy "${profile_folder}" 'f' "${file}" + done + + directory_array=( + 'ABphotos' + 'bookmarkbackups' + 'sessionstore-backups' + 'GoogleContacts' + "Local\ Folders" + 'lnubackups' + 'minidumps' + 'SDThumbs' + "smart\ mailboxes" + 'startupCache' + 'thumbnails' + '*telemetry*' + 'weave' + 'crashes' + '*healthreport*' + ) + for directory in "${directory_array[@]}"; do + find_and_destroy "${profile_folder}" 'd' "${directory}" + done + + echo "--> Size after: $(folder_size "${profile_folder}")" + success "Successfully processed profile folder for '${1}'" +} + +process_browser() { + check_app "${1}" && vacuum_browser_profile_folder "$@" +} + +# TODO: Commented out since I am moving away from Arc and will delete that folder completely +# process_browser arc "${PERSONAL_PROFILES_DIR}/ArcProfile" +process_browser brave "${PERSONAL_PROFILES_DIR}/BraveProfile" +# TODO: Commented out since I haven't tested that this works without losing auto-recreated data +# process_browser chrome "${PERSONAL_PROFILES_DIR}/ChromeProfile" +process_browser firefox "${PERSONAL_PROFILES_DIR}/FirefoxProfile" +process_browser thunderbird "${PERSONAL_PROFILES_DIR}/ThunderbirdProfile" +process_browser zen "${PERSONAL_PROFILES_DIR}/ZenProfile" diff --git a/scripts/fresh-install-of-osx.sh b/scripts/fresh-install-of-osx.sh index b20a21a..59a1a54 100755 --- a/scripts/fresh-install-of-osx.sh +++ b/scripts/fresh-install-of-osx.sh @@ -32,22 +32,30 @@ set_ssh_folder_permissions() { } clone_repo_into() { - ensure_dir_exists "${2}" - if ! is_git_repo "${2}"; then + local target_folder="${2}" + ensure_dir_exists "${target_folder}" + if ! is_git_repo "${target_folder}"; then local tmp_folder="$(mktemp -d)" git -C "${tmp_folder}" clone -q "${1}" . - mv "${tmp_folder}/.git" "${2}" - git -C "${2}" checkout . - git -C "${2}" submodule update --init --recursive --remote --rebase --force + mv "${tmp_folder}/.git" "${target_folder}" + git -C "${target_folder}" checkout . + git -C "${target_folder}" submodule update --init --recursive --remote --rebase --force rm -rf "${tmp_folder}" - success "Successfully cloned '${1}' into '${2}'" + success "Successfully cloned '${1}' into '${target_folder}'" + + local target_branch="${3}" + if is_non_zero_string "${target_branch}"; then + git -C "${target_folder}" switch "${target_branch}" + local checked_out_branch="$(git -C "${target_folder}" branch --show-current)" + [[ "${checked_out_branch}" != "${target_branch}" ]] && error "'${target_branch}' is not equal to the branch that was checked out: '${checked_out_branch}'; something is wrong. Please correct before retrying!" + fi else - warn "Skipping cloning of '${1}' since '${2}' is already a git repo" + warn "Skipping cloning of '${1}' since '${target_folder}' is already a git repo" fi } clone_omz_plugin_if_not_present() { - clone_repo_into "${1}" "${ZSH_CUSTOM}/plugins/$(basename "${1}")" + clone_repo_into "${1}" "${ZSH_CUSTOM}/plugins/${1##*/}" } replace_executable_if_exists_and_is_not_symlinked() { @@ -189,11 +197,7 @@ if is_non_zero_string "${DOTFILES_DIR}" && ! is_git_repo "${DOTFILES_DIR}"; then rm -rf "${ZDOTDIR}/.zshrc" # Note: Cloning with https since the ssh keys will not be present at this time - clone_repo_into "https://github.com/${GH_USERNAME}/dotfiles" "${DOTFILES_DIR}" - - git -C "${DOTFILES_DIR}" switch "${DOTFILES_BRANCH}" - local_branch="$(git -C "${DOTFILES_DIR}" branch --show-current)" - [[ "${local_branch}" != "${DOTFILES_BRANCH}" ]] && error "'DOTFILES_BRANCH' env var is not equal to the branch that was checked out: '${local_branch}'; something is wrong. Please correct before retrying!" + clone_repo_into "https://github.com/${GH_USERNAME}/dotfiles" "${DOTFILES_DIR}" "${DOTFILES_BRANCH}" append_to_path_if_dir_exists "${DOTFILES_DIR}/scripts" @@ -355,8 +359,8 @@ if is_non_zero_string "${KEYBASE_USERNAME}"; then if is_non_zero_string "${KEYBASE_PROFILES_REPO_NAME}" && is_non_zero_string "${PERSONAL_PROFILES_DIR}"; then clone_repo_into "$(build_keybase_repo_url "${KEYBASE_PROFILES_REPO_NAME}")" "${PERSONAL_PROFILES_DIR}" - # Clone the natsumi-browser repo into the ZenProfile/Profiles/chrome folder - is_directory "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/" && clone_repo_into "git@github.com:greeeen-dev/natsumi-browser" "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/chrome" + # Clone the natsumi-browser repo into the ZenProfile/Profiles/chrome folder and switch to the 'dev' branch + is_directory "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/" && clone_repo_into "git@github.com:vraravam/natsumi-browser" "${PERSONAL_PROFILES_DIR}/ZenProfile/Profiles/chrome" dev else warn "skipping cloning of profiles repo since either the 'KEYBASE_PROFILES_REPO_NAME' or the 'PERSONAL_PROFILES_DIR' env var hasn't been set" fi diff --git a/scripts/recreate-repo.sh b/scripts/recreate-repo.sh index 4a8be53..97acf42 100755 --- a/scripts/recreate-repo.sh +++ b/scripts/recreate-repo.sh @@ -35,7 +35,7 @@ fi ! is_git_repo "${folder}" && error "'${folder}' is not a git repo. Please specify the root of a git repo to proceed. Aborting!!!" # For the profiles repo alone, I don't care about retaining the history -[[ "$(basename "${folder}")" == "${KEYBASE_PROFILES_REPO_NAME}" ]] && force=Y +[[ "${folder##*/}" == "${KEYBASE_PROFILES_REPO_NAME}" ]] && force=Y echo "$(yellow 'Processing folder'): '${folder}'" echo "$(yellow "Squash commits (will lose history!)"): '${force}'" @@ -86,7 +86,7 @@ eval "SKIP_SIZE_BEFORE=1 ${git_cmd} cc" if [[ "${git_url}" =~ 'keybase' ]]; then echo "$(blue 'Recreating') '$(yellow "${git_url}")'" - git_remote_repo_name="$(basename "${git_url}")" + local git_remote_repo_name="${git_url##*/}" keybase git delete -f "${git_remote_repo_name}" keybase git create "${git_remote_repo_name}" fi