CtrlG - A Command Line Context Switcher

Overview

CtrlG - A Command Line Context Switcher

CtrlG is a tool to quickly switch contexts to another directory, using a fuzzy finder. If enabled, ctrlg can cd all split panes in the current window of a tmux session to the selected directory. Press ctrl + g to fuzzy find directories, configured by globbing patterns.

demo

Install

Make sure you have cargo installed. If not, install it from rustup.rs. Then install the ctrlg CLI by running:

cargo install ctrlg

Once the CLI is installed, you will need to set up the key binding depending on your shell. Alternatively, you can disable the default keybind by setting $CTRLG_NOBIND to true before running the init script, then set up your own keybind to call _ctrlg_search_and_go.

Zsh

> ~/.zshrc">
echo 'eval "$(ctrlg init zsh)"' >> ~/.zshrc

Bash

> ~/.bashrc">
echo 'eval "$(ctrlg init bash)"' >> ~/.bashrc

Fish

echo 'ctrlg init fish | source' >> ~/.config/fish/config.fish

Tmux Integration

To make ctrlg send the cd command to all split panes in the current tmux window, set the environment variable CTRLG_TMUX to true.

Bash/Zsh

export CTRLG_TMUX=true

Fish

set CTRLG_TMUX true

Configuration

ctrlg will look for a configuration file at ~/.config/ctrlg/config.yml. The default configuration is shown below:

# configure what directories to list in the fuzzy finder
# can be any list of globbing patterns, will only show directories
# not files
search_dirs:
  - "~/git/*"
# globbing patterns of files to find for use as preview
# see below for more details on previews
preview_files:
  - "README.*"
# enable or disable the preview window
previews: true
# force using or not using `bat` for previews
preview_with_bat: [true if `bat` is installed, false otherwise]
# force using or not using `exa` for preview fallback when no
# matching `preview_files` are found
preview_fallback_exa: [true if `exa` is installed, false otherwise]

Any configuration values can be overridden by passing them as arguments to the CLI. When passing arguments to the CLI, replace _ with -, e.g. preview_with_bat should be passed to the CLI as --preview-with-bat. See ctrlg --help and ctrlg find --help.

Previews

Previews, if enabled, are generated by rendering the first file in each directory matching any of the specified preview_files globbing patterns. If a matching file is found, it will be rendered with bat by default if bat is installed, otherwise it will be rendered with cat. You can force using or not using bat with the preview_with_bat option. You can default to always using the fallback instead of rendering a file by setting an empty list of globbing patterns, like: preview_files:.

If no matching preview files are found, the directory listing is used as the preview. By default, directory contents are listed using exa by default if exa is installed, otherwise contents are listed using ls. You can force using or not using exa as the fallback preview using the preview_fallback_exa option.

