Skip to content

Commit fe8c26a

Browse files
add talscale GUI install script
1 parent baaed21 commit fe8c26a

File tree

6 files changed

+194
-28
lines changed

6 files changed

+194
-28
lines changed

install_scripts/tailscale.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
tmp_dir=/tmp/install_scripts/tailscale
4+
tailscale_pkg="${tmp_dir}/install.pkg"
5+
6+
if [[ "$(which tailscale)" == "" ]]; then
7+
echo "installing tailscale as it has not been found on the system"
8+
mkdir -p "${tmp_dir}"
9+
cd "${tmp_dir}" || exit 1
10+
wget https://pkgs.tailscale.com/stable/Tailscale-latest-macos.pkg -O "${tailscale_pkg}"
11+
open "${tailscale_pkg}"
12+
else
13+
echo "tailscale GUI is already installed"
14+
fi

zsh/aliases

-28
This file was deleted.

zsh/aliases/aliases.sh

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/usr/bin/env zsh
2+
3+
# formats ls as a vertical list, excluding extra information from ls -l
4+
# CLICOLOR_FORCE=1 forces ls colour to be displayed even through piping.
5+
# LC_COLLATE=cs_CZ.ISO8859-2 is a locale that is used to sort the alphabet in a case-insensitive way (i.e. aAbBcC rather than abcABC).
6+
# it does sort dotfiles after Z but we're getting there.
7+
# similar to exa -1
8+
alias l='CLICOLOR_FORCE=1 LC_COLLATE=cs_CZ.ISO8859-2 ls -lF | awk "{\$1=\$2=\$3=\$4=\$5=\$6=\$7=\$8=\"\"; if (NR!=1) print substr(\$0, 9)}"'
9+
alias la='CLICOLOR_FORCE=1 LC_COLLATE=cs_CZ.ISO8859-2 ls -lFA | awk "{\$1=\$2=\$3=\$4=\$5=\$6=\$7=\$8=\"\"; if (NR!=1) print substr(\$0, 9)}"'
10+
11+
# git
12+
# other aliases are in ~/.config/git/config
13+
alias g='git'
14+
15+
# kube
16+
alias k='kubectl'
17+
alias kg='kubectl get'
18+
alias kx='kubectx'
19+
alias kwatch='watch -n 1 kubectl'
20+
21+
# for when I need to cheer myself up
22+
alias please='sudo'
23+
24+
alias tf='terraform'
25+
26+
alias vim="nvim"
27+
28+
#
29+
# Brew
30+
# This code is used so that I can transparently use `brew install XYZ`
31+
# and this script will keep the Brewfile automatically up to date
32+
#
33+
# Overriding the brew function only for install/uninstall
34+
35+
# Static Brewfile location
36+
BREWFILE="${XDG_CONFIG_HOME:-$HOME/.config}/brewfile/Brewfile"
37+
38+
# Overriding the brew function only for install/uninstall
39+
brew() {
40+
if [[ "$1" == "install" ]]; then
41+
shift
42+
brew_install_with_brewfile "$@"
43+
elif [[ "$1" == "uninstall" ]]; then
44+
shift
45+
brew_uninstall_with_brewfile "$@"
46+
else
47+
# Pass all other commands directly to the original brew command
48+
command brew "$@"
49+
fi
50+
}
51+
52+
# Function to handle brew install and update the Brewfile
53+
brew_install_with_brewfile() {
54+
IS_CASK=0
55+
FORMULA=""
56+
57+
# Parse arguments to handle "--cask" regardless of position
58+
for arg in "$@"; do
59+
if [[ "$arg" == "--cask" ]]; then
60+
IS_CASK=1
61+
else
62+
FORMULA="$arg"
63+
fi
64+
done
65+
66+
if [[ -z "$FORMULA" ]]; then
67+
echo "Usage: brew install [--cask] <formula|cask>"
68+
return 1
69+
fi
70+
71+
# Ensure the Brewfile exists
72+
if [[ ! -f "$BREWFILE" ]]; then
73+
mkdir -p "$(dirname "$BREWFILE")"
74+
touch "$BREWFILE"
75+
fi
76+
77+
# Ensure the formula gets installed as either a formula or cask correctly
78+
if [[ $IS_CASK -eq 1 ]]; then
79+
# Install as cask
80+
if command brew install --cask "$FORMULA"; then
81+
add_to_brewfile "$FORMULA" "cask"
82+
else
83+
echo "Failed to install \"$FORMULA\"."
84+
return 1
85+
fi
86+
else
87+
# Install as formula
88+
if command brew install "$FORMULA"; then
89+
add_to_brewfile "$FORMULA" "brew"
90+
else
91+
echo "Failed to install \"$FORMULA\"."
92+
return 1
93+
fi
94+
fi
95+
}
96+
97+
# Helper function to add entries to the Brewfile
98+
add_to_brewfile() {
99+
ENTRY_TYPE="$2"
100+
FORMULA="$1"
101+
ENTRY="$ENTRY_TYPE \"$FORMULA\""
102+
103+
# Check if the entry already exists
104+
if grep -qE "^$ENTRY$" "$BREWFILE"; then
105+
echo "$ENTRY is already in the Brewfile."
106+
else
107+
TMPFILE=$(mktemp)
108+
awk -v entry="$ENTRY" -v type="$ENTRY_TYPE" '
109+
BEGIN { placed = 0 }
110+
/^brew "/ && type == "brew" {
111+
if (!placed && $0 > entry) {
112+
print entry
113+
placed = 1
114+
}
115+
}
116+
/^cask "/ && type == "cask" {
117+
if (!placed && $0 > entry) {
118+
print entry
119+
placed = 1
120+
}
121+
}
122+
{ print $0 }
123+
END {
124+
if (!placed) print entry
125+
}
126+
' "$BREWFILE" > "$TMPFILE"
127+
mv "$TMPFILE" "$BREWFILE"
128+
echo "Added \"$FORMULA\" to the Brewfile as $ENTRY."
129+
fi
130+
}
131+
# Function to handle brew uninstall and update the Brewfile
132+
brew_uninstall_with_brewfile() {
133+
IS_CASK=0
134+
FORMULA=""
135+
136+
# Parse arguments to handle "--cask" regardless of position
137+
for arg in "$@"; do
138+
if [[ "$arg" == "--cask" ]]; then
139+
IS_CASK=1
140+
else
141+
FORMULA="$arg"
142+
fi
143+
done
144+
145+
if [[ -z "$FORMULA" ]]; then
146+
echo "Usage: brew uninstall [--cask] <formula|cask>"
147+
return 1
148+
fi
149+
150+
# Ensure the Brewfile exists
151+
if [[ ! -f "$BREWFILE" ]]; then
152+
echo "No Brewfile found at $BREWFILE."
153+
return 1
154+
fi
155+
156+
# Uninstall the formula or cask (pass --cask only if required)
157+
if [[ $IS_CASK -eq 1 ]]; then
158+
if command brew uninstall --cask "$FORMULA"; then
159+
ENTRY="cask \"$FORMULA\""
160+
else
161+
echo "Failed to uninstall \"$FORMULA\"."
162+
return 1
163+
fi
164+
else
165+
if command brew uninstall "$FORMULA"; then
166+
ENTRY="brew \"$FORMULA\""
167+
else
168+
echo "Failed to uninstall \"$FORMULA\"."
169+
return 1
170+
fi
171+
fi
172+
173+
# Check if the entry exists in the Brewfile and remove it
174+
if grep -qE "^$ENTRY$" "$BREWFILE"; then
175+
sed -i.bak "/^$ENTRY$/d" "$BREWFILE" && rm -f "$BREWFILE.bak"
176+
echo "Removed \"$FORMULA\" from the Brewfile."
177+
else
178+
echo "\"$FORMULA\" was not found in the Brewfile."
179+
fi
180+
}

zsh/aliases/brew.sh

Whitespace-only changes.

zsh/functions/brew.sh

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)