This commit is contained in:
2021-11-15 00:26:15 +04:00
parent 8583c61d95
commit 081dc5ccc1
10 changed files with 64 additions and 17 deletions

View File

@@ -58,7 +58,6 @@ function __fzf_complete -d 'fzf completion and print selection back to commandli
set -l query
string join -- \n $complist \
| sort \
| eval (__fzfcmd) (string escape --no-quoted -- $initial_query) --print-query (__fzf_complete_opts) \
| cut -f1 \
| while read -l r

View File

@@ -2,12 +2,12 @@ function __fzf_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 ]
if test (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" ]
while test ! -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")

View File

@@ -39,7 +39,7 @@ function __fzf_open -d "Open files and directories."
-o -type d -print \
-o -type l -print 2> /dev/null | sed 's@^\./@@'"
eval "$FZF_OPEN_COMMAND | "(__fzfcmd) $preview_cmd "-m $FZF_DEFAULT_OPTS $FZF_OPEN_OPTS --query \"$fzf_query\"" | read -l select
set -l select (eval "$FZF_OPEN_COMMAND | "(__fzfcmd) $preview_cmd "-m $FZF_DEFAULT_OPTS $FZF_OPEN_OPTS --query \"$fzf_query\"" | string escape)
# set how to open
set -l open_cmd
@@ -54,7 +54,7 @@ function __fzf_open -d "Open files and directories."
set -l open_status 0
if not test -z "$select"
commandline "$open_cmd \"$select\"" ;and commandline -f execute
commandline "$open_cmd $select"; and commandline -f execute
set open_status $status
end

View File

@@ -2,14 +2,14 @@ function __fzf_parse_commandline -d 'Parse the current command line token and re
# eval is used to do shell expansion on paths
set -l commandline (eval "printf '%s' "(commandline -t))
if [ -z $commandline ]
if test -z $commandline
# Default to current directory with no --query
set dir '.'
set fzf_query ''
else
set dir (__fzf_get_dir $commandline)
if [ "$dir" = "." -a (string sub -l 1 $commandline) != '.' ]
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
set fzf_query $commandline
else

View File

@@ -1,6 +1,6 @@
function __fzf_reverse_isearch
history merge
history -z | eval (__fzfcmd) --read0 --tiebreak=index --toggle-sort=ctrl-r $FZF_DEFAULT_OPTS $FZF_REVERSE_ISEARCH_OPTS -q '(commandline)' | perl -pe 'chomp if eof' | read -lz result
history -z | eval (__fzfcmd) --read0 --print0 --tiebreak=index --toggle-sort=ctrl-r $FZF_DEFAULT_OPTS $FZF_REVERSE_ISEARCH_OPTS -q '(commandline)' | read -lz result
and commandline -- $result
commandline -f repaint
end

View File

@@ -1,7 +1,7 @@
function __fzfcmd
set -q FZF_TMUX; or set FZF_TMUX 0
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
if [ $FZF_TMUX -eq 1 ]
if test $FZF_TMUX -eq 1
echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
else
echo "fzf"