diff --git a/.zsh/zsh-autocomplete b/.zsh/zsh-autocomplete new file mode 160000 index 00000000..d00142dd --- /dev/null +++ b/.zsh/zsh-autocomplete @@ -0,0 +1 @@ +Subproject commit d00142dd752c15aaa775d79c61ff0611acf20bad diff --git a/.zsh/zsh-autosuggestions b/.zsh/zsh-autosuggestions new file mode 160000 index 00000000..a411ef3e --- /dev/null +++ b/.zsh/zsh-autosuggestions @@ -0,0 +1 @@ +Subproject commit a411ef3e0992d4839f0732ebeb9823024afaaaa8 diff --git a/.zsh/zsh-fex/fex.zsh b/.zsh/zsh-fex/fex.zsh new file mode 100644 index 00000000..a580d239 --- /dev/null +++ b/.zsh/zsh-fex/fex.zsh @@ -0,0 +1,93 @@ +# Sets up ZSH widget for fex, this is needed for +# - launching fex with a shortcut +# - executing commands such as `cd` from fex + +# Stores ZSH before initialization options in `__fex_pre_init_options` +# such that evaluating the variable will restore the options. +# +# The variable is evaluated in the `always` block after setting up +# the fex ZSH widget. +# +# Taken, mostly verbatim, from: +# - https://github.com/junegunn/fzf/blob/master/shell/completion.zsh +if 'zmodload' 'zsh/parameter' 2>'/dev/null' && (( ${+options} )); then + __fex_pre_init_options="options=(${(j: :)${(kv)options[@]}})" +else + () { + __fex_pre_init_options="setopt" + 'local' '__fex_opt' + for __fex_opt in "${(@)${(@f)$(set -o)}%% *}"; do + if [[ -o "$__fex_opt" ]]; then + __fex_pre_init_options+=" -o $__fex_opt" + else + __fex_pre_init_options+=" +o $__fex_opt" + fi + done + } +fi + +'emulate' 'zsh' '-o' no_aliases + +{ + +FEX_COMMAND=${FEX_DEFAULT_COMMAND:-fex} + +function __fex_exec { + setopt localoptions pipefail no_aliases 2> /dev/null + + local item + # Echo every '\n' delimited item written to stdout + # the (q) ensures `item` is treated as a single word + # even if spaces. + $(echo $FEX_COMMAND) "$@" < /dev/tty | while read item; do + echo -n "${(q)item} " + done + + # Set previous command return code to ret so it can + # be returned. + local ret=$? + echo + return $ret +} + +function fex-widget { + setopt localoptions pipefail no_aliases 2> /dev/null + + # Single echo to preserve current prompt + echo + + EXEC_CMD="$(__fex_exec)" + + # Return code of executed fex returned command + local ret=$? + + # If no return value (normal quit) then reset prompt + if [[ -z "$EXEC_CMD" ]]; then + zle reset-prompt + return $ret + fi + + # Pushes BUFFER onto stack and clears it + zle push-line + + # BUFFER is ZSH env var, accept-line execs what's in BUFFER + BUFFER=$EXEC_CMD + zle accept-line + zle reset-prompt + + return $ret +} + +# Register ZSH widget fex-widget +zle -N fex-widget + +} always { + # Restore the original options. + eval $__fex_pre_init_options + 'unset' '__fex_pre_init_options' +} + +# References: +# - https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh +# - https://github.com/junegunn/fzf/blob/master/shell/completion.zsh +# - https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html diff --git a/.zsh/zsh-syntax-highlighting b/.zsh/zsh-syntax-highlighting new file mode 160000 index 00000000..c5ce0014 --- /dev/null +++ b/.zsh/zsh-syntax-highlighting @@ -0,0 +1 @@ +Subproject commit c5ce0014677a0f69a10b676b6038ad127f40c6b1 diff --git a/zshrc.txt b/zshrc.txt index 7e33abdd..28fdcc59 100644 --- a/zshrc.txt +++ b/zshrc.txt @@ -195,3 +195,6 @@ if [[ -f "$HOME/.sdrc" ]] ; then source "$HOME/.sdrc" fi [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + +[ -f ~/.zsh/zsh-fex/fex.zsh ] && source ~/.zsh/zsh-fex/fex.zsh +bindkey '^f' fex-widget