Created
August 29, 2023 11:35
-
-
Save CognitiveDisson/33582597325218712bafbe404f46d5c6 to your computer and use it in GitHub Desktop.
bzqfzf for zsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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