diff --git a/shell/completion.bash b/shell/completion.bash index 4ebeff7e..3eae1e73 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -36,9 +36,9 @@ __skimcmd_complete() { echo "sk-tmux -d${SKIM_TMUX_HEIGHT:-40%}" || echo "sk" } -_skim_orig_completion_filter() { - sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _skim_orig_completion_\3="\1 %s \3 #\2";/' | - awk -F= '{gsub(/[^A-Za-z0-9_= ;]/, "_", $1); print $1"="$2}' +__skim_orig_completion_filter() { + sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _skim_orig_completion_\3="\1 %s \3 #\2"; [[ "\1" = *" -o nospace "* ]] \&\& [[ ! "$__skim_nospace_commands" = *" \3 "* ]] \&\& __skim_nospace_commands="$__skim_nospace_commands \3 ";/' | + awk -F= '{OFS = FS} {gsub(/[^A-Za-z0-9_= ;]/, "_", $1);}1' } _skim_opts_completion() { @@ -111,7 +111,7 @@ _skim_opts_completion() { } _skim_handle_dynamic_completion() { - local cmd orig_var orig ret orig_cmd + local cmd orig_var orig ret orig_cmd orig_complete cmd="$1" shift orig_cmd="$1" @@ -120,10 +120,18 @@ _skim_handle_dynamic_completion() { if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then $orig "$@" elif [ -n "$_skim_completion_loader" ]; then + orig_complete=$(complete -p "$cmd" 2> /dev/null) _completion_loader "$@" ret=$? - eval "$(complete | command grep "\-F.* $orig_cmd$" | _skim_orig_completion_filter)" - source "${BASH_SOURCE[0]}" + # _completion_loader may not have updated completion for the command + if [ "$(complete -p "$cmd" 2> /dev/null)" != "$orig_complete" ]; then + eval "$(complete | command grep " -F.* $orig_cmd$" | __skim_orig_completion_filter)" + if [[ "$__skim_nospace_commands" = *" $orig_cmd "* ]]; then + eval "${orig_complete/ -F / -o nospace -F }" + else + eval "$orig_complete" + fi + fi return $ret fi } @@ -139,7 +147,7 @@ __skim_generic_path_completion() { base=${cur:0:${#cur}-${#trigger}} eval "base=$base" - dir="$base" + [[ $base = *"/"* ]] && dir="$base" while true; do if [ -z "$dir" ] || [ -d "$dir" ]; then leftover=${base/#"$dir"} @@ -150,6 +158,7 @@ __skim_generic_path_completion() { printf "%q$3 " "$item" done) matches=${matches% } + [[ -z "$3" ]] && [[ "$__skim_nospace_commands" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches " if [ -n "$matches" ]; then COMPREPLY=( "$matches" ) else @@ -204,7 +213,7 @@ _skim_complete_kill() { [ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1 local selected skim skim="$(__skimcmd_complete)" - selected=$(ps -ef | sed 1d | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-50%} --min-height 15 --reverse $SKIM_DEFAULT_OPTIONS --preview 'echo {}' --preview-window down:3:wrap $SKIM_COMPLETION_OPTS" $skim -m | awk '{print $2}' | tr '\n' ' ') + selected=$(command ps -ef | sed 1d | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-50%} --min-height 15 --reverse $SKIM_DEFAULT_OPTIONS --preview 'echo {}' --preview-window down:3:wrap $SKIM_COMPLETION_OPTS" $skim -m | awk '{print $2}' | tr '\n' ' ') printf '\e[5n' if [ -n "$selected" ]; then COMPREPLY=( "$selected" ) @@ -219,8 +228,8 @@ _skim_complete_telnet() { } _skim_complete_ssh() { _skim_complete '-m' "$@" < <( - cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \ - <(command grep -oE '^[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \ + cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host ' | command grep -v '[*?]' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \ + <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \ <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') | awk '{if (length($2) > 0) {print $2}}' | sort -u ) @@ -254,9 +263,9 @@ a_cmds=" svn tar unzip zip" x_cmds="kill ssh telnet unset unalias export" # Preserve existing completion -eval $(complete | +eval "$(complete | sed -E '/-F/!d; / _skim/d; '"/ ($(echo $d_cmds $a_cmds $x_cmds | sed 's/ /|/g; s/+/\\+/g'))$/"'!d' | - _skim_orig_completion_filter) + __skim_orig_completion_filter)" if type _completion_loader > /dev/null 2>&1; then _skim_completion_loader=1 fi diff --git a/shell/completion.zsh b/shell/completion.zsh index d80b63ae..df4aed2b 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -29,13 +29,12 @@ fi __skimcmd_complete() { [ -n "$TMUX_PANE" ] && [ "${SKIM_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] && - echo "skim-tmux -d${SKIM_TMUX_HEIGHT:-40%}" || echo "sk" + echo "sk-tmux -d${SKIM_TMUX_HEIGHT:-40%}" || echo "sk" } __skim_generic_path_completion() { local base lbuf compgen skim_opts suffix tail skim dir leftover matches - # (Q) flag removes a quoting level: "foo\ bar" => "foo bar" - base=${(Q)1} + base=$1 lbuf=$2 compgen=$3 skim_opts=$4 @@ -44,14 +43,14 @@ __skim_generic_path_completion() { skim="$(__skimcmd_complete)" setopt localoptions nonomatch - dir="$base" + eval "base=$base" + [[ $base = *"/"* ]] && dir="$base" while [ 1 ]; do - if [[ -z "$dir" || -d ${~dir} ]]; then + if [[ -z "$dir" || -d ${dir} ]]; then leftover=${base/#"$dir"} leftover=${leftover/#\/} [ -z "$dir" ] && dir='.' [ "$dir" != "/" ] && dir="${dir/%\//}" - dir=${~dir} matches=$(eval "$compgen $(printf %q "$dir")" | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} --reverse $SKIM_DEFAULT_OPTIONS $SKIM_COMPLETION_OPTS" ${=skim} ${=skim_opts} -q "$leftover" | while read item; do echo -n "${(q)item}$suffix " done) @@ -59,8 +58,7 @@ __skim_generic_path_completion() { if [ -n "$matches" ]; then LBUFFER="$lbuf$matches$tail" fi - zle redisplay - typeset -f zle-line-init >/dev/null && zle zle-line-init + zle reset-prompt break fi dir=$(dirname "$dir") @@ -93,8 +91,7 @@ _skim_complete() { if [ -n "$matches" ]; then LBUFFER="$lbuf$matches" fi - zle redisplay - typeset -f zle-line-init >/dev/null && zle zle-line-init + zle reset-prompt command rm -f "$fifo" } _skim_complete_telnet() { @@ -105,8 +102,8 @@ _skim_complete_telnet() { } _skim_complete_ssh() { _skim_complete '-m' "$@" < <( - command cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \ - <(command grep -oE '^[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \ + command cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host ' | command grep -v '[*?]' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \ + <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \ <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') | awk '{if (length($2) > 0) {print $2}}' | sort -u ) @@ -144,12 +141,11 @@ skim-completion() { # Kill completion (do not require trigger sequence) if [ $cmd = kill -a ${LBUFFER[-1]} = ' ' ]; then skim="$(__skimcmd_complete)" - matches=$(ps -ef | sed 1d | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-50%} --min-height 15 --reverse $SKIM_DEFAULT_OPTIONS --preview 'echo {}' --preview-window down:3:wrap $SKIM_COMPLETION_OPTS" ${=skim} -m | awk '{print $2}' | tr '\n' ' ') + matches=$(command ps -ef | sed 1d | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-50%} --min-height 15 --reverse $SKIM_DEFAULT_OPTIONS --preview 'echo {}' --preview-window down:3:wrap $SKIM_COMPLETION_OPTS" ${=skim} -m | awk '{print $2}' | tr '\n' ' ') if [ -n "$matches" ]; then LBUFFER="$LBUFFER$matches" fi - zle redisplay - typeset -f zle-line-init >/dev/null && zle zle-line-init + zle reset-prompt # Trigger sequence given elif [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then d_cmds=(${=SKIM_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}) diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index 951e5efa..c7528bcc 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -3,11 +3,11 @@ # copied and modified from https://github.com/junegunn/fzf/blob/master/shell/key-bindings.bash # __skim_select__() { - local cmd="${skim_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ + local cmd="${SKIM_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type f -print \ -o -type d -print \ -o -type l -print 2> /dev/null | cut -b3-"}" - eval "$cmd" | SKIM_DEFAULT_OPTIONS="--height ${skim_TMUX_HEIGHT:-40%} --reverse $SKIM_DEFAULT_OPTIONS $skim_CTRL_T_OPTS" skim -m "$@" | while read -r item; do + eval "$cmd" | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} --reverse $SKIM_DEFAULT_OPTIONS $SKIM_CTRL_T_OPTS" skim -m "$@" | while read -r item; do printf '%q ' "$item" done echo @@ -16,24 +16,24 @@ __skim_select__() { if [[ $- =~ i ]]; then __skim_use_tmux__() { - [ -n "$TMUX_PANE" ] && [ "${skim_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] + [ -n "$TMUX_PANE" ] && [ "${SKIM_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] } __skimcmd() { __skim_use_tmux__ && - echo "sk-tmux -d${skim_TMUX_HEIGHT:-40%}" || echo "sk" + echo "sk-tmux -d${SKIM_TMUX_HEIGHT:-40%}" || echo "sk" } __skim_select_tmux__() { local height - height=${skim_TMUX_HEIGHT:-40%} + height=${SKIM_TMUX_HEIGHT:-40%} if [[ $height =~ %$ ]]; then height="-p ${height%\%}" else height="-l $height" fi - tmux split-window $height "cd $(printf %q "$PWD"); SKIM_DEFAULT_OPTIONS=$(printf %q "$SKIM_DEFAULT_OPTIONS") PATH=$(printf %q "$PATH") skim_CTRL_T_COMMAND=$(printf %q "$skim_CTRL_T_COMMAND") skim_CTRL_T_OPTS=$(printf %q "$skim_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__skim_select__ --no-height)\"; tmux setb -b skim \"\$RESULT\" \\; pasteb -b skim -t $TMUX_PANE \\; deleteb -b skim || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'" + tmux split-window $height "cd $(printf %q "$PWD"); SKIM_DEFAULT_OPTIONS=$(printf %q "$SKIM_DEFAULT_OPTIONS") PATH=$(printf %q "$PATH") SKIM_CTRL_T_COMMAND=$(printf %q "$SKIM_CTRL_T_COMMAND") SKIM_CTRL_T_OPTS=$(printf %q "$SKIM_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__skim_select__ --no-height)\"; tmux setb -b skim \"\$RESULT\" \\; pasteb -b skim -t $TMUX_PANE \\; deleteb -b skim || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'" } skim-file-widget() { @@ -48,9 +48,9 @@ skim-file-widget() { __skim_cd__() { local cmd dir - cmd="${skim_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ + cmd="${SKIM_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | cut -b3-"}" - dir=$(eval "$cmd" | SKIM_DEFAULT_OPTIONS="--height ${skim_TMUX_HEIGHT:-40%} --reverse $SKIM_DEFAULT_OPTIONS $skim_ALT_C_OPTS" $(__skimcmd) -m) && printf 'cd %q' "$dir" + dir=$(eval "$cmd" | SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} --reverse $SKIM_DEFAULT_OPTIONS $SKIM_ALT_C_OPTS" $(__skimcmd) -m) && printf 'cd %q' "$dir" } __skim_history__() ( @@ -58,7 +58,7 @@ __skim_history__() ( shopt -u nocaseglob nocasematch line=$( HISTTIMEFORMAT= history | - SKIM_DEFAULT_OPTIONS="--height ${skim_TMUX_HEIGHT:-40%} $SKIM_DEFAULT_OPTIONS --reverse -n2..,.. --tac $skim_CTRL_R_OPTS -m" $(__skimcmd) | + SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} $SKIM_DEFAULT_OPTIONS --tac --sync -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $SKIM_CTRL_R_OPTS -m" $(__skimcmd) | command grep '^ *[0-9]') && if [[ $- =~ H ]]; then sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line" @@ -82,7 +82,7 @@ if [[ ! -o vi ]]; then fi # CTRL-R - Paste the selected command from history into the command line - bind '"\C-r": " \C-e\C-u`__skim_history__`\e\C-e\e^\er"' + bind '"\C-r": " \C-e\C-u\C-y\ey\C-u`__skim_history__`\e\C-e\er\e^"' # ALT-C - cd into the selected directory bind '"\ec": " \C-e\C-u`__skim_cd__`\e\C-e\er\C-m"' @@ -112,7 +112,7 @@ else bind -m vi-command '"\C-t": "i\C-t"' # CTRL-R - Paste the selected command from history into the command line - bind '"\C-r": "\C-x\C-addi`__skim_history__`\C-x\C-e\C-x^\C-x\C-a$a\C-x\C-r"' + bind '"\C-r": "\C-x\C-addi`__skim_history__`\C-x\C-e\C-x\C-r\C-x^\C-x\C-a$a"' bind -m vi-command '"\C-r": "i\C-r"' # ALT-C - cd into the selected directory diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish new file mode 100644 index 00000000..70323bdd --- /dev/null +++ b/shell/key-bindings.fish @@ -0,0 +1,148 @@ +#!/bin/fish +# completion.fish +# copied and modified from https://github.com/junegunn/fzf/blob/master/shell/completion.fish + +function skim_key_bindings + + # Store current token in $dir as root for the 'find' command + function skim-file-widget -d "List files and folders" + set -l commandline (__skim_parse_commandline) + set -l dir $commandline[1] + set -l skim_query $commandline[2] + + # "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not + # $dir itself, even if hidden. + set -q SKIM_CTRL_T_COMMAND; or set -l SKIM_CTRL_T_COMMAND " + command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ + -o -type f -print \ + -o -type d -print \ + -o -type l -print 2> /dev/null | sed 's@^\./@@'" + + set -q SKIM_TMUX_HEIGHT; or set SKIM_TMUX_HEIGHT 40% + begin + set -lx SKIM_DEFAULT_OPTIONS "--height $SKIM_TMUX_HEIGHT --reverse $SKIM_DEFAULT_OPTIONS $SKIM_CTRL_T_OPTS" + eval "$SKIM_CTRL_T_COMMAND | "(__skimcmd)' -m --query "'$skim_query'"' | while read -l r; set result $result $r; end + end + if [ -z "$result" ] + commandline -f repaint + return + else + # Remove last token from commandline. + commandline -t "" + end + for i in $result + commandline -it -- (string escape $i) + commandline -it -- ' ' + end + commandline -f repaint + end + + function skim-history-widget -d "Show command history" + set -q SKIM_TMUX_HEIGHT; or set SKIM_TMUX_HEIGHT 40% + begin + set -lx SKIM_DEFAULT_OPTIONS "--height $SKIM_TMUX_HEIGHT $SKIM_DEFAULT_OPTIONS --tiebreak=index --bind=ctrl-r:toggle-sort $SKIM_CTRL_R_OPTS -m" + + set -l FISH_MAJOR (echo $version | cut -f1 -d.) + set -l FISH_MINOR (echo $version | cut -f2 -d.) + + # history's -z flag is needed for multi-line support. + # history's -z flag was added in fish 2.4.0, so don't use it for versions + # before 2.4.0. + if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ]; + history -z | eval (__skimcmd) --read0 -q '(commandline)' | perl -pe 'chomp if eof' | read -lz result + and commandline -- $result + else + history | eval (__skimcmd) -q '(commandline)' | read -l result + and commandline -- $result + end + end + commandline -f repaint + end + + function skim-cd-widget -d "Change directory" + set -l commandline (__skim_parse_commandline) + set -l dir $commandline[1] + set -l skim_query $commandline[2] + + set -q SKIM_ALT_C_COMMAND; or set -l SKIM_ALT_C_COMMAND " + command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ + -o -type d -print 2> /dev/null | sed 's@^\./@@'" + set -q SKIM_TMUX_HEIGHT; or set SKIM_TMUX_HEIGHT 40% + begin + set -lx SKIM_DEFAULT_OPTIONS "--height $SKIM_TMUX_HEIGHT --reverse $SKIM_DEFAULT_OPTIONS $SKIM_ALT_C_OPTS" + eval "$SKIM_ALT_C_COMMAND | "(__skimcmd)' -m --query "'$skim_query'"' | read -l result + + if [ -n "$result" ] + cd $result + + # Remove last token from commandline. + commandline -t "" + end + end + + commandline -f repaint + end + + function __skimcmd + set -q SKIM_TMUX; or set SKIM_TMUX 0 + set -q SKIM_TMUX_HEIGHT; or set SKIM_TMUX_HEIGHT 40% + if [ $SKIM_TMUX -eq 1 ] + echo "sk-tmux -d$SKIM_TMUX_HEIGHT" + else + echo "sk" + end + end + + bind \ct skim-file-widget + bind \cr skim-history-widget + bind \ec skim-cd-widget + + if bind -M insert > /dev/null 2>&1 + bind -M insert \ct skim-file-widget + bind -M insert \cr skim-history-widget + bind -M insert \ec skim-cd-widget + end + + function __skim_parse_commandline -d 'Parse the current command line token and return split of existing filepath and rest of token' + # eval is used to do shell expansion on paths + set -l commandline (eval "printf '%s' "(commandline -t)) + + if [ -z $commandline ] + # Default to current directory with no --query + set dir '.' + set skim_query '' + else + set dir (__skim_get_dir $commandline) + + if [ "$dir" = "." -a (string sub -l 1 $commandline) != '.' ] + # if $dir is "." but commandline is not a relative path, this means no file path found + set skim_query $commandline + else + # Also remove trailing slash after dir, to "split" input properly + set skim_query (string replace -r "^$dir/?" '' "$commandline") + end + end + + echo $dir + echo $skim_query + end + + function __skim_get_dir -d 'Find the longest existing filepath from input string' + set dir $argv + + # Strip all trailing slashes. Ignore if $dir is root dir (/) + if [ (string length $dir) -gt 1 ] + set dir (string replace -r '/*$' '' $dir) + end + + # Iteratively check if dir exists and strip tail end of path + while [ ! -d "$dir" ] + # If path is absolute, this can keep going until ends up at / + # If path is relative, this can keep going until entire input is consumed, dirname returns "." + set dir (dirname "$dir") + end + + echo $dir + end + +end diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index aa9c1b61..3f0a681d 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -31,13 +31,22 @@ __skimcmd() { skim-file-widget() { LBUFFER="${LBUFFER}$(__fsel)" local ret=$? - zle redisplay - typeset -f zle-line-init >/dev/null && zle zle-line-init + zle reset-prompt return $ret } zle -N skim-file-widget bindkey '^T' skim-file-widget +# Ensure precmds are run after cd +skim-redraw-prompt() { + local precmd + for precmd in $precmd_functions; do + $precmd + done + zle reset-prompt +} +zle -N skim-redraw-prompt + # ALT-C - cd into the selected directory skim-cd-widget() { local cmd="${SKIM_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ @@ -50,8 +59,7 @@ skim-cd-widget() { fi cd "$dir" local ret=$? - zle reset-prompt - typeset -f zle-line-init >/dev/null && zle zle-line-init + zle skim-redraw-prompt return $ret } zle -N skim-cd-widget @@ -61,8 +69,8 @@ bindkey '\ec' skim-cd-widget skim-history-widget() { local selected num setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null - selected=( $(fc -l 1 | - SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} --reverse $SKIM_DEFAULT_OPTIONS -n2..,.. --tac --preview='echo {}' --preview-window down:4:wrap $SKIM_CTRL_R_OPTS --query=${(q)LBUFFER} -m" $(__skimcmd)) ) + selected=( $(fc -rl 1 | + SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} $SKIM_DEFAULT_OPTIONS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $SKIM_CTRL_R_OPTS --query=${(qqq)LBUFFER} -m" $(__skimcmd)) ) local ret=$? if [ -n "$selected" ]; then num=$selected[1] @@ -70,8 +78,7 @@ skim-history-widget() { zle vi-fetch-history -n $num fi fi - zle redisplay - typeset -f zle-line-init >/dev/null && zle zle-line-init + zle reset-prompt return $ret } zle -N skim-history-widget