Skip to content
/ gas Public

A smart command runner with directory-scoped history.

License

Notifications You must be signed in to change notification settings

sisoe24/gas

Repository files navigation

gas

A smart command runner with directory-scoped history by default.

What it does

gas helps you run commands and scripts without having to remember the exact syntax every time. By default, it stores and reuses commands for the current directory. If you add a -label, you can run that command from any directory.

It's particularly handy when you're jumping between different projects that all have their own build commands, test runners, or scripts.

Core behavior

  • gas (no flags): runs the last command saved for the current directory only.
  • gas -run "<command>": runs and saves that command for the current directory.
  • gas -run <label>: resolves a labeled command and can run it from any directory.
    • If the same label exists in multiple directories, gas prefers the one from your current directory.

Features

  • Smart command history - remembers commands per directory
  • Label commands - give frequently used commands memorable names
  • Interactive selection - browse your command history with fzf
  • Environment variables - save environment settings with commands

Installation

go install github.com/sisoe24/gas@latest

Optional but recommended:

  • fzf for the interactive menus
  • bat for pretty file previews

Basic usage

Run a command and remember it:

gas -run "npm test"

Re-run the last command in this directory only:

gas

Give a command a label so you can run it from anywhere:

gas -run "go test ./..." -label "test-all"
gas -run test-all  # labeled command; works from any directory

Browse and pick from your history:

gas -browse        # commands from current directory
gas -browse-all    # commands from all directories

Examples

Some real-world usage patterns:

# Set up a build command with a label
gas -run "make build && make test" -label "build-test"

# Run a script with specific environment variables
gas -run ./deploy.sh -env "ENV=staging" -label "deploy-staging"

# Run with interactive shell (loads your .bashrc/.zshrc, etc.)
gas -run myfunction -shell

# Just run a one-off command
gas -run "find . -name '*.go' | xargs wc -l"

# Add a command without running it
gas -add "echo 'hello world'" -label "greet"

# Later, just type gas to repeat the last command
gas

Other useful commands

gas -last                        # show info about the last command
gas -delete-directory-commands   # delete command history for current directory
gas -delete-all-commands         # delete all command history
gas -db-path                     # show where the history database is stored
gas -db-table                    # show database table name

Interactive Browser

When using -browse or -browse-all, you get an interactive fzf interface with these keyboard shortcuts:

  • ENTER - Run the selected command
  • CTRL+D - Delete the selected command
  • CTRL+E - Edit the selected command
  • CTRL+Y - Copy command to clipboard
  • F1 - Show help
  • ESC - Cancel and exit

Environment Variables

  1. SHELL or GAS_SHELL

    • Determines which shell gas uses to run commands. For Unix-like systems, SHELL is typically set automatically. On Windows, set GAS_SHELL to your preferred shell (e.g. powershell.exe or pwsh)

    [!TIP] Powershell: $env:GAS_SHELL=(Get-Process -Id $PID).path

  2. EDITOR or GAS_EDITOR

    • Required to open files in your default text editor for editing commands. For Unix-like systems, EDITOR is typically set automatically. On Windows, set GAS_EDITOR to your preferred editor.
  3. GAS_DB_PATH

    • Overrides the default database file path (~/.config/gas/gas.sqlite).
  4. GAS_FZF_PREVIEW_CMD

    • Custom preview command for fzf when browsing command history. The command data is passed as base64-encoded string to handle multiline content.
    • Default: echo {2} | base64 -d
    • If bat exists: echo {2} | base64 -d | bat --language=yaml --color=always

    [!TIP] Powershell: $env:GAS_FZF_PREVIEW_CMD="powershell -Command '[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String(''{2}''))'" or use WSL: wsl echo {2} | wsl base64 -d

Contributing

If you find bugs or want to add features, feel free to open an issue or submit a pull request. The code is pretty straightforward Go.

To run tests:

go test -v

About

A smart command runner with directory-scoped history.

Topics

Resources

License

Stars

Watchers

Forks