Skip to content

Commit

Permalink
fix asdf prune unused, disable thumbnail for screenshots, karabiner u…
Browse files Browse the repository at this point in the history
…pdate
  • Loading branch information
nonrational committed Oct 15, 2024
1 parent a0a4299 commit b5921ea
Show file tree
Hide file tree
Showing 6 changed files with 588 additions and 417 deletions.
2 changes: 1 addition & 1 deletion .githelpers
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ delete_remoteless_branches_interactive(){
python3 $HOME/bin/git-broom.py
}

delete_all_my_branches_interactive(){ ]
delete_all_my_branches_interactive(){
for branch in $(git branch | egrep '^\W*(aln|anorton|alan)/'); do
printf "Delete $branch, both local and origin? ";
read ans;
Expand Down
3 changes: 3 additions & 0 deletions .macos
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ defaults write com.apple.coreservices.uiagent CSUIHasSafariBeenLaunched -bool YE
defaults write com.apple.coreservices.uiagent CSUIRecommendSafariNextNotificationDate -date 2050-01-01T00:00:00Z
defaults write com.apple.coreservices.uiagent CSUILastOSVersionWhereSafariRecommendationWasMade -float 10.99

# Disable "floating thumbnail" preview and screenshot delay
defaults write com.apple.screencapture show-thumbnail -bool false

###############################################################
# _ _ _
# _____ ___ __ ___ _ __(_)_ __ ___ ___ _ __ | |_ __ _| |
Expand Down
129 changes: 66 additions & 63 deletions bin.Darwin/asdf-prune-unused
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
#!/usr/bin/env bash
#!/usr/bin/env python

# https://github.com/asdf-vm/asdf/issues/819#issuecomment-852449294
# Note: You probably want to set a global python version before running this script.
#
# asdf install python latest
# asdf global python latest

# Unoffical Bash "strict mode"
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
#ORIGINAL_IFS=$IFS
IFS=$'\t\n' # Stricter IFS settings
import subprocess
import os

# Function used to convert lines like this:
#
# ruby 2.0.0
# ruby 3.0.0
# elixir 1.10.0
#
# To lines like this:
#
# ruby 2.0.0 3.0.0
# elixir 1.10.0
join_multiple() {
local last=''
local n=''

while IFS=' ' read -r word definition; do

if [ "$last" == "$word" ]; then
printf " %s" "$definition"
else
if [ -n "$n" ]; then echo; else n=1; fi
printf "%s\\t%s" "$word" "$definition"
last="$word"
fi
done < "${1:-/dev/stdin}"
echo
}

# Find command often crashes due to permission issues
version_files="$(find . -maxdepth 3 -name .tool-versions || true)"

# Combine all .tool-version file contents into one variable
versions_in_use="$(
while read -r filename; do
cat "$filename";
done <<< "$version_files"
)"

# Loop over each line of the .tool-versions file
while read -r line; do
IFS=$' \t' read -r -a tool_and_versions <<< "$line"
# Split out the tool name and versions
tool_name="${tool_and_versions[0]}"
global_versions=("${tool_and_versions[@]:1}")

# Loop over each version of the tool name
for version in $(asdf list "$tool_name"); do
# Trim off leading/trailing tab/spaces
trimmed_version=$(echo "$version" | xargs)
# When version not in `global_versions` array from .tool-versions file
if [[ ! " ${global_versions[*]} " =~ ${trimmed_version} ]]; then
# Remove the version here if you want
echo "> asdf uninstall $tool_name $trimmed_version"
asdf uninstall $tool_name $trimmed_version
fi
done
done < <(echo "$versions_in_use" | sort -k1 | sort -u | join_multiple)
def strip_stars(version):
return version.replace('*', '').strip()

def find_tool_version_paths_in(dirname):
dirname = os.path.expanduser(dirname)
version_files = subprocess.run(['find', dirname, '-maxdepth', '3', '-name', '.tool-versions'], stdout=subprocess.PIPE, text=True)
versions_in_use = version_files.stdout.splitlines()
return versions_in_use

def get_installed_versions(tool_name):
result = subprocess.run(['asdf', 'list', tool_name], stdout=subprocess.PIPE, text=True)
versions = [strip_stars(line) for line in result.stdout.splitlines()]
return versions

def get_in_use_versions_by_tool_name():
global_paths = [os.path.expanduser('~/.tool-versions')]
tool_version_paths = global_paths + find_tool_version_paths_in('~/wrk') + find_tool_version_paths_in('~/src')

in_use_map = {}

for path in tool_version_paths:
with open(path, 'r') as file:
lines = file.readlines()
for line in lines:
tool_name, tool_version = line.strip().split()
tool_version = strip_stars(tool_version)
versions_in_use = in_use_map.get(tool_name, [])
versions_in_use.append(tool_version)
in_use_map[tool_name] = list(set(versions_in_use))

return in_use_map

if __name__ == "__main__":
in_use_map = get_in_use_versions_by_tool_name()

commands = []

for tool_name, versions in in_use_map.items():
print(f'Checking {tool_name}...')
installed_versions = get_installed_versions(tool_name)

print(f' In-Use: {", ".join(versions)}')
print(f' Installed: {", ".join(installed_versions)}')

unused = set(installed_versions) - set(versions)

print(f' Unused: {", ".join(unused)}')

for v in unused:
commands.append(f'asdf uninstall {tool_name} {v}')

if commands:
response = input("🧹 Do you want to uninstall the unused versions? (y/n): ").strip().lower()
if response in ['y', 'yes']:
for c in commands:
print(f'> {c}')
subprocess.run(c, shell=True)
else:
print("✨ No unused versions to uninstall.")
4 changes: 2 additions & 2 deletions bin.Darwin/git-rupall
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ MAX_DEPTH=${1:-3}

for d in $(find . -maxdepth $MAX_DEPTH -type d -name .git); do
cd $(dirname "$d")
git up || git pull
cd -
git up
cd - &> /dev/null
done
Loading

0 comments on commit b5921ea

Please sign in to comment.