37 lines
1.4 KiB
Fish
37 lines
1.4 KiB
Fish
# https://github.com/junegunn/fzf
|
|
set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse"
|
|
set -gx FZF_DEFAULT_COMMAND "fd --type=file"
|
|
|
|
function __fzf_files
|
|
set -l src_cmd "fd --type=file --hidden --follow --color=always --exclude=.git 2>/dev/null"
|
|
set -l fzf_cmd "fzf --ansi --preview 'bat --style=header,numbers --color=always {}' --preview-window right:70%:hidden:wrap --bind '?:toggle-preview'"
|
|
if set -l selection (eval "$src_cmd | $fzf_cmd")
|
|
commandline -i (echo $selection | string escape)
|
|
end
|
|
commandline -f repaint
|
|
end
|
|
|
|
function __fzf_git_log
|
|
if not git rev-parse --git-dir >/dev/null 2>&1
|
|
echo '__fzf_search_git_log: Not in a git repository!' >&2
|
|
else
|
|
set -l src_cmd 'command git logsearch'
|
|
set -l fzf_cmd 'fzf --ansi --tiebreak=index'
|
|
if set -l selection (eval "$src_cmd | $fzf_cmd")
|
|
set commit_hash (string split --max 1 " " $selection)[1]
|
|
commandline -i $commit_hash
|
|
end
|
|
end
|
|
commandline -f repaint
|
|
end
|
|
|
|
function __fzf_history
|
|
set -l src_cmd 'history search --null --show-time="%Y-%m-%d | "'
|
|
set -l fzf_cmd "fzf --read0 --tiebreak=index --query=(commandline) --preview='echo {}' --preview-window='bottom:50%:hidden:wrap' --bind='?:toggle-preview'"
|
|
if set -l selection (eval "$src_cmd | $fzf_cmd")
|
|
set -l command (string split --max 1 " | " $selection)[2..-1]
|
|
commandline -r $command
|
|
end
|
|
commandline -f repaint
|
|
end
|