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

@ -14,8 +14,8 @@ test -L $HOME/.hushlogin || ln -f -s $BASEDIR/hushlogin $HOME/.hushlogin
test -L $HOME/.tmux.conf || ln -f -s $BASEDIR/tmux $HOME/.tmux.conf
test -L $HOME/.config/starship.toml || ln -f -s $BASEDIR/starship.toml $HOME/.config/starship.toml
test -L $HOME/.config/jmb.omp.toml || ln -f -s $BASEDIR/jmb.omp.toml $HOME/.config/jmb.omp.toml
test -d $HOME/.sheldon || mkdir $HOME/.sheldon
test -L $HOME/.sheldon/plugins.toml || ln -f -s $BASEDIR/sheldon.toml $HOME/.sheldon/plugins.toml
test -d $HOME/.config/sheldon || mkdir $HOME/.config/sheldon
test -L $HOME/.config/sheldon/plugins.toml || ln -f -s $BASEDIR/sheldon.toml $HOME/.config/sheldon/plugins.toml
test -L $HOME/.zsh || ln -f -s $BASEDIR/zsh $HOME/.zsh
test -L $HOME/.zshrc || ln -f -s $BASEDIR/zshrc.zsh $HOME/.zshrc

View file

@ -1,25 +1,43 @@
# `sheldon` configuration file
# ----------------------------
# Sheldon configuration file
#
# You can modify this file directly or you can use one of the following
# `sheldon` commands which are provided to assist in editing the config file:
# See https://sheldon.cli.rs
#
# - `sheldon add` to add a new plugin to the config file
# - `sheldon edit` to open up the config file in the default editor
# - `sheldon remove` to remove a plugin from the config file
#
# See the documentation for more https://github.com/rossmacarthur/sheldon#readme
# Also heavily inspired by https://github.com/rossmacarthur/dotfiles/tree/trunk
shell = "zsh"
[templates]
defer = { value = 'zsh-defer source "{{ file }}"', each = true }
defer = """{{ hooks?.pre | nl }}{% for file in files %}zsh-defer source "{{ file }}"\n{% endfor %}{{ hooks?.post | nl }}"""
defer-more = """{{ hooks?.pre | nl }}{% for file in files %}zsh-defer -t 0.5 source "{{ file }}"\n{% endfor %}{{ hooks?.post | nl }}"""
[plugins]
# Completions
# -----------
[plugins.zsh-completions]
github = "zsh-users/zsh-completions"
# Sourced
# -------
[plugins.zsh-defer]
github = "romkatv/zsh-defer"
[plugins.iterm2-shell-integration]
remote = "https://iterm2.com/shell_integration/zsh"
# Some of the functions may get used elsewhere
# so we do not defer loading
[plugins.functions]
local = "~/.zsh/plugins"
# Deferred plugins
# ----------------
[plugins.aliases]
local = "~/.zsh/plugins"
apply = ["defer"]
[plugins.zsh-syntax-highlighting]
github = "zsh-users/zsh-syntax-highlighting"
apply = ["defer"]
@ -32,3 +50,49 @@ apply = ["defer"]
github = "zsh-users/zsh-autosuggestions"
apply = ["defer"]
use = ["{{ name }}.zsh"]
[plugins.zsh-you-should-use]
github = "MichaelAquilina/zsh-you-should-use"
apply = ["defer"]
hooks.pre = "export YSU_MODE=ALL"
[plugins.forgit]
github = "wfxr/forgit"
apply = ["defer"]
[plugins.fnm]
local = "~/.zsh/plugins"
apply = ["defer"]
[plugins.zoxide]
local = "~/.zsh/plugins"
apply = ["defer"]
[plugins.mcfly]
local = "~/.zsh/plugins"
apply = ["defer"]
[plugins.thefuck]
local = "~/.zsh/plugins"
apply = ["defer"]
[plugins.fzf]
local = "~/.zsh/plugins"
apply = ["defer"]
hooks.pre = "export FZF_COMPLETION_TRIGGER='~~'"
# This works best if it is placed last.
[plugins.compinit]
local = "~/.zsh/plugins"
apply = ["defer"]
# Plugins that are even more deferred
# -----------------------------------
[plugins.github-copilot]
local = "~/.zsh/plugins"
apply = ["defer-more"]
[plugins.ngrok]
local = "~/.zsh/plugins"
apply = ["defer-more"]

