Skip to content

Instantly share code, notes, and snippets.

@CognitiveDisson
Created August 29, 2023 11:35
Show Gist options
  • Save CognitiveDisson/33582597325218712bafbe404f46d5c6 to your computer and use it in GitHub Desktop.
Save CognitiveDisson/33582597325218712bafbe404f46d5c6 to your computer and use it in GitHub Desktop.
bzqfzf for zsh
# Example: vim (bzqfzf //...)
# Description: ZSH functions (should be easily converted to zsh) for Basel fuzzy search.
# Requirements:
# bazel
# brew install fzf
# brew install bat
# Add "source ~/.zsh_functions/bzqfzf.sh" to `~/.zshrc`
# ~.zsh_functions/bzqfzf.sh:
function bat_preview_for_bazel() {
bazel_target="$argv[1]"
bazel_output=$(bazel query $bazel_target --noshow_progress --output=build | head -1 | sed -e "s/^#[[:space:]]//")
bazel_file=$(echo "$bazel_output" | cut -d: -f1)
line=$(echo "$bazel_output" | cut -d: -f2)
bat --style=numbers --color=always --line-range $line: "$bazel_file"
}
function bazel_file_from_target() {
bazel_target="$argv[1]"
bazel_output=$(bazel query $bazel_target --noshow_progress --output=build | head -1 | sed -e "s/^#[[:space:]]//")
bazel_file=$(echo "$bazel_output" | cut -d: -f1)
echo "$bazel_file"
}
function bzqfzf() {
bazel query $argv | fzf --preview='bat_preview_for_bazel {}' --bind 'enter:become(bazel_file_from_target {})'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment