Move zsh and aliases to conf.d style configs

This commit is contained in:
Daniel Lynn 2023-03-30 15:46:14 -05:00
parent f3e303fd93
commit 2cbf3d6e55
Signed by: daniel
GPG Key ID: 28496A140E180A9D
21 changed files with 181 additions and 188 deletions

View File

@ -1,16 +1,3 @@
alias e="$EDITOR"
alias app="./bin/app"
if (( $+commands[exa] )); then
alias l="exa --git --icons --grid"
alias ll="exa --git --icons --long --grid"
alias lt="exa --git --icons --long --tree --level=2"
fi
if (( $+commands[helix] )); then
alias hx="helix"
fi
if (( $+commands[coreutils] )); then
alias \[="coreutils \["
alias b2sum="coreutils b2sum"

8
aliases.d/editor.zsh Normal file
View File

@ -0,0 +1,8 @@
alias e="$EDITOR"
# Use $FINDER and $EDITOR
if (( $+commands[$FINDER] )); then
e?() {
$EDITOR $($FINDER)
}
fi

5
aliases.d/exa.zsh Normal file
View File

@ -0,0 +1,5 @@
if (( $+commands[exa] )); then
alias l="exa --git --icons --grid"
alias ll="exa --git --icons --long --grid"
alias lt="exa --git --icons --long --tree --level=2"
fi

3
aliases.d/helix.zsh Normal file
View File

@ -0,0 +1,3 @@
if (( $+commands[helix] )); then
alias hx="helix"
fi

1
aliases.d/toolshed.zsh Normal file
View File

@ -0,0 +1 @@
alias app="./bin/app"

View File

@ -52,6 +52,7 @@ tmux_conf = { source = "tmux.conf", target = ".tmux.conf" }
zellij = { source = "zellij", target = ".config/zellij" }
# zsh
zsh = { source = "aliases", target = ".aliases" }
zshconfigs = { source = "zsh.d", target = ".config/zsh.d" }
zshaliases = { source = "aliases.d", target = ".config/aliases.d" }
zshenv = { source = "zshenv", target = ".zshenv" }
zshrc = { source = "zshrc", target = ".zshrc" }

View File

@ -0,0 +1,4 @@
# Autosuggestions
if [[ -s /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]]; then
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
fi

4
zsh.d/broot.zsh Normal file
View File

@ -0,0 +1,4 @@
# broot
if [[ -s ~/.config/broot/launcher/bash/br ]]; then
source ~/.config/broot/launcher/bash/br
fi

4
zsh.d/direnv.zsh Normal file
View File

@ -0,0 +1,4 @@
# Per-directory env
if (( $+commands[direnv])); then
eval "$(direnv hook zsh)"
fi

33
zsh.d/exa.zsh Normal file
View File

@ -0,0 +1,33 @@
# exa
if (( $+commands[exa] )); then
# exa explorer
exex() {
local depth=1
local old_depth=0
local min_depth=1
local max_depth=3
local exa_opts=("--color=always" "--git" "--icons" "-F" "-T")
while true; do
if [[ $depth -ne $old_depth ]]; then
local old_depth=$depth
clear
exa $exa_opts -L$depth
fi
read -sk key
case $key in
h)
[[ $depth -gt $min_depth ]] && (( depth-- ))
;;
l)
[[ $depth -lt $max_depth ]] && (( depth++ ))
;;
q)
break
;;
esac
done
}
fi

10
zsh.d/fd.zsh Normal file
View File

@ -0,0 +1,10 @@
# Use fd for fzf
if (( $+commands[fd] && $+commands[fzf] )); then
_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}
_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
fi

12
zsh.d/gh.zsh Normal file
View File

@ -0,0 +1,12 @@
# gh
if (( $+commands[gh] )); then
gh_chpwd_hook() {
if [[ -d ".github" ]]; then
gh pr list
fi
}
chpwd_functions+=( gh_chpwd_hook )
gh_chpwd_hook
fi

