Skip to content

Commit

Permalink
feat: split .zshrc to individual files
Browse files Browse the repository at this point in the history
split `$XDG_CONFIG_HOME/zsh/.zshrc` up into
`$XDG_CONFIG_HOME/zsh/.zshrc.d/*`. This allows for better management
and prioritization between different tool's env. Similar to what was
done to `.profile` in e712243 (feat: split `.profile` to individual
files, 2023-02-10).
  • Loading branch information
tobyvin committed Feb 11, 2023
1 parent 63393e6 commit 17fa2c0
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 74 deletions.
4 changes: 4 additions & 0 deletions bottom/.config/zsh/.zshrc.d/20-bottom.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/zsh
# vim:ft=sh

alias top="btm --basic"
File renamed without changes.
16 changes: 16 additions & 0 deletions docker/.config/zsh/.zshrc.d/20-docker.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/zsh
# vim:ft=sh

alias dexec="docker exec -it"
alias dps="docker ps"
alias dc="docker compose"
alias dce="docker compose exec"
alias dcps="docker compose ps"
alias dcls="docker compose ls"
alias dcdn="docker compose down"
alias dcup="docker compose up"
alias dcupd="docker compose up -d"
alias dcl="docker compose logs"
alias dclf="docker compose logs -f"
alias dct="docker context"
alias dcu="docker context use"
10 changes: 10 additions & 0 deletions fzf/.config/zsh/.zshrc.d/50-fzf.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/zsh
# vim: ft=sh

_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}

_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
34 changes: 34 additions & 0 deletions fzf/.local/bin/live-grep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

need() {
for need_cmd in "$@"; do
if ! command -v "$need_cmd" >/dev/null 2>&1; then
printf "live-grep: command not found: %s\n" "$need_cmd" >&2
exit 1
fi
done
}

need "rg" "bat"

INITIAL_QUERY="${*:-}"
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
PREVIEW_CMD='bat --color=always {1} --highlight-line {2} 2>/dev/null || bat --color=always {}'
INITIAL_CMD="$RG_PREFIX --files"

