-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_lists.sh
More file actions
103 lines (80 loc) · 3.13 KB
/
Copy pathrun_lists.sh
File metadata and controls
103 lines (80 loc) · 3.13 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
#!/usr/bin/env bash
set -euo pipefail
# Bash before 4.4 (like the default one on Macs these days) doesn't have this option:
# https://news.ycombinator.com/item?id=24738359
shopt -s inherit_errexit 2> /dev/null || true
# Bash before 4.2 (like the default one on Macs these days) doesn't support negative subscripts:
# https://stackoverflow.com/a/61345169/380599
script_name=$(basename "${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}")
if ! chezmoi_source="$(chezmoi data | jq --exit-status --raw-output '.chezmoi.sourceDir')"; then
echo "$script_name: couldn't fetch source directory from 'chezmoi data'"
exit 1
fi
function process_list() {
# Parameter #1 is the command to generate the list
# Parameter #2 is the name of the list
# Parameter #3 (optional) will, if set to anything, skip sorting
# Parse out the command name (from the first line (NR) only) and make sure it is available
cmd_name=$(awk 'NR == 1 { print $1 }' <<< "$1")
if ! hash "$cmd_name" &> /dev/null; then
echo "$script_name > ${FUNCNAME[0]}: command '$cmd_name' not found; aborting"
return
fi
# Print command and first argument
current_timestamp=$(TZ=UTC date '+%Y%m%dT%H%M%SZ')
printf "%s: [%s] " "$script_name" "$current_timestamp"
awk 'NR == 1 { print $1, $2 }' <<< "$1"
# If the command is 'brew' then make sure we're up to date before kicking off the lists
if [[ $cmd_name == "brew" ]]; then
brew update
fi
if ! cmd_output="$(eval "$1")"; then
: # No-op; skipping errors
fi
# Make sure the list directory structure and the file itself all exist.
list_file_path="$chezmoi_source/lists/text/list.$2.txt"
mkdir -p "$(basename list_file_path)"
touch "$list_file_path"
if [[ -n ${3-} ]]; then
echo "$cmd_output" > "$list_file_path"
else
sort --ignore-case <<< "$cmd_output" > "$list_file_path"
fi
}
# Git repos I have checked out locally
git_list_cmd="fd '^\.git$' \"$HOME\"/git --hidden --type directory --exec git -C '{//}' rev-parse --show-toplevel \
| grep --invert-match '/github\.com/ovotech/'"
process_list "$git_list_cmd" "git"
# Go binaries
if command -v gup &> /dev/null; then
process_list "gup list" "go.gup" skipsort
elif [[ -d "$HOME"/go/bin ]]; then
process_list "find \"$HOME\"/go/bin -type f" "go.bin"
fi
# Rust binaries
if [[ ! -d $HOME/.cargo/bin ]]; then
echo "$script_name: No '\$HOME.cargo/bin/' directory found; skipping"
else
process_list "cargo install --list" "rust.bin" skipsort
fi
# Homebrew
process_list "brew tap" "brew.tap"
process_list "brew list -1 --formula" "brew"
process_list "brew list -1 --cask" "brew.cask"
# TODO: leverage 'brew bundle dump --file=- --all' instead
# pnpm
pnpm_list_cmd='pnpm list --global --json --long \
| jq --raw-output '\''.[].dependencies | to_entries | .[].value | "\(.homepage):\(.version)"'\'
process_list "$pnpm_list_cmd" "pnpm"
# VSCode extensions
process_list "code --list-extensions" "vscode"
# Python packages
process_list "python3 -m pip list --format freeze" "pip3"
# Ruby gems
process_list "gem list --no-verbose" "gem"
# Kubectl plugins
process_list "kubectl krew list" "kubectl.krew"
# GitHub CLU extensions
process_list "gh extension list" "gh"
# Mac App Store
process_list "mas list" "mas" skipsort