12
zsh.d/git.zsh Normal file
View File

@ -0,0 +1,12 @@
# git
if (( $+commands[git] )); then
git_chpwd_hook() {
if [[ -d ".git" ]]; then
git status
fi
}
chpwd_functions+=( git_chpwd_hook )
git_chpwd_hook
fi

4
zsh.d/manjaro.zsh Normal file
View File

@ -0,0 +1,4 @@
# Source manjaro-zsh-configuration
if [[ -e /usr/share/zsh/manjaro-zsh-config ]]; then
source /usr/share/zsh/manjaro-zsh-config
fi

4
zsh.d/navi.zsh Normal file
View File

@ -0,0 +1,4 @@
# Cheat my way through the CLI
if (( $+commands[navi] )); then
eval "$(navi widget zsh)"
fi

7
zsh.d/nvm.zsh Normal file
View File

@ -0,0 +1,7 @@
# NVM
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
source "$NVM_DIR/nvm.sh" # This loads nvm
fi
if [[ -s "$NVM_DIR/bash_completion" ]]; then
source "$NVM_DIR/bash_completion" # This loads nvm bash_completion
fi

26
zsh.d/prompt.zsh Normal file
View File

@ -0,0 +1,26 @@
# Use a prompt, depending on what is available:
# 1. starship
# 2. p10k
# 3. manjaro
if (( $+commands[starship] )); then
eval "$(starship init zsh)"
else
if [[ -s ~/.p10k.zsh ]]; then
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
source ~/.p10k.zsh
else
# Use powerline
USE_POWERLINE="true"
# Use manjaro zsh prompt
if [[ -e /usr/share/zsh/manjaro-zsh-prompt ]]; then
source /usr/share/zsh/manjaro-zsh-prompt
fi
fi
fi

View File

@ -0,0 +1,6 @@
# Virtualenvwrapper
if [[ -s "$HOME/.local/bin/virtualenvwrapper_lazy.sh" ]]; then
source "$HOME/.local/bin/virtualenvwrapper_lazy.sh"
elif [[ -s "$HOME/.local/bin/virtualenvwrapper.sh" ]]; then
source "$HOME/.local/bin/virtualenvwrapper.sh"
fi

18
zsh.d/zellij.zsh Normal file
View File

@ -0,0 +1,18 @@
# zellij
if (( $+commands[zellij] )); then
ZELLIJ_AUTO_ATTACH=true
eval "$(zellij setup --generate-auto-start zsh)"
ide() {
local layout="${ZELLIJ_LAYOUT:-${HOME}/.config/zellij/layouts/project.kdl}"
local name="${PWD##*/}"
local name="${name:-/}"
if (( ${+ZELLIJ} )); then
# FIXME: https://github.com/zellij-org/zellij/issues/2299
zellij action new-tab --layout "${layout}" --cwd "${PWD}" --name "${name}"
else
zellij --layout "${layout}" $@
fi
}
fi

4
zsh.d/zoxide.zsh Normal file
View File

@ -0,0 +1,4 @@
# Intelligent and fast autojump
if (( $+commands[zoxide] )); then
eval "$(zoxide init zsh)"
fi

188
zshrc
View File

