From 6de17552a4ba9dee026eab734a0454d84ab58f8c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 13 Jul 2022 00:03:34 +0100 Subject: [PATCH] fix(zsh): `g` function not autocompleting --- roles/zsh/files/config/.zshrc | 7 ++++++- roles/zsh/files/config/configs/git.zsh | 12 ------------ roles/zsh/files/config/configs/post/completion.zsh | 14 ++------------ roles/zsh/files/config/configs/prompt.zsh | 6 +++--- roles/zsh/files/config/functions/g | 9 +++++++++ 5 files changed, 20 insertions(+), 28 deletions(-) delete mode 100644 roles/zsh/files/config/configs/git.zsh create mode 100644 roles/zsh/files/config/functions/g diff --git a/roles/zsh/files/config/.zshrc b/roles/zsh/files/config/.zshrc index 7ab803cc..5f2bd58e 100644 --- a/roles/zsh/files/config/.zshrc +++ b/roles/zsh/files/config/.zshrc @@ -1,10 +1,13 @@ +for function in $ZDOTDIR/functions/*; do + source "${function}" +done + sources=( 'aliases' 'colour' 'functions' 'fzf' 'general' - 'git' 'history' 'navigation' 'nvm' @@ -13,8 +16,10 @@ sources=( 'platformsh' 'plugins' 'prompt' + 'post/completion' ) + for s in "${sources[@]}"; do source $ZDOTDIR/configs/${s}.zsh done diff --git a/roles/zsh/files/config/configs/git.zsh b/roles/zsh/files/config/configs/git.zsh deleted file mode 100644 index 6268bdc0..00000000 --- a/roles/zsh/files/config/configs/git.zsh +++ /dev/null @@ -1,12 +0,0 @@ -compdef g=git - -# No arguments: `git status` -# With arguments: acts like `git` -g() { - if [[ $# > 0 ]]; - then - git $@ - else - git status --short --branch - fi -} diff --git a/roles/zsh/files/config/configs/post/completion.zsh b/roles/zsh/files/config/configs/post/completion.zsh index 2f5ac0bc..4cc7bc31 100644 --- a/roles/zsh/files/config/configs/post/completion.zsh +++ b/roles/zsh/files/config/configs/post/completion.zsh @@ -1,17 +1,7 @@ # load our own completion functions -fpath=(~/.zsh/completion-scripts /usr/local/share/zsh/site-functions $fpath) +fpath=(~/.config/zsh/completion-scripts $fpath) -# completion; use cache if updated within 24h -autoload -Uz compinit -if [[ -n $HOME/.zcompdump(#qN.mh+24) ]]; then - compinit -d $HOME/.zcompdump; -else - compinit -C; -fi; - -# disable zsh bundled function mtools command mcd -# which causes a conflict. -compdef -d mcd +autoload -Uz compinit && compinit ## case-insensitive (all), partial-word and then substring completion zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' \ diff --git a/roles/zsh/files/config/configs/prompt.zsh b/roles/zsh/files/config/configs/prompt.zsh index 46e359e7..fecd9fc8 100644 --- a/roles/zsh/files/config/configs/prompt.zsh +++ b/roles/zsh/files/config/configs/prompt.zsh @@ -3,13 +3,13 @@ setopt prompt_subst git_branch() { local branch="$(git symbolic-ref HEAD 2> /dev/null | cut -d'/' -f3)" - [ -n "${branch}" ] && echo " (${branch})" + [ -n "${branch}" ] && echo " ${branch}" } git_commit() { local commit_sha="$(git rev-parse --short HEAD 2> /dev/null)" - [ -n "${commit_sha}" ] && echo " [${commit_sha}]" + [ -n "${commit_sha}" ] && echo " [%{$fg[yellow]%}${commit_sha}%{$reset_color%}]" } -export PS1='%{$fg[blue]%}%1d%{$reset_color%}%{$fg[green]%}$(git_branch)%{$reset_color%}%{$fg[yellow]%}$(git_commit)%{$reset_color%} $ ' +export PS1='%{$fg[blue]%}%~%{$reset_color%}%{$fg[green]%}$(git_branch)%{$reset_color%}$(git_commit) $ ' diff --git a/roles/zsh/files/config/functions/g b/roles/zsh/files/config/functions/g new file mode 100644 index 00000000..438db752 --- /dev/null +++ b/roles/zsh/files/config/functions/g @@ -0,0 +1,9 @@ +# No arguments: `git status` +# With arguments: acts like `git` +g() { + if [[ $# -gt 0 ]]; then + git "$@" + else + git status + fi +}