Skip to content

Commit 875c293

Browse files
authored
macOS additions/changes (#8)
* use realpath instead of readlink -f * fix .profile to work with zsh on macos * bring back zsh This reverts commit e622253. * add subl bin to PATH * add support for macos git prompt * fixes for sublime text on macos * quote paths just in case * add script to bootstrap macos * also source git bash completion script * fix order of redirection
1 parent ffb9508 commit 875c293

28 files changed

+101
-48
lines changed

configs/shell/bashrc

+13-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,19 @@ fi
7979
# |__/ \______/ |______/
8080

8181
# on some systems this is not sourced automatically
82-
if [ -e /usr/share/git/completion/git-prompt.sh ] && ! command -v __git_ps1 >/dev/null 2>&1; then
83-
. /usr/share/git/completion/git-prompt.sh
82+
if ! command -v __git_ps1 >/dev/null 2>&1; then
83+
if [ -e '/usr/share/git/completion/git-prompt.sh' ]; then
84+
. '/usr/share/git/completion/git-prompt.sh'
85+
elif [ -e '/usr/local/etc/bash_completion.d/git-prompt.sh' ]; then
86+
. '/usr/local/etc/bash_completion.d/git-prompt.sh'
87+
fi
88+
fi
89+
if ! command -v ___git_complete >/dev/null 2>&1; then
90+
if [ -e '/usr/share/git/completion/git-completion.bash' ]; then
91+
. '/usr/share/git/completion/git-completion.bash'
92+
elif [ -e '/usr/local/etc/bash_completion.d/git-completion.bash' ]; then
93+
. '/usr/local/etc/bash_completion.d/git-completion.bash'
94+
fi
8495
fi
8596

8697
# wrap in a function to allow local variables

configs/shell/profile

+13-11
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ umask 022
66

77
# add paths to $PATH. these should be listed in order of
88
# least precedence first, highest precedence last
9-
paths="
9+
_paths=(
1010
/sbin
1111
/usr/sbin
12-
$HOME/Library/Python/*/bin
13-
$HOME/.cargo/bin
14-
$HOME/.npm/bin
15-
$HOME/.local/bin
16-
$HOME/bin
17-
"
18-
for path in $paths; do
19-
if [ -d "$path" ] && [ ! -L "$path" ]; then
20-
PATH="$path:$PATH"
12+
/usr/local/opt/*/libexec/gnubin
13+
"/Applications/Sublime Text.app/Contents/SharedSupport/bin"
14+
"$HOME/Library/Python/*/bin"
15+
"$HOME/.cargo/bin"
16+
"$HOME/.npm/bin"
17+
"$HOME/.local/bin"
18+
"$HOME/bin"
19+
)
20+
for _path in "${_paths[@]}"; do
21+
if [ -d "$_path" ] && [ ! -L "$_path" ]; then
22+
PATH="$_path:$PATH"
2123
fi
2224
done
23-
unset path paths
25+
unset _path _paths
2426

2527
# bashrc doesn't execute itself
2628
if [ -n "$BASH_VERSION" ]; then

install.sh

+24-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [ ! -d $HOME/.local/bin ]; then
1313
mkdir -p $HOME/.local/bin
1414
fi
1515
bindir=$HOME/.local/bin
16-
root=$(dirname "$(readlink -f "$0")")
16+
root=$(dirname "$(realpath "$0")")
1717
configs=$root/configs
1818
scripts=$root/scripts
1919
vendor=$root/vendor
@@ -172,7 +172,7 @@ install_i3blocks() {
172172
ln -sf $vendor/i3blocks-contrib/volume/volume $conf_path/scripts/
173173

174174
for f in $configs/i3/block-scripts/*; do
175-
filepath=$(readlink -f $f)
175+
filepath=$(realpath $f)
176176
filename=$(basename $f)
177177
ln -sf $filepath $conf_path/scripts/$filename
178178
done
@@ -221,14 +221,21 @@ install_rg() {
221221
}
222222

223223
install_subl() {
224-
pkgdir=$HOME/.config/sublime-text-3/Packages
225-
userdir=$pkgdir/User
226-
mkdir -p $pkgdir
227-
if [ -d $userdir ] && [ ! -L $userdir ]; then
228-
mv $userdir $userdir.bak
224+
if [ -d $HOME/.config/sublime-text-3/Packages ]; then
225+
pkgdir=$HOME/.config/sublime-text-3/Packages
226+
elif [ -d "$HOME/Library/Application Support/Sublime Text/Packages" ]; then
227+
pkgdir="$HOME/Library/Application Support/Sublime Text/Packages"
228+
else
229+
echo "Sublime Text Packages directory not found!"
230+
return
231+
fi
232+
userdir="$pkgdir/User"
233+
mkdir -p "$pkgdir"
234+
if [ -d "$userdir" ] && [ ! -L "$userdir" ]; then
235+
mv "$userdir" "$userdir.bak"
229236
fi
230-
ln -sfT $configs/sublime-text $userdir
231-
ln -sf $scripts/sublp.sh $bindir/sublp
237+
ln -sfT "$configs/sublime-text" "$userdir"
238+
ln -sf "$scripts/sublp.sh" "$bindir/sublp"
232239
}
233240

234241
install_taskwarrior() {
@@ -331,6 +338,13 @@ install_xorg() {
331338
rm -f $HOME/.config/fontconfig/local.conf
332339
}
333340

341+
install_zsh() {
342+
ln -sf $configs/shell/zshrc $HOME/.zshrc
343+
ln -sf $configs/shell/profile $HOME/.zprofile
344+
ln -sf $configs/shell/logout $HOME/.zlogout
345+
_install_fzf
346+
}
347+
334348

335349
if [ ! -e $root/.venv ]; then
336350
echo "Setting up virtual environment ..."
@@ -395,6 +409,7 @@ install vim
395409
install nvim
396410
install xorg Xorg
397411
install xdg xdg-open
412+
install zsh
398413

399414
[ -e ~/.dropbox-dist ] && install_dropbox
400415

scripts/bootstrap-macos.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
confirm() {
4+
echo -n "$* [Y/n] "
5+
read REPLY
6+
if [ -z "$REPLY" ] || [ "$REPLY" != "${REPLY#[Yy]}" ]; then
7+
return 0
8+
fi
9+
return 1
10+
}
11+
12+
# attempt to get rid of mouse + scroll wheel acceleration
13+
defaults write -g com.apple.mouse.scaling -int -1
14+
defaults write -g com.apple.scrollwheel.scaling -int -1
15+
16+
# un-invert scrolling
17+
defaults write -g com.apple.swipescrolldirection -int 0
18+
19+
# I don't like homebrew but there are no good alternatives
20+
if ! command -v brew >/dev/null 2>&1 && confirm "Install Homebrew?"; then
21+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
22+
23+
# gnu utils to replace horribly out of date bsd grep/awk etc.
24+
brew install coreutils findutils gawk grep gnu-tar gnu-sed gnu-getopt
25+
fi

scripts/i3-switch.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22

3-
dir="$(dirname "$(readlink -f "$0")")"
3+
dir="$(dirname "$(realpath "$0")")"
44
id="$(i3-msg -t get_tree | $dir/i3-get.py "${1-next}")"
55
[ $? = 0 ] && [ "$id" ] && i3-msg [id="$id"] focus >/dev/null

scripts/sublp.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if ! command -v subl >/dev/null 2>&1; then
66
exit 1
77
fi
88

9-
dir=$(readlink -f "${1-$PWD}")
9+
dir=$(realpath "${1-$PWD}")
1010
cd $dir || exit 1
1111

1212
find_sublime_project_file() {
@@ -24,7 +24,7 @@ done
2424
if [ -z "$sp" ]; then
2525
echo "No sublime-project found, running init-project ..."
2626
init-project --noninteractive --allow-no-type
27-
dir=$(readlink -f "${1-$PWD}")
27+
dir=$(realpath "${1-$PWD}")
2828
sp="$(find_sublime_project_file "$dir")"
2929
fi
3030
if [ -z "$sp" ]; then

scripts/upgrade/_lib.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fail() {
3535
}
3636

3737
latest_already_installed() {
38-
script="$(basename "$(readlink -f "$0")")"
38+
script="$(basename "$(realpath "$0")")"
3939
name="${script%%.*}"
4040
echo "Latest version of $name ($version) is already installed!" >&2
4141
exit 0
@@ -47,7 +47,7 @@ download() {
4747
cd ~/downloads || exit 1
4848
wget "$1" -O "$filename"
4949
if [ -z "${2-}" ]; then
50-
readlink -f "$filename"
50+
realpath "$filename"
5151
fi
5252
}
5353

scripts/upgrade/acrophone.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
url=$(gh_urls bcicen/acrophone | grep linux-amd64 | head -1)
77
version=$(echo $url | sed -r 's|.*/download/v([0-9.-]+)/.*|\1|')

scripts/upgrade/docker-compose.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
url=$(gh_urls docker/compose | grep Linux-x86_64 | grep -v -- '-rc' | head -1)
77
version=$(echo $url | sed -r 's|.*/download/([0-9.-]+)/.*|\1|')

scripts/upgrade/docker-machine.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
url=$(gh_urls docker/machine | grep -v -- '-rc' | head -1)
77
version=$(echo $url | sed -r 's|.*/download/v([0-9.-]+)/.*|\1|')

scripts/upgrade/earthly.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(gh_releases earthly/earthly | head -1)
77

scripts/upgrade/fluxctl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
repo=fluxcd/flux
77
version=$(gh_tags $repo | head -1)

scripts/upgrade/go.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
if [ $# -gt 0 ]; then
77
version="$1"

scripts/upgrade/helm.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
# exclude alpha/beta/rc, and always get highest version number (as opposed to
77
# most recent release by date)

scripts/upgrade/k3s.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(gh_tags rancher/k3s | head -1)
77

scripts/upgrade/keepassxc.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
# grep for digits removes alpha/beta/rc releases
77
url=$(gh_urls keepassxreboot/keepassxc | grep -P '\/[\d\.]+\/' | grep '\.AppImage$' | head -1)

scripts/upgrade/kops.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(gh_tags kubernetes/kops | head -1)
77

scripts/upgrade/kotlin.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
url=$(gh_url JetBrains/kotlin | grep -F linux-x64 | head -1)
77
version=$(basename $url | grep -oP '\d+(\.\d+)+')

scripts/upgrade/kubectl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
77

scripts/upgrade/kubeseal.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(gh_latest_tag bitnami-labs/sealed-secrets/releases/latest)
77

scripts/upgrade/minikube.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(gh_latest_tag kubernetes/minikube)
77

scripts/upgrade/php.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
if [ $# -lt 1 ];then
77
fail "Must provide version!"

scripts/upgrade/python.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
versions=$(gh_tags python/cpython | sed -r 's/^v//g' | grep -xP "\d+\.\d+\.\d+" | sort -V)
77
if [ $# -gt 0 ]; then

scripts/upgrade/shellcheck.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(gh_latest_tag koalaman/shellcheck)
77
version_num=$(echo "$version" | sed s/^v//)

scripts/upgrade/terraform.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version=$(
77
curl -sSL https://releases.hashicorp.com/terraform/ \

scripts/upgrade/terragrunt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
version="${1-$(gh_latest_tag gruntwork-io/terragrunt)}"
77

scripts/upgrade/vagrant.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -eu
33
# shellcheck source=_lib.sh
4-
. "$(dirname "$(readlink -f "$0")")/_lib.sh"
4+
. "$(dirname "$(realpath "$0")")/_lib.sh"
55

66
url=$(curl -sSL https://www.vagrantup.com/downloads.html | grep -oP 'https://[/A-z0-9._-]+_x86_64\.deb' | sort -V | tail -1)
77
version=$(echo $url | sed -r 's/.*vagrant_([0-9.]+)_x86_64.*/\1/')

update-vendors.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22

3-
root=$(dirname "$(readlink -f "$0")")
3+
root=$(dirname "$(realpath "$0")")
44

55
update_fzf() {
66
./install --bin

0 commit comments

Comments
 (0)