@ -4,182 +4,22 @@ unsetopt nomatch
# Swap CAPSLOCK and ESC
setxkbmap -option caps:swapescape
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Use powerline
USE_POWERLINE="true"
# Source manjaro-zsh-configuration
if [[ -e /usr/share/zsh/manjaro-zsh-config ]]; then
source /usr/share/zsh/manjaro-zsh-config
fi
# Use a prompt, depending on what is available:
# 1. starship
# 2. p10k
# 3. manjaro
if (( $+commands[starship] )); then
eval "$(starship init zsh)"
else
if [[ -s ~/.p10k.zsh ]]; then
source ~/.p10k.zsh
else
# Use manjaro zsh prompt
if [[ -e /usr/share/zsh/manjaro-zsh-prompt ]]; then
source /usr/share/zsh/manjaro-zsh-prompt
fi
fi
fi
# Autosuggestions
if [[ -s /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]]; then
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
fi
# Intelligent and fast autojump
if (( $+commands[zoxide] )); then
eval "$(zoxide init zsh)"
fi
# Cheat my way through the CLI
if (( $+commands[navi] )); then
eval "$(navi widget zsh)"
fi
# Per-directory env
if (( $+commands[direnv])); then
eval "$(direnv hook zsh)"
fi
# Use $FINDER and $EDITOR
if (( $+commands[$FINDER] )); then
e?() {
$EDITOR $($FINDER)
}
fi
# Use fd for fzf
if (( $+commands[fd] && $+commands[fzf] )); then
_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}
_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
fi
# Custom aliases
if [[ -s ~/.aliases ]]; then
source ~/.aliases
fi
if [[ -s ~/.aliases.local ]]; then
source ~/.aliases.local
fi
# NVM
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
source "$NVM_DIR/nvm.sh" # This loads nvm
fi
if [[ -s "$NVM_DIR/bash_completion" ]]; then
source "$NVM_DIR/bash_completion" # This loads nvm bash_completion
fi
# Virtualenvwrapper
if [[ -s "$HOME/.local/bin/virtualenvwrapper_lazy.sh" ]]; then
source "$HOME/.local/bin/virtualenvwrapper_lazy.sh"
elif [[ -s "$HOME/.local/bin/virtualenvwrapper.sh" ]]; then
source "$HOME/.local/bin/virtualenvwrapper.sh"
fi
# broot
if [[ -s ~/.config/broot/launcher/bash/br ]]; then
source ~/.config/broot/launcher/bash/br
fi
# zellij
if (( $+commands[zellij] )); then
ZELLIJ_AUTO_ATTACH=true
eval "$(zellij setup --generate-auto-start zsh)"
ide() {
local layout="${ZELLIJ_LAYOUT:-${HOME}/.config/zellij/layouts/project.kdl}"
local name="${PWD##*/}"
local name="${name:-/}"
if (( ${+ZELLIJ} )); then
zellij action new-tab --layout "${layout}" --cwd "${PWD}" --name "${name}"
else
zellij --layout "${layout}" $@
fi
}
fi
# exa
if (( $+commands[exa] )); then
# exa explorer
exex() {
local depth=1
local old_depth=0
local min_depth=1
local max_depth=3
local exa_opts=("--color=always" "--git" "--icons" "-F" "-T")
while true; do
if [[ $depth -ne $old_depth ]]; then
local old_depth=$depth
clear
exa $exa_opts -L$depth
fi
read -sk key
case $key in
h)
[[ $depth -gt $min_depth ]] && (( depth-- ))
;;
l)
[[ $depth -lt $max_depth ]] && (( depth++ ))
;;
q)
break
;;
esac
done
}
fi
# git
if (( $+commands[git] )); then
git_chpwd_hook() {
if [[ -d ".git" ]]; then
git status
fi
}
chpwd_functions+=( git_chpwd_hook )
git_chpwd_hook
fi
# gh
if (( $+commands[gh] )); then
gh_chpwd_hook() {
if [[ -d ".github" ]]; then
gh pr list
fi
}
chpwd_functions+=( gh_chpwd_hook )
gh_chpwd_hook
fi
# conf.d style configurations
for config in "${HOME}/.config/zsh.d"/*; do
source "$config"
done
# Source machine-specific setup
if [[ -s ~/.zshrc.local ]]; then
source ~/.zshrc.local
fi
# conf.d style aliases
for config in "${HOME}/.config/aliases.d"/*; do
source "$config"
done
# Source machine-specific aliases
if [[ -s ~/.aliases.local ]]; then
source ~/.aliases.local
fi