Comments
  • [Bug]: No graphics appear when ctrlg is opened

    [Bug]: No graphics appear when ctrlg is opened

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    out https://user-images.githubusercontent.com/71287827/146962890-43456a8b-ac65-449b-b56e-0e5470cff96b.mp4

    I'm not sure if the GIF will load properly, but basically, when I press ctrl-g, the ctrlg UI appears, but nothing ever happens after that. Maybe I'm using it wrong?

    Operating System + Version

    Arch Linux 5.15.7-arch1-1

    Shell + Version

    zsh 5.8 (x86_64-pc-linux-gnu)

    Minimal Configuration to Reproduce

    HISTFILE=~/.histfile
    HISTSIZE=10000
    SAVEHIST=10000
    setopt autocd beep extendedglob nomatch notify correct_all
    
    # Keybind snippet from https://bbs.archlinux.org/viewtopic.php?id=26110
    autoload zkbd
    [[ ! -f ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE ]] && zkbd
    source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
    
    [[ -n ${key[Backspace]} ]] && bindkey "${key[Backspace]}" backward-delete-char
    [[ -n ${key[Insert]} ]] && bindkey "${key[Insert]}" overwrite-mode
    [[ -n ${key[Home]} ]] && bindkey "${key[Home]}" beginning-of-line
    [[ -n ${key[PageUp]} ]] && bindkey "${key[PageUp]}" up-line-or-history
    [[ -n ${key[Delete]} ]] && bindkey "${key[Delete]}" delete-char
    [[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
    [[ -n ${key[PageDown]} ]] && bindkey "${key[PageDown]}" down-line-or-history
    [[ -n ${key[Up]} ]] && bindkey "${key[Up]}" up-line-or-search
    [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char
    [[ -n ${key[Down]} ]] && bindkey "${key[Down]}" down-line-or-search
    [[ -n ${key[Right]} ]] && bindkey "${key[Right]}" forward-char
    
    # Load version control information
    autoload -Uz vcs_info
    precmd() { vcs_info }
    
    # Format the vcs_info_msg_0_ variable
    zstyle ':vcs_info:git:*' formats 'on %F{4}branch %F{6}%b '
    
    # Function for gathering the last exit code and setting the right prompt to it
    function check_last_exit_code() {
      local LAST_EXIT_CODE=$?
      if [[ $LAST_EXIT_CODE -ne 0 ]]; then
        local EXIT_CODE_PROMPT=' '
        EXIT_CODE_PROMPT+="%B%F{5}-%F{1}$LAST_EXIT_CODE%F{5}-%F{15}%b"
        echo "$EXIT_CODE_PROMPT"
      fi
    }
    
    # Setup the left prompt, including VCS info
    setopt PROMPT_SUBST
    PROMPT='%F{9}%n %F{15}in %F{3}${PWD/#$HOME/~} %F{15}${vcs_info_msg_0_}%F{2}%#%F{15} > '
    RPROMPT='$(check_last_exit_code)'
    
    # Setup some basic aliases, and add color where possible
    alias ...="cd ../.."
    alias ....="cd ../../.."
    alias ls='ls --color'
    alias la='ls -lah --color'
    alias grep='grep --color'
    alias ip='ip -c'
    alias udb='sudo updatedb'
    alias clr='clear'
    alias rcd='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
    alias spotify-dl='spotify_dl'
    alias vi='nvim'
    alias vim='nvim'
    
    # Run afetch if in terminal
    [[ "$(cat /proc/$PPID/comm)" =~ "(kitty)" ]] && afetch
    [[ "$(cat /proc/$PPID/comm)" =~ "(kitty)" ]] && export TERM="kitty"
    
    ### Added by Zinit's installer
    if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
        print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
        command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
        command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
            print -P "%F{33} %F{34}Installation successful.%f%b" || \
            print -P "%F{160} The clone has failed.%f%b"
    fi
    
    source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
    autoload -Uz _zinit
    (( ${+_comps} )) && _comps[zinit]=_zinit
    
    # Load a few important annexes, without Turbo
    # (this is currently required for annexes)
    zinit light-mode for \
        zdharma-continuum/zinit-annex-as-monitor \
        zdharma-continuum/zinit-annex-bin-gem-node \
        zdharma-continuum/zinit-annex-patch-dl \
        zdharma-continuum/zinit-annex-rust
    
    ### End of Zinit's installer chunk
    
    zinit light zsh-users/zsh-syntax-highlighting
    zinit light zsh-users/zsh-autosuggestions
    zinit light zsh-users/zsh-history-substring-search
    eval "$(ctrlg init zsh)"
    

    I'm sorry that this is probably the worst .zshrc you've ever seen. :(

    Additional Details

    Lenovo ThinkPad X1 Yoga 4th Intel i7 10510U 16gb DDR4 Intel Integrated Graphics

    bug 
    opened by greembow 11
  • [Feature]: add key bind to copy selected path to clipboard

    [Feature]: add key bind to copy selected path to clipboard

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Probably ctrl + y for the key binding. It should copy the selected path to the clipboard and exit.

    Use Case

    When you want to run a command on the selected path but don't necessarily want to cd to it.

    enhancement help wanted 
    opened by mrjones2014 4
  • [Feature]: Add key bind for scrolling preview

    [Feature]: Add key bind for scrolling preview

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    The action names for the Skim finder are just "up" and "down". We should bind keys to those actions so that preview can be scrolled. Not sure about what the key binds should be.

    Use Case

    So that previews can be scrolled.

    enhancement good first issue 
    opened by mrjones2014 3
  • [Feature]: Keybind to open selected directory in `$EDITOR` if defined

    [Feature]: Keybind to open selected directory in `$EDITOR` if defined

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    There should be a separate key bind in the fuzzy finder like maybe ctrl + enter or something that, when used, opens the selected directory in $EDITOR (if $EDITOR is defined) in the active tmux pane only. So, both tmux panes would still get cd'd, but only current would open $EDITOR.

    Use Case

    Quickly opening a context to work on writing some code. cd to the directory in all panes, but have the current pane open Neovim to the directory, for example.

    enhancement shell-plugin 
    opened by mrjones2014 2
  • [Feature]: Migrate to Clap 3.0.0 once it is released

    [Feature]: Migrate to Clap 3.0.0 once it is released

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Clap 3.0.0 pretty much does natively what StructOpt does (StructOpt depends on Clap and adds some extra configuration niceties and features). Once Clap 3.0.0 is out of beta, we should migrate to it and remove StructOpt.

    Use Case

    StructOpt will most likely go into maintenance mode once Clap 3.0.0 is released.

    enhancement 
    opened by mrjones2014 2
  • [Feature]: Ability to show any info you want for the directory??🤯 🤯

    [Feature]: Ability to show any info you want for the directory??🤯 🤯

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Related to #19, maybe one way to solve this would be to just have a "hook" system. Basically, if a function exists in the shell called ctrlg_dir_info or something like that, it gets run and the output (truncated to the first line of output only) is shown in the finder.

    Use Case

    Showing repo path (e.g. like on GitHub how it is shown as mrjones2014/ctrlg), git status, etc. You could get really creative and show some really useful info about the directory right next to the directory name in the finder.

    enhancement 
    opened by mrjones2014 2
  • [Feature]: Support using `glow` instead of `bat` for previews

    [Feature]: Support using `glow` instead of `bat` for previews

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Add support for using glow to render markdown previews rather than bat.

    https://github.com/charmbracelet/glow

    It will require changing the setting in settings.rs to specify which tool you want to use. Probably an enum, Bat, Glow, or None (None defaulting to cat).

    Use Case

    glow renders markdown with pizzazz! as their README.md says.

    enhancement 
    opened by mrjones2014 1
  • [Feature]: add a sub-command to print keybindings

    [Feature]: add a sub-command to print keybindings

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    ctrlg keybinds should print out the key bindings of the fuzzy finder. We can use platform-detection to print the right character (alt vs. macOS option symbol) on each platform.

    Use Case

    Quickly checking keybinds if you've forgotten them.

    enhancement 
    opened by mrjones2014 1
  • [Feature]: Option to run in a floating window like fzf-tmux

    [Feature]: Option to run in a floating window like fzf-tmux

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    fzf-tmux lets you run the fzf finder in either a floating window or split pane, then return the results to the original pane. It's very very cool. For our use I think it makes sense to only support the floating window version.

    Use Case

    Because it looks really awesome 🤩

    enhancement 
    opened by mrjones2014 1
  • [Feature]: Add a key bind to just insert the selected path into the command line of the *current pane only*

    [Feature]: Add a key bind to just insert the selected path into the command line of the *current pane only*

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Similar to #46, it could be useful to have a key bind which just inserts the selected path to the command line of the current pane only.

    Use Case

    Same use case as #46 pretty much. When you want to run a command on the selected path but don't necessarily want to cd to it.

    enhancement good first issue 
    opened by mrjones2014 1
  • [Feature]: Update checking and self updates

    [Feature]: Update checking and self updates

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Implement the CLI itself checking for updates and the ability for it to update itself.

    https://github.com/jaemk/self_update

    Use Case

    Currently the only way people would know there is an update available is by checking here or via Cargo. It would be cool to print a message or something notifying that the user is able to run ctrlg update to update the CLI (ctrlg update not implemented yet).

    enhancement help wanted 
    opened by mrjones2014 1
  • [Feature]: command to add current directory to `search_dirs` config

    [Feature]: command to add current directory to `search_dirs` config

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    It should include the option to save either the current directory exactly, or the current directory as a glob (so, including all directories inside it).

    Use Case

    To easily add new paths to the config file.

    enhancement good first issue 
    opened by mrjones2014 0
  • [Feature]: Try to match terminal theme by default

    [Feature]: Try to match terminal theme by default

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    I made the default theme (statically) to match my terminal theme (which is https://github.com/mrjones2014/lighthaus.nvim). Of course you can customize the colors through the config, but it would be really cool to try to automatically match the color scheme.

    I believe we can do this with indexed colors or something? For example, for Kitty terminal emulator, kitty.conf has several named colors such as background, selection_foreground etc. but also has a set of colors like:

    # normal
    color0 #373C45
    color1 #FF5050
    color2 #44B273
    color3 #ED722E
    color4 #1D918B
    color5 #D16BB7
    color6 #00BFA4
    color7 #8E8D8D
    
    # bright
    color8 #CCCCCC
    color9 #FF4D00
    color10 #10B981
    color11 #FFFF00
    color12 #0DB9D7
    color13 #D68EB2
    color14 #5AD1AA
    color15 #FFFADE
    

    How do we get and use these indexed colors? I think these numbered colors are a standard terminal thing.

    Use Case

    It would be cool to match the user's terminal theme without them having to set it in config.

    enhancement help wanted 
    opened by mrjones2014 0
  • [Bug]: sending the `cd` command to other tmux panes should clear the command line first

    [Bug]: sending the `cd` command to other tmux panes should clear the command line first

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    If you already have a command typed but not yet run, it messes with the tmux integration. See gif example:

    CleanShot-2022-01-11-at-14 21 40

    Shell + Version

    fish, version 3.3.1-838-g1eb58f905
    

    Minimal Configuration to Reproduce

    ctrlg init fish | source
    

    Additional Details

    We'd need a way to clear the line before sending our command. Or simply abort if the line isn't empty.

    bug good first issue 
    opened by mrjones2014 2
  • [Feature]: Publish to Homebrew (needs help)

    [Feature]: Publish to Homebrew (needs help)

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    We should publish to Homebrew. I haven't really done this before. Will require some research or some help from others.

    Use Case

    So that people can install from brew without needing to install a rust toolchain manually.

    enhancement help wanted 
    opened by mrjones2014 2
  • [Feature]: switch from Makefile to `cargo-make`

    [Feature]: switch from Makefile to `cargo-make`

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    • cargo-make: https://github.com/sagiegurari/cargo-make
    • cargo-make GitHub Actions: https://github.com/marketplace/actions/rust-cargo-make

    Use Case

    Makefiles can be a burden to get working on Windows. I don't personally use Windows, but we should make it easier for new contributors to get started.

    enhancement good first issue tooling 
    opened by mrjones2014 1
  • [Feature]: Ensure entry uniqueness

    [Feature]: Ensure entry uniqueness

    Similar Issues

    • [X] Before filing, I have searched for similar issues.

    Description

    Say you have multiple search_dirs configured like so:

    search_dirs:
      - ~/dir1/*
      - ~/dir2/*
    

    and there's a sub-directory under both dir1 and dir2, both called repo, so ~/dir1/repo and ~/dir2/repo.

    Currently they would both just show up in the finder as repo. But they should show up as dir1/repo and dir2/repo. We should include the minimum number of parent directories to ensure that the display text is unique.

    Use Case

    If for some reason there ends up being directories with the same name in the finder, currently there is no way to tell where each one is located.

    enhancement help wanted 
    opened by mrjones2014 0
Releases(v0.9.2)
Owner
Mat Jones
Software engineer, home lab hobbyist, passionate about online privacy and security. Huge Neovim nerd.
Mat Jones
Attempt to make a git profile switcher to switch profiles.

Git Profile Switcher █▀▀ █ ▀█▀   █▀ █░█░█ █ ▀█▀ █▀▀ █░█ █▀▀ █▀█ █▄█ █ ░█░   ▄█ ▀▄▀▄▀ █ ░█░ █▄▄ █▀█

Srikanth K 2 Sep 23, 2022
A browser switcher/chooser written in Rust

bro Introduction One project in Rust that allows users to choose their web browser when clicking a link is bro. bro is a command-line utility that all

Alexander Qi 4 Jan 29, 2023
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
🐢 Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands

Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands. Additionally, it provides optional and fully encrypted synchronisation of your history between machines, via an Atuin server.

Ellie Huxtable 4.6k Jan 1, 2023
a Rust library implementing safe, lightweight context switches, without relying on kernel services

libfringe libfringe is a library implementing safe, lightweight context switches, without relying on kernel services. It can be used in hosted environ

edef 473 Dec 28, 2022
Solving context limits when working with AI LLM models by implementing a "chunkable" attribute on your prompt structs.

Promptize Promptize attempts to solve the issues with context limits when working with AI systems. It allows a user to add an attribute to their struc

Dan Nelson 5 Jul 18, 2023
A minimal window context for Rust on Windows.

winctx A minimal window context for Rust on Windows. I read msdn so you don't have to. This crate provides a minimalistic method for setting up and ru

John-John Tedro 19 Dec 25, 2023
Command-line HTTP client for sending a POST request to specified URI on each stdin line.

line2httppost Simple tool to read lines from stdin and post each line as separate POST request to a specified URL (TCP connection is reused though). G

Vitaly Shukela 3 Jan 3, 2023
Pink is a command-line tool inspired by the Unix man command.

Pink is a command-line tool inspired by the Unix man command. It displays custom-formatted text pages in the terminal using a subset of HTML-like tags.

null 3 Nov 2, 2023
Checkline: checkbox line picker for stdin line input

checkline is a Unix command line interface (CLI) terminal user interface (TUI) that prompts you to check each line of stdin, to pick each line to output to stdout

SixArm 4 Dec 4, 2022
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

null 10.4k Jan 10, 2023
Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

null 743 Jan 1, 2023
Parse command line arguments by defining a struct.

StructOpt Parse command line arguments by defining a struct. It combines clap with custom derive. Documentation Find it on Docs.rs. You can also check

Guillaume P. 2.6k Jan 5, 2023
A command line progress reporting library for Rust

indicatif Documentation A Rust library for indicating progress in command line applications to users. This currently primarily provides progress bars

Armin Ronacher 3.2k Dec 30, 2022
Low-level Rust library for implementing terminal command line interface, like in embedded systems.

Terminal CLI Need to build an interactive command prompt, with commands, properties and with full autocomplete? This is for you. Example, output only

HashMismatch 47 Nov 25, 2022
⚡️ Lightning-fast and minimal calendar command line. Written in Rust 🦀

⚡️ Lightning-fast and minimal calendar command line. It's similar to cal. Written in Rust ??

Arthur Henrique 36 Jan 1, 2023
Command-Line program that takes images and produces the copy of the image with a thin frame and palette made of the 10 most frequent colors.

paleatra v.0.0.1 Command-Line program that takes an image and produces the copy of the image with a thin frame and palette made of the 10 most frequen

Beka Modebadze 24 Dec 29, 2022
parse command-line arguments into a hashmap and vec of positional args

parse command-line arguments into a hashmap and vec of positional args This library doesn't populate custom structs, format help messages, or convert types.

James Halliday 17 Aug 11, 2022
A tactics trainer for the command line

Chess Tactics CLI Practice some chess tactics in your terminal while you wait for your code to compile. Fetches tactics from this tactics API. Built W

Marcus Buffett 28 Dec 21, 2022