View file

@ -1,27 +0,0 @@
# aliases.zsh
alias auao="sudo apt update && apt list --upgradable"
alias aupg="sudo apt upgrade"
alias aurup="sudo aura -Akua"
alias bubc="brew upgrade && brew cleanup"
alias bubo="brew update && brew outdated"
test $PLATFORM = 'osx' && alias brewcurl="/usr/local/opt/curl/bin/curl --cacert /usr/local/etc/openssl@1.1/cert.pem"
test $PLATFORM = 'osx-m1' && alias brewcurl="/opt/homebrew/opt/curl/bin/curl"
test $PLATFORM = 'osx' && alias brewssl="/usr/local/opt/openssl@1.1/bin/openssl"
alias ga="git add"
alias gf="git fetch --all; git fetch --tags"
alias gs="git status"
alias gb="git rev-parse --abbrev-ref HEAD"
alias irc="ssh jmb -t '. ~/.zshrc; tmux attach -t irc'"
test $PLATFORM = 'linux' && alias ls="ls -F --color=always"
test $PLATFORM = 'osx' && alias ls="ls -FG"
test $PLATFORM = 'osx-m1' && alias ls="ls -FG"
test $PLATFORM = 'linux' && alias pipup="pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U"
test $PLATFORM = 'osx' && alias pipup="pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U"
test $PLATFORM = 'osx-m1' && alias pipup="pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U"
alias rtor="tmux attach -t rtor"
alias startace="acestreamengine --client-console --upload-limit 0 --download-limit 0"
alias up="sudo pacman -Syu"
alias aws-whoami="aws sts get-caller-identity"
alias als="eza --oneline --long --classify --icons --header"
alias sail="[ -f sail ] && bash sail || bash vendor/bin/sail"

View file