if [ $# -gt 0 ]; then
INITIAL_CMD="$RG_PREFIX '$INITIAL_QUERY'"
fi

# shellcheck disable=2046
set -- $(
FZF_DEFAULT_COMMAND="$INITIAL_CMD" fzf \
--ansi --color="hl:-1:underline,hl+:-1:underline:reverse" \
--bind="change:reload:sleep 0.1; [ -n {q} ] && ($RG_PREFIX {q} || true) || $RG_PREFIX --files" \
--disabled --query="$INITIAL_QUERY" --delimiter=":" \
--preview="$PREVIEW_CMD" --preview-window='up,60%,border-bottom,+{2}+3/3,~3'
)

if [ $# -gt 0 ]; then
xdg-open "$1" "+$2"
fi
4 changes: 4 additions & 0 deletions gnupg/.config/zsh/.zshrc.d/20-gnupg.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/zsh
# vim:ft=sh

alias unlock='echo "" | gpg --clearsign 1>/dev/null && ssh localhost -- : 1>/dev/null'
4 changes: 4 additions & 0 deletions sheldon/.config/profile.d/20-sheldon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

SHELDON_PROFILE="$(uname -r 2>/dev/null | rev | cut -d- -f1 | rev)"
export SHELDON_PROFILE
8 changes: 0 additions & 8 deletions sheldon/.config/sheldon/plugins.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ github = 'romkatv/zsh-defer'
[plugins.zsh-vi-mode]
github = "jeffreytse/zsh-vi-mode"

[plugins.zsh-wsl]
local = '~/.local/share/wsl/shell'
profiles = ["WSL2"]

[plugins.zsh-autosuggestions]
github = "zsh-users/zsh-autosuggestions"
use = ["{{ name }}.zsh"]
Expand Down Expand Up @@ -50,7 +46,3 @@ apply = ["defer"]
[plugins.zsh-fzf-history-search]
github = "joshskidmore/zsh-fzf-history-search"
apply = ["defer"]

[plugins.compinit]
local = '~/.local/share/zsh/plugins'
apply = ["defer"]
3 changes: 3 additions & 0 deletions sheldon/.config/zsh/.zshrc.d/80-sheldon.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/zsh

source <(sheldon source)
3 changes: 3 additions & 0 deletions starship/.config/zsh/.zshrc.d/70-starship.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/zsh

source <(starship init zsh)
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions texlive/.config/zsh/.zshrc.d/20-texlive.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/zsh
# vim:ft=sh

alias tlmgr='/usr/share/texmf-dist/scripts/texlive/tlmgr.pl --usermode'
File renamed without changes.
4 changes: 4 additions & 0 deletions wget/.config/zsh/.zshrc.d/20-wget.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/zsh
# vim:ft=sh

alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
File renamed without changes.
69 changes: 5 additions & 64 deletions zsh/.config/zsh/.zshrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/zsh
# vim: ft=sh
# shellcheck shell=sh
# shellcheck disable=3000-4000,1090

export HYPHEN_INSENSITIVE="true"
export DISABLE_UPDATE_PROMPT="true"
Expand All @@ -23,15 +21,12 @@ setopt hist_verify # show command with history expansion to user befo
setopt share_history # share command history data
setopt nonomatch

zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"

bindkey -v
bindkey -m 2>/dev/null

# TODO: improve this with terminfo validation
#
# See: https://wiki.archlinux.org/title/Zsh#Key_bindings
bindkey '^ ' autosuggest-accept
bindkey '^[q' push-line
bindkey '^[[Z' reverse-menu-complete
bindkey '^[[1~' beginning-of-line
Expand All @@ -40,7 +35,6 @@ bindkey '^[[3~' delete-char
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word

bindkey -M vicmd '^ ' autosuggest-accept
bindkey -M vicmd '^[q' push-line
bindkey -M vicmd '^[[Z' reverse-menu-complete
bindkey -M vicmd '^[[1~' beginning-of-line
Expand All @@ -54,62 +48,9 @@ alias tree="tree --gitignore"
alias grep='grep --color=auto'
alias ipa="ip -s -c -h a"
alias untar="tar -zxvf"
alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
alias tlmgr='/usr/share/texmf-dist/scripts/texlive/tlmgr.pl --usermode'
alias unlock='echo "" | gpg --clearsign 1>/dev/null && ssh localhost -- : 1>/dev/null'

SHELDON_PROFILE="$(uname -r 2>/dev/null | rev | cut -d- -f1 | rev)"
export SHELDON_PROFILE
export ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern line)
export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd completion)
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#4f4738"

if command -v fd >/dev/null 2>&1; then
_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}
fi

if command -v fd >/dev/null 2>&1; then
_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
fi

if command -v btm >/dev/null 2>&1; then
alias top="btm --basic"
fi

if command -v docker >/dev/null 2>&1; then
alias dexec="docker exec -it"
alias dps="docker ps"
alias dc="docker compose"
alias dce="docker compose exec"
alias dcps="docker compose ps"
alias dcls="docker compose ls"
alias dcdn="docker compose down"
alias dcup="docker compose up"
alias dcupd="docker compose up -d"
alias dcl="docker compose logs"
alias dclf="docker compose logs -f"
alias dct="docker context"
alias dcu="docker context use"
fi

if command -v rga >/dev/null 2>&1; then
rgi() {
RG_PREFIX="rga --files-with-matches"
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
xdg-open "$file"
}
fi

command -v starship >/dev/null 2>&1 && source <(starship init zsh)
command -v sheldon >/dev/null 2>&1 && source <(sheldon source)
for script in "$XDG_CONFIG_HOME"/zsh/.zshrc.d/*.zsh; do
if [ -r "$script" ]; then
source "$script"
fi
done
8 changes: 8 additions & 0 deletions zsh/.config/zsh/.zshrc.d/20-autosuggest.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/zsh
# vim:ft=sh

bindkey '^ ' autosuggest-accept
bindkey -M vicmd '^ ' autosuggest-accept

export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd completion)
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#4f4738"
4 changes: 4 additions & 0 deletions zsh/.config/zsh/.zshrc.d/20-highlight.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/zsh
# vim:ft=sh

export ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern line)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/zsh

zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"

# Load all stock functions (from $fpath files) called below.
autoload -U compaudit compinit

Expand All @@ -21,8 +23,8 @@ 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
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
Expand Down

0 comments on commit 17fa2c0

Please sign in to comment.