Skip to content

Commit 2fe79cd

Browse files
authored
10/4/2025 (#51)
1 parent c59d613 commit 2fe79cd

4 files changed

Lines changed: 85 additions & 31 deletions

File tree

.10_macos.bash

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,65 @@ fi
2323
__homebrew_funcs() {
2424
# Install a specific version of a Homebrew formula
2525
# @param {string} $1 Formula name
26-
# @param {string} $2 Formula version
26+
# @param {string} $2 Formula version (exact)
2727
vintage() {
28-
# Ensure homebrew/core is tapped and up to date
29-
brew tap | grep -xq homebrew/core \
30-
&& brew update \
31-
|| brew tap --force homebrew/core
28+
# Figure out the relevant tap
29+
local brew_tap
30+
local is_cask=false
31+
if brew search --cask "/^${1:?}$/" &> /dev/null; then
32+
brew_tap="homebrew/cask"
33+
is_cask=true
34+
else
35+
brew_tap="homebrew/core"
36+
fi
37+
38+
# Ensure the appropriate tap is tapped and up to date
39+
if brew tap | grep -xq "${brew_tap}"; then
40+
brew update
41+
else
42+
brew tap --force "${brew_tap}"
43+
fi
3244

3345
# Ensure homebrew/local is created
3446
brew tap | grep -xq homebrew/local \
3547
|| brew tap homebrew/local
3648

37-
# Extract the formula
38-
brew extract --force "--version=${2:?}" "${1:?}" homebrew/local
39-
40-
# If the formula is already installed, re-link it
41-
if brew list -1 | grep -xq "${1:?}@${2:?}"; then
42-
brew unlink "${1:?}@${2:?}"
43-
brew link --overwrite "${1:?}@${2:?}"
44-
return 0
45-
fi
46-
47-
# Install the formula and ensure it's linked
48-
brew install "homebrew/local/${1:?}@${2:?}" \
49-
|| brew link --overwrite "${1:?}@${2:?}"
49+
if [ "${is_cask}" = false ]; then
50+
# If the formula is already installed, re-link it
51+
if brew list -1 | grep -xq "${1:?}@${2:?}"; then
52+
brew unlink "${1:?}@${2:?}"
53+
brew link --overwrite "${1:?}@${2:?}"
54+
return 0
55+
fi
56+
57+
# Install the formula and ensure it's linked
58+
brew install "homebrew/local/${1:?}@${2:?}" \
59+
|| brew link --overwrite "${1:?}@${2:?}"
60+
else (
61+
# Sub shell to make `cd` safe
62+
cd "$(brew --repository "${brew_tap}")" || return 1
63+
64+
# Emulate `brew extract` for casks
65+
local cask_path
66+
cask_path=$(git ls-files 'Casks/*' | grep -E "/${1:?}\.rb$")
67+
local version_match
68+
version_match=$(git rev-list --all "${cask_path}" \
69+
| xargs -n1 -I% git --no-pager grep --fixed-strings "version \"${2:?}\"" % -- "${cask_path}" \
70+
2> /dev/null | head -1)
71+
local commit_hash="${version_match%%:*}"
72+
local local_cask_dir
73+
local_cask_dir="$(brew --repository homebrew/local)/Casks"
74+
if [ ! -d "${local_cask_dir}" ]; then
75+
mkdir -p "${local_cask_dir}"
76+
fi
77+
local local_cask_file="${local_cask_dir}/${1:?}@${2:?}.rb"
78+
git show "${commit_hash}:${cask_path}" \
79+
| sed "s/cask \"${1:?}\"/cask \"${1:?}@${2:?}\"/" \
80+
> "${local_cask_file}"
81+
82+
# Install the formula
83+
brew install --cask "homebrew/local/${1:?}@${2:?}"
84+
) fi
5085
}
5186
}
5287
__homebrew_funcs
@@ -56,9 +91,29 @@ __homebrew_funcs
5691

5792
# Homebrew packages
5893
if command -v brew &> /dev/null; then
59-
# Apps
60-
[[ -d /Applications/LinearMouse.app ]] || brew install --cask linearmouse
61-
[[ -d /Applications/Rectangle.app ]] || brew install --cask rectangle
94+
# Apps (only install if shell is interactive, in case of admin password prompt)
95+
if [[ $- == *i* ]]; then
96+
for cask in $(
97+
echo "1password"
98+
#echo "discord"
99+
echo "firefox"
100+
echo "github"
101+
#echo "inkscape"
102+
echo "libreoffice"
103+
echo "linearmouse"
104+
echo "rectangle"
105+
#echo "signal"
106+
echo "spotify"
107+
#echo "steam"
108+
echo "visual-studio-code"
109+
echo "wine-stable"
110+
); do
111+
app_artifact=$(brew info --json=v2 --cask "${cask}" \
112+
| jq --raw-output ".casks[] | select(.token==\"${cask}\") | .artifacts[] | .app // empty | .[]" \
113+
| head -1)
114+
[[ -d "/Applications/${app_artifact}" ]] || echo brew install --cask "${cask}"
115+
done
116+
fi
62117

63118
# CLI tools
64119
command -v dive > /dev/null || brew install dive
@@ -70,7 +125,6 @@ if command -v brew &> /dev/null; then
70125
command -v rename > /dev/null || brew install rename
71126
command -v tree > /dev/null || brew install tree
72127
command -v watch > /dev/null || brew install watch
73-
command -v wine > /dev/null || brew install --cask --no-quarantine wine-stable
74128
command -v wget > /dev/null || brew install wget
75129

76130
if ! command -v hstr &> /dev/null; then
@@ -110,7 +164,7 @@ if command -v mas &> /dev/null; then
110164
# Grammarly for Safari
111165
echo "1462114288"
112166
); do
113-
echo "${mas_list}" | grep "^${app_id} " &> /dev/null || mas install "${app_id}"
167+
echo "${mas_list}" | grep -Eq "^${app_id} " || mas install "${app_id}"
114168
done
115169
fi
116170

