From 1f110837c60b11a09eda9f72d1262c49a4782a03 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 20 Nov 2022 03:17:52 -0800 Subject: [PATCH] Allow excluding directories from starship's git status module --- init.zsh | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/init.zsh b/init.zsh index f6573e3..e500d96 100644 --- a/init.zsh +++ b/init.zsh @@ -139,7 +139,7 @@ SPACESHIP_PACKAGE_SYMBOL=" " autoload -U promptinit && promptinit prompt spaceship # Change cursor shape for different vi modes. -function zle-line-init zle-keymap-select { +function __zsh_vim_key_prompt_handler { SPACESHIP_CHAR_SYMBOL="❮" local _shape=0 case "${KEYMAP}" in @@ -157,9 +157,37 @@ function zle-line-init zle-keymap-select { zle reset-prompt printf '\e[%d q' "${_shape}" } +function __zsh_check_disabled_git_prompt_dirs { + local excluded=false + for file in ${(s:\0:)__ZSH_PROMPT_EXCLUDE_GIT_STATUS}; do + if [[ "${PWD:P}/" = "${file}/"* ]]; then + SPACESHIP_GIT_STATUS_SHOW=false + excluded=true + break + fi + done + if ! $excluded; then + SPACESHIP_GIT_STATUS_SHOW=true + fi +} +function chpwd { + __zsh_check_disabled_git_prompt_dirs +} +function zle-line-init { + __zsh_vim_key_prompt_handler +} +function zle-keymap-select { + __zsh_vim_key_prompt_handler +} zle -N zle-keymap-select zle -N zle-line-init +# Exclude DIR from spaceship's git status module +# prompt_exclude_git_status +function prompt_exclude_git_status { + __ZSH_PROMPT_EXCLUDE_GIT_STATUS="${__ZSH_PROMPT_EXCLUDE_GIT_STATUS}\0${1:P}" +} + # Bookmarks [ -v ZSH_BOOKMARK_DIR ] || ZSH_BOOKMARK_DIR="${HOME}/.cache/zsh/bookmarks" [ -v ZSH_BOOKMARK_LS ] || ZSH_BOOKMARK_LS=true @@ -209,6 +237,7 @@ setopt histignoredups # Clean up internal functions unfunction load_plugin +unfunction prompt_exclude_git_status # Run fortune and cowsay if we are not in nvim [[ -v NVIM ]] || fortune | cowsay -felephant-in-snake -n