Skip to content

Instantly share code, notes, and snippets.

@CognitiveDisson
Created August 29, 2023 11:35
Show Gist options
  • Select an option

  • Save CognitiveDisson/33582597325218712bafbe404f46d5c6 to your computer and use it in GitHub Desktop.

Select an option

Save CognitiveDisson/33582597325218712bafbe404f46d5c6 to your computer and use it in GitHub Desktop.

Revisions

  1. CognitiveDisson created this gist Aug 29, 2023.
    31 changes: 31 additions & 0 deletions bzqfzf.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # 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 {})'
    }