From 889fd62e1747ab53dddc12dfb4538b3dc7e8d9e7 Mon Sep 17 00:00:00 2001 From: surtur Date: Fri, 8 Sep 2023 14:12:40 +0200 Subject: [PATCH] zsh: split functionality into child files --- .zsh/bindings.zsh | 21 +++++++++++++++++++++ .zsh/fzf.zsh | 12 ++++++++++++ .zsh/zvm.zsh | 17 +++++++++++++++++ .zshrc | 46 ++++------------------------------------------ 4 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 .zsh/bindings.zsh create mode 100644 .zsh/fzf.zsh create mode 100644 .zsh/zvm.zsh diff --git a/.zsh/bindings.zsh b/.zsh/bindings.zsh new file mode 100644 index 0000000..73a0755 --- /dev/null +++ b/.zsh/bindings.zsh @@ -0,0 +1,21 @@ +# as per https://github.com/jeffreytse/zsh-vi-mode#execute-extra-commands +function zvm_after_lazy_keybindings() { + # map Del escape sequence to actual Del key in all (n,i) modes to resemble vim instead of vi + bindkey -a '^[[3~' delete-char + # map arrow up/down to control fish-like history substring search and highlighting + bindkey '^[[A' history-substring-search-up + bindkey '^[[B' history-substring-search-down + bindkey '^o' fzf-open + # also map the same keys in 'viins' (INSERT) mode... + bindkey -M viins '^[[A' history-substring-search-up + bindkey -M viins '^[[B' history-substring-search-down + bindkey -M viins '^o' fzf-open + # ...and in 'vicmd' (NORMAL) mode... + bindkey -M vicmd '^[[A' history-substring-search-up + bindkey -M vicmd '^[[B' history-substring-search-down + # ...and as well to K, J, instead of arrow up/down, respectively. + # note these are capital letters, original behaviour of j, k is left unchanged + bindkey -M vicmd 'K' history-substring-search-up + bindkey -M vicmd 'J' history-substring-search-down + bindkey '^\' accept-and-hold +} diff --git a/.zsh/fzf.zsh b/.zsh/fzf.zsh new file mode 100644 index 0000000..eb1e6a0 --- /dev/null +++ b/.zsh/fzf.zsh @@ -0,0 +1,12 @@ +export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --exclude 'node_modules' --exclude 'nix/profiles' ." + +# export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" +export FZF_CTRL_T_COMMAND="fd --follow --full-path --hidden --base-directory . --exclude '.git' --exclude 'node_modules' --exclude 'nix/profiles' ." +export FZF_ALT_C_COMMAND="fd -H -t d ." +export DISABLE_FZF_AUTO_COMPLETION="true" +# Options to fzf command +export FZF_COMPLETION_OPTS='+c -x' +export FZF_DEFAULT_OPTS="--height=60% --inline-info --bind=ctrl-j:preview-half-page-down,ctrl-k:preview-half-page-up --color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9 --color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9 --color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6 --color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4" +# Using highlight (http://www.andre-simon.de/doku/highlight/en/highlight.html) +# export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'" +export FZF_CTRL_T_OPTS="--preview 'bat --style=numbers --color=always --line-range :200 {}'" diff --git a/.zsh/zvm.zsh b/.zsh/zvm.zsh new file mode 100644 index 0000000..1da3e86 --- /dev/null +++ b/.zsh/zvm.zsh @@ -0,0 +1,17 @@ +# if [[ "$(hostnamectl hostname)" == "sth" ]]; then +# if [[ "$(hostname -s)" == "sth" ]]; then +if [[ "$(lsb_release -i -s)" == "Arch" ]]; then + local fzf_bindings="/usr/share/fzf/key-bindings.zsh" +elif [[ "$(lsb_release -i -s)" == "Fedora" ]]; then + local fzf_bindings="/usr/share/fzf/shell/key-bindings.zsh" +fi + +zvm_after_init_commands+=("[ -f $fzf_bindings ] && source $fzf_bindings") + +unset fzf_bindings + +function zvm_config() { + ZVM_LINE_INIT_MODE=$ZVM_MODE_INSERT + ZVM_CURSOR_STYLE_ENABLED=false + # ZVM_INSERT_MODE_CURSOR=$ZVM_CURSOR_BLINKING_BLOCK +} diff --git a/.zshrc b/.zshrc index 0c525a9..1223047 100644 --- a/.zshrc +++ b/.zshrc @@ -110,52 +110,14 @@ ZSH_THEME_GIT_PROMPT_CACHE=" " - # map Del escape sequence to actual Del key in all (n,i) modes to resemble vim instead of vi - bindkey -a '^[[3~' delete-char - # map arrow up/down to control fish-like history substring search and highlighting - bindkey '^[[A' history-substring-search-up - bindkey '^[[B' history-substring-search-down - bindkey '^o' fzf-open - # also map the same keys in 'viins' (INSERT) mode... - bindkey -M viins '^[[A' history-substring-search-up - bindkey -M viins '^[[B' history-substring-search-down - bindkey -M viins '^o' fzf-open - # ...and in 'vicmd' (NORMAL) mode... - bindkey -M vicmd '^[[A' history-substring-search-up - bindkey -M vicmd '^[[B' history-substring-search-down - # ...and as well to K, J, instead of arrow up/down, respectively. - # note these are capital letters, original behaviour of j, k is left unchanged - bindkey -M vicmd 'K' history-substring-search-up - bindkey -M vicmd 'J' history-substring-search-down - bindkey '^\' accept-and-hold HISTORY_SUBSTRING_SEARCH_FUZZY=" " - export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --exclude 'node_modules' --exclude 'nix/profiles' ." - - # export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" - export FZF_CTRL_T_COMMAND="fd --follow --full-path --hidden --base-directory . --exclude '.git' --exclude 'node_modules' --exclude 'nix/profiles' ." - export FZF_ALT_C_COMMAND="fd -H -t d ." - export DISABLE_FZF_AUTO_COMPLETION="true" - # Options to fzf command - export FZF_COMPLETION_OPTS='+c -x' - export FZF_DEFAULT_OPTS="--height=60% --inline-info --bind=ctrl-j:preview-half-page-down,ctrl-k:preview-half-page-up --color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9 --color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9 --color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6 --color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4" - # Using highlight (http://www.andre-simon.de/doku/highlight/en/highlight.html) - # export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'" - export FZF_CTRL_T_OPTS="--preview 'bat --style=numbers --color=always --line-range :200 {}'" - - # if [[ "$(hostnamectl hostname)" == "sth" ]]; then - # if [[ "$(hostname -s)" == "sth" ]]; then - if [[ "$(lsb_release -i -s)" == "Arch" ]]; then - local fzf_bindings="/usr/share/fzf/key-bindings.zsh" - elif [[ "$(lsb_release -i -s)" == "Fedora" ]]; then - local fzf_bindings="/usr/share/fzf/shell/key-bindings.zsh" - fi - zvm_after_init_commands+=("[ -f $fzf_bindings ] && source $fzf_bindings") - unset fzf_bindings - # ZVM_INSERT_MODE_CURSOR=$ZVM_CURSOR_BLINKING_BLOCK - local __tosrc=( + ~/.zsh/bindings.zsh + ~/.zsh/fzf.zsh + ~/.zsh/zvm.zsh + ~/.dotenv ${XDG_RUNTIME_DIR}/secrets/envs ~/.zsh/aliases.zsh