Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active June 21, 2022 10:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save weaming/765703bb6e295cffdfcc16ac6cf037ac to your computer and use it in GitHub Desktop.
Save weaming/765703bb6e295cffdfcc16ac6cf037ac to your computer and use it in GitHub Desktop.
# inspired by https://github.com/junegunn/fzf/issues/868
function __fzf_ls_files
git ls-tree -r --name-only HEAD 2>/dev/null; or fd --type f --hidden --follow --exclude .git
end
function __fzf_grep_last
set -l cmd (commandline)
# default complete all, and compatible with fzf `**<TAB>`
if str_endswith "$cmd" ' '; or test $cmd = '**'
cat
else
grep (echo $cmd | awk '{print $NF}')
end
end
function fzf_complete
set -l last_word (commandline | awk '{print $NF}')
begin; complete -C; __fzf_ls_files; end \
| sort | uniq | __fzf_grep_last \
| fzf -d \t -1 -0 --ansi --header="$last_word" --height="80%" --tabstop=4 \
| read -l token
# Remove description
set token (string replace -r \t'.*' '' -- $token)
commandline -rt "$token"
end
function fzf_tab_binding
bind \ch 'fzf_complete; commandline -f repaint'
end
@c02y
Copy link

c02y commented Apr 23, 2021

What is str_endwidth?

Never mind, I always use https://github.com/jethrokuan/fzf/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment