Skip to content

Instantly share code, notes, and snippets.

@reiyw
Last active September 13, 2021 09:33
Show Gist options
  • Save reiyw/3c50f44ef8fa872cdbec309466554d04 to your computer and use it in GitHub Desktop.
Save reiyw/3c50f44ef8fa872cdbec309466554d04 to your computer and use it in GitHub Desktop.
fzf keybind to specify a target for Bazel run in zsh.
fzf-bazel-run() {
local ret=$(bazel query 'kind("_binary", //...)' --output location | fzf --with-nth 4 --preview 'a=($(echo {} | tr ":" " ")); tail -n +$a[2] $a[1] | sed "/^$/q"')
local a=(${(s/ /)ret})
local target=$a[4]
if [[ -n "$target" ]]; then
BUFFER="bazel run $target"
CURSOR=${#BUFFER}
fi
}
zle -N fzf-bazel-run
bindkey '<keymap>' fzf-bazel-run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment