fzf: custom bindings/functions

This commit is contained in:
Charles Gould 2020-08-16 04:09:07 -04:00
parent 01b5dab099
commit d1968327c3
6 changed files with 44 additions and 21 deletions

View File

@ -1,8 +1,36 @@
# https://github.com/junegunn/fzf
set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse --multi"
set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse"
set -gx FZF_DEFAULT_COMMAND "fd --type=file"
set -gx FZF_CTRL_T_COMMAND "fd --type=file --follow"
set -gx FZF_CTRL_T_OPTS "--ansi --preview 'bat --style=header,numbers --color=always {}' --preview-window right:70%:hidden:wrap --bind '?:toggle-preview'"
set -gx FZF_CTRL_R_OPTS "--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
set -gx FZF_ALT_C_COMMAND "fd --type=directory --follow"
set -gx FZF_ALT_C_OPTS "--preview 'tree -CL 1 {}'"
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)'
if set -l selection (eval "$src_cmd | $fzf_cmd")
set -l command (string split --max 1 " | " $selection)[2]
commandline -r $command
end
commandline -f repaint
end

View File

@ -5,7 +5,7 @@ function fbrew --description "Fuzzy homebrew"
set --local inst_pkgs $argv
if test (count $inst_pkgs) -eq 0
set inst_pkgs (brew search | eval "fzf --prompt='[brew:install] '")
set inst_pkgs (brew search | eval "fzf --multi --prompt='[brew:install] '")
end
if test (count $inst_pkgs) -gt 0
@ -24,7 +24,7 @@ function fbrew --description "Fuzzy homebrew"
set --local locked_pkgs node python
if test (count $uninst_pkgs) -eq 0
set uninst_pkgs (brew leaves | eval "fzf --prompt='[brew:uninstall] '")
set uninst_pkgs (brew leaves | eval "fzf --multi --prompt='[brew:uninstall] '")
end
if test (count $uninst_pkgs) -gt 0

View File

@ -5,15 +5,9 @@ function fish_user_key_bindings
# By default, Ctrl+L clears the screen
# Add binding Ctrl+Alt+L to clear screen AND scrollback buffer
bind \e\f 'clear; commandline -f repaint'
bind -M insert \e\f 'clear; commandline -f repaint'
bind -M visual \e\f 'clear; commandline -f repaint'
# Bindings for fzf
if command -q brew
source (brew --prefix)/opt/fzf/shell/key-bindings.fish
fzf_key_bindings
else if command -q fzf-share
source (fzf-share)/key-bindings.fish
fzf_key_bindings
end
bind \cp __fzf_files
bind \cg __fzf_git_log
bind \cr __fzf_history
end

View File

@ -16,14 +16,14 @@ function fkill --description "Fuzzy kill processes"
set --local fkill_procs
if contains -- '--tcp' $argv
set fkill_pid (lsof -Pwni tcp | sed 1d | eval "fzf --prompt='[kill:tcp] '" | awk '{print $2}')
set fkill_pid (lsof -Pwni tcp | sed 1d | eval "fzf --multi --prompt='[kill:tcp] '" | awk '{print $2}')
else
if test $fkill_uid -eq 0
set fkill_procs (ps -ef | tail -n +2 | string collect)
else
set fkill_procs (ps -f -u $fkill_uid | tail -n +2 | string collect)
end
set fkill_pid (echo $fkill_procs | eval "fzf --prompt='[kill:process] ' --preview='ps -p {2}' --preview-window='down:3'" | awk '{print $2}')
set fkill_pid (echo $fkill_procs | eval "fzf --multi --prompt='[kill:process] ' --preview='ps -p {2}' --preview-window='down:3'" | awk '{print $2}')
end
if test (count $fkill_pid) -gt 0

View File

@ -9,6 +9,7 @@
branchsort = branch --sort='-committerdate' --format='%(HEAD) %(color:blue)%(committerdate:short)%(color:reset) - %(if)%(worktreepath)%(then)%(color:reverse yellow)%(refname:short)%(color:reset)%(else)%(color:yellow)%(refname:short)%(color:reset)%(end)'
can = commit --amend --no-edit
cand = commit --amend --no-edit --date=now
logsearch = log --color=always --format=tformat:'%C(green)%h%C(reset) %C(blue)%cs%C(reset) %C(normal)%s%C(reset)'
rbi = rebase --interactive
wipe = restore --staged --worktree
[color]

View File

@ -10,7 +10,7 @@ function _install_extra_brews --argument-names favorite_brews
set -a brew_pkgs_options $brew_pkg
end
end
set --local brew_pkgs_inst (string split ' ' -- $brew_pkgs_options | eval "fzf --prompt='[brew:install] '")
set --local brew_pkgs_inst (string split ' ' -- $brew_pkgs_options | eval "fzf --multi --prompt='[brew:install] '")
if test (count $brew_pkgs_inst) -gt 0
echo "Installing: $brew_pkgs_inst"
brew install $brew_pkgs_inst
@ -25,7 +25,7 @@ function _install_extra_casks --argument-names favorite_casks
set -a brew_casks_options $brew_cask
end
end
set --local brew_casks_inst (string split ' ' -- $brew_casks_options | eval "fzf --prompt='[brew:install] '")
set --local brew_casks_inst (string split ' ' -- $brew_casks_options | eval "fzf --multi --prompt='[brew:install] '")
if test (count $brew_casks_inst) -gt 0
echo "Installing: $brew_casks_inst"
brew cask install $brew_casks_inst