Another powerful technique: readline bindings. This alias brings up a fzf-style file picker on Ctrl-F. Any picked filenames are inserted at the current cursor position:
bind -x '"\C-f":"_skim_insert"'
_skim_insert() {
local files="$(sk --cmd='rg --files' --multi)"
if [[ $? -eq 0 ]]; then
local completions="$(python3 -c 'import sys, shlex; print(" ".join(shlex.quote(a.rstrip("\n")) for a in sys.argv[1].splitlines()))' "$files")"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}${completions}${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( $READLINE_POINT + ${#READLINE_LINE} ))
fi
}
This one picks a Git commit ID from git log on Ctrl-G:
bind -x '"\C-g":"_git_commit_insert"'
_git_commit_insert() {
local files="$(sk --cmd='git log --oneline' --multi --reverse)"
if [[ $? -eq 0 ]]; then
local completions="$(python3 -c 'import sys, shlex; print(" ".join(shlex.quote(a.split()[0]) for a in sys.argv[1].splitlines()))' "$files")"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}${completions}${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( $READLINE_POINT + ${#READLINE_LINE} ))
fi
}
Really handy for git commit --fixup!
These examples use Skim instead of fzf. It’s a Rust reimplementation. I use Skim instead of fzf because I can easily cargo install it along with Ripgrep.
Another powerful technique: readline bindings. This alias brings up a fzf-style file picker on Ctrl-F. Any picked filenames are inserted at the current cursor position:
This one picks a Git commit ID from
git log
on Ctrl-G:Really handy for
git commit --fixup
!These examples use Skim instead of fzf. It’s a Rust reimplementation. I use Skim instead of fzf because I can easily
cargo install
it along with Ripgrep.Thanks for pointing me at Skim, it’s an awesome tool. My new interactive git branch selector alias is:
Probably not the most efficient way to combine fzf and rg, but I use this function daily: