mirror of
https://github.com/ViViDboarder/shoestrap.git
synced 2025-01-31 05:44:16 +00:00
Downgrade fzf keybindings
This is because newer fzf versions will have `--fish` option
This commit is contained in:
parent
cbcb27c86a
commit
c3a7950e8b
@ -1,4 +1,5 @@
|
|||||||
### key-bindings.fish ###
|
# key-bindings.fish from fzf 0.29.0
|
||||||
|
|
||||||
# ____ ____
|
# ____ ____
|
||||||
# / __/___ / __/
|
# / __/___ / __/
|
||||||
# / /_/_ / / /_
|
# / /_/_ / / /_
|
||||||
@ -12,35 +13,31 @@
|
|||||||
# - $FZF_ALT_C_COMMAND
|
# - $FZF_ALT_C_COMMAND
|
||||||
# - $FZF_ALT_C_OPTS
|
# - $FZF_ALT_C_OPTS
|
||||||
|
|
||||||
|
|
||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
function fzf_key_bindings
|
function fzf_key_bindings
|
||||||
|
|
||||||
function __fzf_defaults
|
|
||||||
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
|
||||||
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
|
|
||||||
test -r "$FZF_DEFAULT_OPTS_FILE"; and string collect -N -- <$FZF_DEFAULT_OPTS_FILE
|
|
||||||
echo $FZF_DEFAULT_OPTS $argv[2]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Store current token in $dir as root for the 'find' command
|
# Store current token in $dir as root for the 'find' command
|
||||||
function fzf-file-widget -d "List files and folders"
|
function fzf-file-widget -d "List files and folders"
|
||||||
set -l commandline (__fzf_parse_commandline)
|
set -l commandline (__fzf_parse_commandline)
|
||||||
set -lx dir $commandline[1]
|
set -l dir $commandline[1]
|
||||||
set -l fzf_query $commandline[2]
|
set -l fzf_query $commandline[2]
|
||||||
set -l prefix $commandline[3]
|
set -l prefix $commandline[3]
|
||||||
|
|
||||||
|
# "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not
|
||||||
|
# $dir itself, even if hidden.
|
||||||
|
test -n "$FZF_CTRL_T_COMMAND"; or set -l FZF_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@^\./@@'"
|
||||||
|
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
begin
|
begin
|
||||||
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path --walker-root=$dir" "$FZF_CTRL_T_OPTS")
|
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
|
||||||
set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND"
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
|
||||||
set -lx FZF_DEFAULT_OPTS_FILE ''
|
|
||||||
eval (__fzfcmd) -m --query=$fzf_query | while read -l r; set -a result $r; end
|
|
||||||
end
|
end
|
||||||
if test -z "$result"
|
if [ -z "$result" ]
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@ -49,7 +46,7 @@ function fzf_key_bindings
|
|||||||
end
|
end
|
||||||
for i in $result
|
for i in $result
|
||||||
commandline -it -- $prefix
|
commandline -it -- $prefix
|
||||||
commandline -it -- (string escape -- $i)
|
commandline -it -- (string escape $i)
|
||||||
commandline -it -- ' '
|
commandline -it -- ' '
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
@ -58,31 +55,19 @@ function fzf_key_bindings
|
|||||||
function fzf-history-widget -d "Show command history"
|
function fzf-history-widget -d "Show command history"
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
begin
|
begin
|
||||||
set -l FISH_MAJOR (string split '.' -- $version)[1]
|
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort,ctrl-z:ignore $FZF_CTRL_R_OPTS +m"
|
||||||
set -l FISH_MINOR (string split '.' -- $version)[2]
|
|
||||||
|
|
||||||
# merge history from other sessions before searching
|
set -l FISH_MAJOR (echo $version | cut -f1 -d.)
|
||||||
test -z "$fish_private_mode"; and builtin history merge
|
set -l FISH_MINOR (echo $version | cut -f2 -d.)
|
||||||
|
|
||||||
# history's -z flag is needed for multi-line support.
|
# 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
|
# history's -z flag was added in fish 2.4.0, so don't use it for versions
|
||||||
# before 2.4.0.
|
# before 2.4.0.
|
||||||
if test "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \)
|
if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
|
||||||
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
|
history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result
|
||||||
set -lx FZF_DEFAULT_OPTS_FILE ''
|
and commandline -- $result
|
||||||
if type -q perl
|
|
||||||
builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
|
|
||||||
and commandline -- $result
|
|
||||||
else
|
|
||||||
set -l line 0
|
|
||||||
for i in (builtin history -z --reverse | string split0)
|
|
||||||
set line (math $line + 1)
|
|
||||||
string escape -n -- $line\t$i
|
|
||||||
end | string join0 | string replace -a '\n' '\n\t' | string unescape -n | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
|
|
||||||
and commandline -- $result
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
builtin history | eval (__fzfcmd) -q '(commandline)' | read -l result
|
history | eval (__fzfcmd) -q '(commandline)' | read -l result
|
||||||
and commandline -- $result
|
and commandline -- $result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -91,18 +76,19 @@ function fzf_key_bindings
|
|||||||
|
|
||||||
function fzf-cd-widget -d "Change directory"
|
function fzf-cd-widget -d "Change directory"
|
||||||
set -l commandline (__fzf_parse_commandline)
|
set -l commandline (__fzf_parse_commandline)
|
||||||
set -lx dir $commandline[1]
|
set -l dir $commandline[1]
|
||||||
set -l fzf_query $commandline[2]
|
set -l fzf_query $commandline[2]
|
||||||
set -l prefix $commandline[3]
|
set -l prefix $commandline[3]
|
||||||
|
|
||||||
|
test -n "$FZF_ALT_C_COMMAND"; or set -l FZF_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@^\./@@'"
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
begin
|
begin
|
||||||
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path --walker-root=$dir" "$FZF_ALT_C_OPTS")
|
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"
|
||||||
set -lx FZF_DEFAULT_OPTS_FILE ''
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
|
||||||
set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"
|
|
||||||
eval (__fzfcmd) +m --query=$fzf_query | read -l result
|
|
||||||
|
|
||||||
if test -n "$result"
|
if [ -n "$result" ]
|
||||||
cd -- $result
|
cd -- $result
|
||||||
|
|
||||||
# Remove last token from commandline.
|
# Remove last token from commandline.
|
||||||
@ -117,31 +103,23 @@ function fzf_key_bindings
|
|||||||
function __fzfcmd
|
function __fzfcmd
|
||||||
test -n "$FZF_TMUX"; or set FZF_TMUX 0
|
test -n "$FZF_TMUX"; or set FZF_TMUX 0
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
if test -n "$FZF_TMUX_OPTS"
|
if [ -n "$FZF_TMUX_OPTS" ]
|
||||||
echo "fzf-tmux $FZF_TMUX_OPTS -- "
|
echo "fzf-tmux $FZF_TMUX_OPTS -- "
|
||||||
else if test "$FZF_TMUX" = "1"
|
else if [ $FZF_TMUX -eq 1 ]
|
||||||
echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
|
echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
|
||||||
else
|
else
|
||||||
echo "fzf"
|
echo "fzf"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
bind \ct fzf-file-widget
|
||||||
bind \cr fzf-history-widget
|
bind \cr fzf-history-widget
|
||||||
if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
|
bind \ec fzf-cd-widget
|
||||||
bind \ct fzf-file-widget
|
|
||||||
end
|
|
||||||
if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
|
|
||||||
bind \ec fzf-cd-widget
|
|
||||||
end
|
|
||||||
|
|
||||||
if bind -M insert &> /dev/null
|
if bind -M insert > /dev/null 2>&1
|
||||||
|
bind -M insert \ct fzf-file-widget
|
||||||
bind -M insert \cr fzf-history-widget
|
bind -M insert \cr fzf-history-widget
|
||||||
if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
|
bind -M insert \ec fzf-cd-widget
|
||||||
bind -M insert \ct fzf-file-widget
|
|
||||||
end
|
|
||||||
if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
|
|
||||||
bind -M insert \ec fzf-cd-widget
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'
|
function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'
|
||||||
@ -151,50 +129,40 @@ function fzf_key_bindings
|
|||||||
set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)
|
set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)
|
||||||
set commandline (string replace -- "$prefix" '' $commandline)
|
set commandline (string replace -- "$prefix" '' $commandline)
|
||||||
|
|
||||||
# escape special characters, except for the $ sign of valid variable names,
|
|
||||||
# so that after eval, the original string is returned, but with the
|
|
||||||
# variable names replaced by their values.
|
|
||||||
set commandline (string escape -n -- $commandline)
|
|
||||||
set commandline (string replace -r -a '\x5c\$(?=[\w])' '\$' -- $commandline)
|
|
||||||
|
|
||||||
# eval is used to do shell expansion on paths
|
# eval is used to do shell expansion on paths
|
||||||
eval set commandline $commandline
|
eval set commandline $commandline
|
||||||
|
|
||||||
# Combine multiple consecutive slashes into one
|
if [ -z $commandline ]
|
||||||
set commandline (string replace -r -a '/+' '/' -- $commandline)
|
|
||||||
|
|
||||||
if test -z "$commandline"
|
|
||||||
# Default to current directory with no --query
|
# Default to current directory with no --query
|
||||||
set dir '.'
|
set dir '.'
|
||||||
set fzf_query ''
|
set fzf_query ''
|
||||||
else
|
else
|
||||||
set dir (__fzf_get_dir $commandline)
|
set dir (__fzf_get_dir $commandline)
|
||||||
|
|
||||||
# BUG: on combined expressions, if a left argument is a single `!`, the
|
if [ "$dir" = "." -a (string sub -l 1 -- $commandline) != '.' ]
|
||||||
# builtin test command of fish will treat it as the ! operator. To
|
|
||||||
# overcome this, have the variable parts on the right.
|
|
||||||
if test "." = "$dir" -a "." != (string sub -l 1 -- $commandline)
|
|
||||||
# if $dir is "." but commandline is not a relative path, this means no file path found
|
# if $dir is "." but commandline is not a relative path, this means no file path found
|
||||||
set fzf_query $commandline
|
set fzf_query $commandline
|
||||||
else
|
else
|
||||||
# Also remove trailing slash after dir, to "split" input properly
|
# Also remove trailing slash after dir, to "split" input properly
|
||||||
set fzf_query (string replace -r "^$dir/?" '' -- $commandline)
|
set fzf_query (string replace -r "^$dir/?" -- '' "$commandline")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
echo (string escape -- $dir)
|
echo $dir
|
||||||
echo (string escape -- $fzf_query)
|
echo $fzf_query
|
||||||
echo $prefix
|
echo $prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
||||||
set dir $argv
|
set dir $argv
|
||||||
|
|
||||||
# Strip trailing slash, unless $dir is root dir (/)
|
# Strip all trailing slashes. Ignore if $dir is root dir (/)
|
||||||
set dir (string replace -r '(?<!^)/$' '' -- $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
|
# Iteratively check if dir exists and strip tail end of path
|
||||||
while test ! -d "$dir"
|
while [ ! -d "$dir" ]
|
||||||
# If path is absolute, this can keep going until ends up at /
|
# 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 "."
|
# If path is relative, this can keep going until entire input is consumed, dirname returns "."
|
||||||
set dir (dirname -- "$dir")
|
set dir (dirname -- "$dir")
|
||||||
@ -204,5 +172,3 @@ function fzf_key_bindings
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
### end: key-bindings.fish ###
|
|
||||||
fzf_key_bindings
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user