@ -3,7 +3,6 @@ test -e /opt/homebrew/opt/fzf/shell/completion.zsh && source /opt/homebrew/opt/f
test -e /usr/share/fzf/completion.zsh && source /usr/share/fzf/completion.zsh
# cURL completions copied from https://blog.revathskumar.com/2024/02/curl-fuzzy-search-options-using-fzf.html
_fzf_complete_curl() {
_fzf_complete --header-lines=1 --prompt="curl> " -- "$@" < <(
curl -h all

View file

@ -1,14 +0,0 @@
export PLATFORM="unkown"
osname=$(uname -s)
cputype=$(uname -m)
if [[ "$osname" == 'Linux' ]]; then
export PLATFORM="linux"
elif [[ "$osname" == 'Darwin' ]]; then
if [[ "$cputpye" == 'x86_64' ]]; then
export PLATFORM="osx"
elif [[ "$cputype" == 'arm64' ]]; then
export PLATFORM="osx-m1"
fi
fi

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

@ -2,34 +2,8 @@
# Functions
# Generate TLS certs using a local CA
gencert () {
DOMAIN=$1
test -d /usr/local/opt/openssl@1.1/bin && PATH='/usr/local/opt/openssl@1.1/bin':$PATH
test -d /opt/homebrew/opt/openssl@1.1/bin && PATH='/opt/homebrew/opt/openssl@1.1/bin':$PATH
test -f /usr/local/etc/openssl@1.1/openssl.cnf && SSLCNF='/usr/local/etc/openssl@1.1/openssl.cnf'
test -f /opt/homebrew/etc/openssl@1.1/openssl.cnf && SSLCNF='/opt/homebrew/etc/openssl@1.1/openssl.cnf'
test -f /etc/ssl/openssl.cnf && SSLCNF='/etc/ssl/openssl.cnf'
cd $HOME/git/ca
[[ ! -d $DOMAIN ]] && mkdir $DOMAIN
cd $DOMAIN
[[ -f key ]] && mv key key.bak
[[ -f csr ]] && mv csr csr.bak
[[ -f crt ]] && mv crt crt.bak
openssl ecparam -name secp384r1 -genkey -noout -out key
chmod 644 key
openssl req -new -sha256 -key key -subj "/C=UK/ST=England/L=Bury/O=JMB Dev Ltd/CN=$DOMAIN" -reqexts SAN -config <(cat $SSLCNF <(printf "[SAN]\nsubjectAltName=DNS:$DOMAIN")) -out csr
openssl x509 -req -in csr -extfile <(cat $SSLCNF <(printf "[SAN]\nsubjectAltName=DNS:$DOMAIN")) -extensions SAN -CA ../jmb-ca-ecc.pem -CAkey ../jmb-ca-ecc.key -CAcreateserial -days 90 -sha256 -out crt
cd $HOME/git/ca
echo 'Certs generated for $DOMAIN'
}
# Delete branches selected via fzf
delete-branches () {
function delete-branches() {
git branch |
grep --invert-match '\*' | # Remove current branch
fzf --multi --preview="git log {..}" |
@ -37,7 +11,7 @@ delete-branches () {
}
# Delete branches selected via fzf (force the deletion)
delete-branches-force () {
function delete-branches-force() {
git branch |
grep --invert-match '\*' | # Remove current branch
fzf --multi --preview="git log {..}" |

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

View file

@ -1,7 +0,0 @@
# ZSH autosuggestions
test -e /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh \
&& source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
test -e /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh \
&& source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
test -e /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh \
&& source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh

View file

@ -1,20 +0,0 @@
# ZSH substring search
bindKeysZshHistoryMacOS() {
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
}
bindKeysZshHistoryLinux() {
zmodload zsh/terminfo
bindkey "$terminfo[cuu1]" history-substring-search-up
bindkey "$terminfo[cud1]" history-substring-search-down
}
test -e /usr/local/opt/zsh-history-substring-search/zsh-history-substring-search.zsh \
&& source /usr/local/opt/zsh-history-substring-search/zsh-history-substring-search.zsh
test -e /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh \
&& source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
test -e /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh \
&& source /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh
test $PLATFORM = 'osx' && bindKeysZshHistoryMacOS
test $PLATFORM = 'osx-m1' && bindKeysZshHistoryMacOS
test $PLATFORM = 'linux' && bindKeysZshHistoryLinux

View file

@ -1,7 +0,0 @@
# ZSH syntax highlghting
test -e /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh \
&& source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
test -e /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh \
&& source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
test -e /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh \
&& source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

134
zshrc.zsh
View file

@ -7,29 +7,11 @@ SAVEHIST=10000
# vim binddings
bindkey -v
# ZSH builtin autoload
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
FPATH=$(brew --prefix)/share/zsh/zsh-completions:$FPATH
fi
autoload -Uz compinit promptinit run-help zmv
compinit
promptinit
case $(type run-help) in
(*alias*) unalias run-help;;
esac
alias help=run-help
# Persistant rehash to find new programs in the $PATH
zstyle ':completion:*' rehash true
# You may need to manually set your language environment
export LANG=en_GB.UTF-8
# Preferred editor for local and remote sessions
export EDITOR='nvim'
# Set the DEFAULT_USER variable to me (jonny)
export DEFAULT_USER="jonny"
export EDITOR=nvim
# Autoadd to PATH (neede for MacTex)
# It prepends to $PATH, so we do it first then add our own
@ -39,34 +21,13 @@ fi
# Add our own dirs to the $PATH
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if [[ -f /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
eval "$(/usr/local/bin/brew shellenv)"
fi
export PATH="$HOME/.local/bin:$PATH"
# Source my own functions
source $HOME/.zsh/functions.zsh
# Determine the running OS
source $HOME/.zsh/platform.zsh
# Detect system appearance
export MACOS_APPEARANCE=`get-system-appearance`
# ZSH syntax highlighting
source $HOME/.zsh/zsh-syntax-highlighting.zsh
# ZSH history substring search
source $HOME/.zsh/zsh-substring-search.zsh
# ZSH autosuggestions
source $HOME/.zsh/zsh-autosuggestions.zsh
# Aliases
source $HOME/.zsh/aliases.zsh
# credit Paul Irish: https://github.com/paulirish/dotfiles/blob/606d85f083eb53853789ce9dcaf31a49756471bd/.zshrc#L80
# Automatically list directory contents on `cd`.
# Switched to using `exa` instead of `ls`.
@ -79,15 +40,13 @@ chpwd_functions=(${chpwd_functions[@]} "ezacd")
# Go Lang stuff
export GOPATH=$HOME/go
if type brew &>/dev/null; then
if (( ${+commands[brew]} )); then
export PATH="$PATH:$(brew --prefix)/go/bin:$(brew --prefix)/opt/go/libexec/bin:$GOPATH/bin"
fi
# GnuPG stuff
GPG_TTY=`tty`
export GPG_TTY
# Add various GNU functions
if type brew &>/dev/null; then
# Prepend them to the PATH so they override any system installed versions
if (( ${+commands[brew]} )); then
export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/findutils/libexec/gnubin:$PATH"
export PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:$PATH"
@ -107,12 +66,12 @@ export PATH="$PATH:$HOME/.composer/vendor/bin"
export PATH="$PATH:$HOME/.cargo/bin"
# Ruby PATH
if type brew &>/dev/null; then
export PATH="$PATH:$(brew --prefix)/opt/ruby/bin:$HOME/.gem/ruby/2.4.0/bin"
if (( ${+commands[brew]} )); then
export PATH="$PATH:$(brew --prefix)/opt/ruby/bin"
fi
# PostgreSQL binaries
if type brew &>/dev/null; then
if (( ${+commands[brew]} )); then
test -d $(brew --prefix)/pgsql && export PATH="$PATH:$(brew --prefix)/pgsql/bin"
fi
@ -123,17 +82,22 @@ test -d $HOME/.php/bin && export PATH="$PATH:$HOME/.php/bin"
test -d "$HOME/Library/Application Support/JetBrains/Toolbox/scripts" && export PATH="$PATH:$HOME/Library/Application Support/JetBrains/Toolbox/scripts"
# Homebrew cURL if we have it
if type brew &>/dev/null; then
if (( ${+commands[brew]} )); then
test -d $(brew --prefix)/opt/curl && export PATH="$(brew --prefix)/opt/curl/bin:$PATH"
fi
# Load plugins via Sheldon
if (( ${+commands[sheldon]} )); then
eval "$(sheldon source)"
fi
# Detect system appearance
export MACOS_APPEARANCE=`get-system-appearance`
# Colourised output for `ls`
# export CLICOLOR=true
# export CLICOLOR_FORCE=true
# export LSCOLORS='dxfxcxdxbxegedabagacad'
# export LS_COLORS='di=33;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
# vivid Dark mode ayu
# vivid Light mode snazzy
# vivid Light mode catppuccin-latte
if type vivid &>/dev/null; then
local vividTheme="ayu"
if [[ $MACOS_APPEARANCE == "light" ]]; then
@ -152,65 +116,13 @@ if [[ $MACOS_APPEARANCE == "light" ]]; then
fi
export BAT_THEME=$batTheme
# Setup fzf completions
export FZF_COMPLETION_TRIGGER='~~'
if type fzf > /dev/null; then
eval "$(fzf --zsh)"
fi
# Source the iTerm2 shell integration
test -e ${HOME}/.iterm2_shell_integration.zsh && source ${HOME}/.iterm2_shell_integration.zsh
# Source the untracked `extra` file
test -e $HOME/.extra && source $HOME/.extra
# You Should Use
test -e /opt/homebrew/share/zsh-you-should-use/you-should-use.plugin.zsh && source /opt/homebrew/share/zsh-you-should-use/you-should-use.plugin.zsh
test -e /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh && source /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh
# Setup Fast Node Manager
if type fnm > /dev/null; then
eval "$(fnm env --use-on-cd)"
fi
# 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
# Init the fuck
if type thefuck > /dev/null; then
eval "$(thefuck --alias)"
fi
# https://github.com/wfxr/forgit
test -e $HOME/git/forgit/forgit.plugin.zsh && source $HOME/git/forgit/forgit.plugin.zsh
test -e $HOME/git/forgit/completionsgit-forgit.zsh && source $HOME/git/forgit/completionsgit-forgit.zsh
# McFly
if type mcfly > /dev/null; then
eval "$(mcfly init zsh)"
fi
# ngrok completions
if command -v ngrok &>/dev/null; then
eval "$(ngrok completion)"
fi
# zoxide - a better `cd` command
if command -v zoxide &>/dev/null; then
eval "$(zoxide init zsh)"
fi
# Init starship prompt -- https://starship.rs
#eval "$(starship init zsh)"
# Oh My Posh
eval "$(oh-my-posh init zsh --config $HOME/.config/jmb.omp.toml)"
if (( ${+commands[oh-my-posh]} )); then
eval "$(oh-my-posh init zsh --config $HOME/.config/jmb.omp.toml)"
fi
# Finally we can have zsh auto source this rc file on command
# attribution: https://www.reddit.com/r/commandline/comments/12g76v/