jpcrs / binocular

Not exactly a telescope, but it's useful sometimes. Extension to search/navigate through files and workspaces.
MIT License
22 stars 2 forks source link

Binocular

Not as useful as a telescope, but helps in some situations.

This extension has a bunch of dependencies and there's no sanity checks, if the tools listed in the dependencies are not available in your PATH it'll just not work, sorry :(

Demo

What's Binocular?

Binocular is an extension to execute shell commands inside vscode. It can be configured to execute any command, as explained in (Custom Commands). My main usage is to use it together with Binocular-cli (The default commands in this extension), which is an opinionated wrapper around rg/fzf/fd/delta, mainly to search files and folders.

Inspired by Telescope. But implemented with the quality of Internet Explorer 6.

Important: The code isn't tested or extensible enough to make this a serious extension. I just created this to help my current workflow whenever I have to use vscode. There's no guarantee to work for other people :).

Is this extension really necessary?

Not really, everything that it does can be easily achieved with vscode Tasks. But I wanted to do it so I can declutter my Tasks file, also the Tasks commands had to be different depending the OS that I'm using in the moment.

Motivation?

My RSI.

How does it work?

It's a simple wrapper around vscode Tasks. It runs a task with some specific command, send the task terminal to the editor and then close at the end of the execution.

Dependencies

There are a bunch of hard dependencies to use the default commands:

Installation

Currently binocular-cli is just available on crates.io, so cargo has to be installed. More information: https://doc.rust-lang.org/cargo/getting-started/installation.html

  1. cargo install binocular-cli
  2. Install all the other dependencies listed HERE

Custom Commands

You can create custom commands with the binocular.command.commands configuration and execute these commands with binocular.customCommands.

Some example of custom commands that I use:

"binocular.command.commands": [
    //lazygit! :)
    {
        "shellCommand": "lazygit",
        "commandIdentifier": "Lazygit"
    },
    // Search git log using the `git fuzzy` tool and checkout the selected one
    {
        "shellCommand": "git checkout $(git fuzzy log)",
        "commandIdentifier": "Git fuzzy log"
    },
    // Search git log for the current file using the `git fuzzy` tool and checkout the selected one
    {
        "shellCommand": "git checkout $(git fuzzy log ${file})",
        "commandIdentifier": "Git fuzzy log current file"
    }
],

Creating shortcuts for custom commands

Since custom commands are defined in the config file, you have to parameterize the shortcut to send the commandIdentifier as parameter. Example:

keybindings.json:

    //Execute Lazygit command defined in binocular.command.commands settings.
    {
        "key": "alt+g",
        "command": "binocular.customCommands",
        "args": "Lazygit"
    },

Default Commands

binocular.searchFile: Search by file name

binocular.searchFileContent: Search by file content

binocular.searchDirectory: Search by directory name

binocular.searchFileConfiguredFolders: Search by file name in configured folders

binocular.searchContentConfiguredFolders: Search by file content in configured folders

binocular.searchDirectoryConfiguredFolders: Search by directory name in configured folders

binocular.searchFileHistory: Search file history

binocular.searchGitFoldersConfiguredFolders: Search git folders in configured folders

binocular.searchErrors: View errors

binocular.searchWarnings: View warnings

binocular.searchHints: View Hints

binocular.customCommands: Execute Custom Commands

Settings

Current Problems