.20_git.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ __git_funcs() {
1919
# Shell alias Git aliases from the .gitconfig
2020
for al in $(git --list-cmds=alias; git --list-cmds=main); do
2121
# shellcheck disable=SC2139
22-
alias g${al}="git ${al}"
22+
alias "g${al}"="git ${al}"
2323
if type __git_aliased_command &> /dev/null; then
2424
complete_func=_git_$(__git_aliased_command "${al}")
2525
type "${complete_func}" &> /dev/null && __git_complete "g${al}" "${complete_func}"
@@ -35,7 +35,7 @@ __git_funcs() {
3535
git pull
3636

3737
local stash_name
38-
stash_name="$(cat /dev/urandom | base32 | tr -dc 'A-Z0-9' | head -c 16)"
38+
stash_name="$(base32 < /dev/urandom | tr -dc 'A-Z0-9' | head -c 16)"
3939
git stash push --message "${stash_name}" || return 1
4040
if [[ $(git branch --list main) ]]; then
4141
git fetch origin main:main
@@ -51,7 +51,7 @@ __git_funcs() {
5151
local origin_old
5252
origin_old="$(git remote get-url origin)"
5353
local origin_new
54-
origin_new="$(echo "${origin_old}" | sed 's#https://github.com/#git@github.com:#')"
54+
origin_new="${origin_old/https:\/\/github.co\//git@github.com:}"
5555
if [[ "${origin_new}" != "${origin_old}" && "${origin_new}" != "" ]]; then
5656
echo "Changing $(pwd) remote origin to: ${origin_new}"
5757
git remote set-url origin "${origin_new}"

.20_kubernetes.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ __kube_funcs() {
2525
# @param {string=} $1 App label
2626
# @param {...string} Additional kubectl options
2727
kcontainers() {
28-
kubectl get pods --output=jsonpath="{.items[*].spec.containers[*].name}" ${1:+--selector="app=$1"} "${@:2}" | tr -s '[[:space:]]' '\n' | sort -u
28+
kubectl get pods --output=jsonpath="{.items[*].spec.containers[*].name}" ${1:+--selector="app=$1"} "${@:2}" | tr -s '[:space:]' '\n' | sort -u
2929
}
3030

3131
# Change to a kubectl context
@@ -49,7 +49,7 @@ __kube_funcs() {
4949
# @param {string} $1 Deployment name
5050
# @param {...string} Additional kubectl options
5151
kdcontainers() {
52-
kubectl get deployment --output=jsonpath="{.spec.template.spec.containers[*].name}" "$1" "${@:2}" | tr -s '[[:space:]]' '\n' | sort -u
52+
kubectl get deployment --output=jsonpath="{.spec.template.spec.containers[*].name}" "$1" "${@:2}" | tr -s '[:space:]' '\n' | sort -u
5353
}
5454

5555
# Delete a Kubernetes pod
@@ -63,7 +63,7 @@ __kube_funcs() {
6363
# @param {string=} $1 App label
6464
# @param {...string} Additional kubectl options
6565
kdeployments() {
66-
kubectl get deployments --output=jsonpath="{.items[*].metadata.name}" ${1:+--selector="app=$1"} "${@:2}" | tr -s '[[:space:]]' '\n' | sort -u
66+
kubectl get deployments --output=jsonpath="{.items[*].metadata.name}" ${1:+--selector="app=$1"} "${@:2}" | tr -s '[:space:]' '\n' | sort -u
6767
}
6868

6969
# Open a port forward session to a remote Kubernetes deployment
@@ -87,7 +87,7 @@ __kube_funcs() {
8787
# @param {string=} $1 App label
8888
# @param {...string} Additional kubectl options
8989
kimages() {
90-
kubectl get pods --output=jsonpath="{.items[*].spec.containers[*].image}" ${1:+--selector="app=$1"} "${@:2}" | tr -s '[[:space:]]' '\n' | sort -u
90+
kubectl get pods --output=jsonpath="{.items[*].spec.containers[*].image}" ${1:+--selector="app=$1"} "${@:2}" | tr -s '[:space:]' '\n' | sort -u
9191
}
9292

9393
# List all Kubernetes ingresses, optionally filtering to an application

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
severity: warning
1515
env:
1616
# SC2148: ignore missing shebang, it's not appropriate here
17-
SHELLCHECK_OPTS: -e SC2148
17+
SHELLCHECK_OPTS: --shell=bash --exclude=SC2148

0 commit comments

Comments
 (0)