USe sheldon to load plugins and source extra commands

This commit is contained in:
Jonny Barnes 2024-07-06 11:44:31 +01:00
parent 4a9e42bd6a
commit 6ce632755c
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
19 changed files with 200 additions and 229 deletions

View file

@ -0,0 +1,14 @@
#!/usr/bin/env zsh
# Homebrew commands
alias bubc="brew upgrade && brew cleanup"
alias bubo="brew update && brew outdated"
# See which user or profile we are authneticated as in aws-cli
alias aws-whoami="aws sts get-caller-identity"
# Use eza instead of ls
alias als="eza --oneline --long --classify --icons --header"
# Laravel Sail
alias sail="[ -f sail ] && bash sail || bash vendor/bin/sail"

View file

@ -0,0 +1,37 @@
#!/usr/bin/env zsh
# Load all stock functions (from $fpath files) called below.
autoload -U compaudit compinit
# Figure out the SHORT hostname
if [[ "$OSTYPE" = darwin* ]]; then
# macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
else
SHORT_HOST=${HOST/.*/}
fi
# Save the location of the current completion dump file.
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
# Construct zcompdump metadata, we will rebuild the Zsh compdump if either
# this file changes or the fpath changes.
zcompdump_revision="#revision: $(sha1sum $0:A)"
zcompdump_fpath="#fpath: $fpath"
# Delete the zcompdump file if zcompdump metadata changed
if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
|| ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
command rm -f "$ZSH_COMPDUMP"
zcompdump_refresh=1
fi
# If the user wants it, load from all found directories
compinit -u -C -d "${ZSH_COMPDUMP}"
# Append zcompdump metadata if missing
if (( $zcompdump_refresh )); then
echo "\n$zcompdump_revision\n$zcompdump_fpath" >>! "$ZSH_COMPDUMP"
fi
unset zcompdump_revision zcompdump_fpath zcompdump_refresh

View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# Setup Fast Node Manager
if type fnm > /dev/null; then
eval "$(fnm env --use-on-cd)"
fi

View file

@ -0,0 +1,120 @@
#!/usr/bin/env zsh
# Functions
# Delete branches selected via fzf
function delete-branches() {
git branch |
grep --invert-match '\*' | # Remove current branch
fzf --multi --preview="git log {..}" |
gxargs --no-run-if-empty git branch --delete
}
# Delete branches selected via fzf (force the deletion)
function delete-branches-force() {
git branch |
grep --invert-match '\*' | # Remove current branch
fzf --multi --preview="git log {..}" |
gxargs --no-run-if-empty git branch --delete --force
}
# Open a PR
function pr-checkout() {
local pr_number
pr_number=$(
gh api 'repos/:owner/:repo/pulls' --jq '.[] | "#\(.number) \(.title)"' |
fzf |
sd '^\#(\d+)\s.*' '$1'
)
if [ -n "$pr_number" ]; then
gh pr checkout "$pr_number"
fi
}
# tail, but better
function watch-file() {
tail -f $1 | bat --paging=never -l log
}
# Get a temporary directory in a cross-platform manner
# See https://unix.stackexchange.com/a/685873
function get-temporary-directory() {
local temporary_directory=${XDG_RUNTIME_DIR:-${TMPDIR:-${TMP:-${TEMP:-/tmp}}}}
echo $temporary_directory
}
# Start an SSH SOCKS tunnel
function start-proxy() {
if [ -z "$SSH_PROXY_HOST" ]; then
echo "SSH_PROXY_HOST is not set or empty"
return
fi
local socket_dir=$(get-temporary-directory)
# Check if the last character of socket_dir is a directory separator character
if [[ $socket_dir[-1] == / ]]; then
# If yes, remove the directory separator character
socket_dir="${socket_dir%?}"
fi
echo "Opening proxy connection"
# Below we use -S and -M to help make closing the connection more reliable
# See this Stack Overflow answer for more info
# https://unix.stackexchange.com/a/525388
# -D 1337 opens up the SOXKS tunnel on localhost:1337
# -f Tells `ssh` to fork the ssh process in to the background
# -C Enables compression of data on the connections
# -q Uses quiet mode
# -N Do not execute a remote command on this connection
# -S Set the ControlPath for this connection
# -M Place the client into `master` mode
ssh -D 1337 -f -C -q -N -S $socket_dir/ssh-proxy-control -M $SSH_PROXY_HOST
}
# Stop an open proxy connection
function stop-proxy() {
if [ -z "$SSH_PROXY_HOST" ]; then
echo "SSH_PROXY_HOST is not set or empty"
return
fi
local socket_dir=$(get-temporary-directory)
# Check if the last character of socket_dir is a directory separator character
if [[ $socket_dir[-1] == / ]]; then
# If yes, remove the directory separator character
socket_dir="${socket_dir%?}"
fi
echo "Closing proxy connection"
# See the comments in `start-proxy()` for more info
ssh -S $socket_dir/ssh-proxy-control -O exit $SSH_PROXY_HOST
}
# Get the system appearance
function get-system-appearance() {
if ! type defaults &>/dev/null; then
echo ""
fi
local darkMode=true;
if [[ $(defaults read -g AppleInterfaceStyle 2> /dev/null) != 'Dark' ]]; then
darkMode=false
fi
if [[ $darkMode == true ]]; then
echo "dark"
else
echo "light"
fi
}

View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# Setup fzf completions
if type fzf > /dev/null; then
eval "$(fzf --zsh)"
fi

View file

@ -0,0 +1,10 @@
#!/usr/bin/env zsh
# Setup GitHub Copilot
# first check we even have the genereic `gh` command
if type gh > /dev/null; then
# Now check we have the copilot plugin installed with `gh`
if gh extension list | rg copilot -c > /dev/null; then
eval "$(gh copilot alias -- zsh)"
fi
fi

View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# McFly
if type mcfly > /dev/null; then
eval "$(mcfly init zsh)"
fi

View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# ngrok completions
if command -v ngrok &>/dev/null; then
eval "$(ngrok completion)"
fi

View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# Init the fuck
if type thefuck > /dev/null; then
eval "$(thefuck --alias)"
fi

View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
# zoxide - a better `cd` command
if command -v zoxide &>/dev/null; then
eval "$(zoxide init zsh)"
fi