-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdots
More file actions
executable file
·114 lines (92 loc) · 2.58 KB
/
Copy pathdots
File metadata and controls
executable file
·114 lines (92 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env zsh
set -euo pipefail
dots_up() {
echo "Updating Command Line Tools..."
local clt_label
clt_label=$(softwareupdate -l 2>&1 | grep "Label: Command Line Tools" | sed 's/.*Label: //' | head -1 || true)
if [[ -n "${clt_label}" ]]; then
sudo softwareupdate -i "${clt_label}"
else
echo "Command Line Tools is up to date."
fi
echo "\nUpdating Homebrew..."
brew update
brew upgrade
echo "\nUpdating mise..."
mise up
echo "\nUpdating yazi plugins and flavors..."
ya pkg upgrade
echo "\nUpdating gh extensions..."
gh extension upgrade --all
if [ -f "$HOME/.apm/apm.yml" ]; then
echo "\nUpdating apm skills..."
apm install -g --update --target agent-skills
fi
echo "\nUpdating Claude Code..."
claude update
echo "\nUpdating VS Code extensions..."
code --update-extensions
echo "\nDone!"
}
dots_cleanup() {
if [[ "${PWD}" != "${HOME}" ]]; then
echo "Error: dots cleanup must be run from the home directory"
exit 1
fi
_storage_snapshot() {
swift -e '
import Foundation
let url = URL(fileURLWithPath: "/")
let keys: Set<URLResourceKey> = [.volumeTotalCapacityKey, .volumeAvailableCapacityForImportantUsageKey]
let v = try! url.resourceValues(forKeys: keys)
let total = Int64(v.volumeTotalCapacity!)
let avail = v.volumeAvailableCapacityForImportantUsage!
let used = total - avail
print(String(format: "%.2f %.2f", Double(used)/1e9, Double(avail)/1e9))
'
}
local before
before=($(_storage_snapshot))
echo "\nCleaning Homebrew..."
brew cleanup || true
echo "\nCleaning mise..."
mise prune --yes || true
echo "\nCleaning npm..."
command -v npm &>/dev/null && npm cache clean --force || true
echo "\nCleaning yarn..."
command -v yarn &>/dev/null && yarn cache clean || true
echo "\nCleaning pnpm..."
command -v pnpm &>/dev/null && pnpm store prune || true
local after
after=($(_storage_snapshot))
local freed=$(awk "BEGIN {printf \"%.2f\", ${before[1]} - ${after[1]}}")
echo "\nCleaned up ${freed} GB (${after[1]} GB used, ${after[2]} GB available)"
}
dots_edit() {
local repo_dir
repo_dir="${DOTFILES_DIR:-}"
if [[ -z "${repo_dir}" ]]; then
echo "DOTFILES_DIR is not defined"
return 1
fi
code "${repo_dir}"
}
case "${1:-}" in
up)
dots_up
;;
cleanup)
dots_cleanup
;;
edit)
dots_edit
;;
*)
echo "Usage: dots <command>
Commands:
up Update Homebrew, mise, and VS Code extensions
cleanup Clean up unused packages and free disk space
edit Open dotfiles in VS Code"
exit 1
;;
esac