Thanks to visit codestin.com
Credit goes to github.com

Skip to content

idelchi/slot

Repository files navigation

slot

slot logo

Save and render named shell commands


GitHub release Go Reference Go Report Card Build Status License: MIT

slot is a command-line tool for saving, organizing, and executing templated shell commands.

  • Save commands with Go template variables and tags for organization in a simple YAML file
  • Render commands with variable substitution using KEY=VAL
  • Shell integration places rendered commands into your prompt for execution

Installation

curl -sSL https://raw.githubusercontent.com/idelchi/slot/refs/heads/main/install.sh | sh -s -- -d ~/.local/bin

Usage

# Save a command with Go template variables
$ slot save deploy 'kubectl apply -f {{.file}}' --tags k8s --tags prod --description 'deploy to prod'
# Save a command with default variables
$ slot save deploy 'kubectl apply -f {{.file}} -n {{.namespace}}' --var file=k8s.yml --var namespace=default
# Render a command with variable substitution
$ slot render deploy file=k8s.yml
kubectl apply -f k8s.yml
# List all saved slots
$ slot list
NAME    CMD                         TAGS      DESCRIPTION
deploy  kubectl apply -f {{.file}}  k8s,prod  deploy to prod
# List slots filtered by tags
$ slot list --tags k8s
# Remove a slot
$ slot remove deploy

Data Storage

Slots are stored in YAML format at ~/.config/slot/slots.yaml. Location can be overridden with the --config flag or SLOTS_FILE environment variable.

Shell Integration

Generate shell integration snippets for command placement:

# Generate integration
$ slot init <shell>

The integration enables the slot run command which places rendered output into your shell prompt for editing before execution.

Use --yes/-y to execute the rendered command directly without editing.

Adding the --fzf flag enables further integration, binding Ctrl-X and Ctrl-Z keys to running or searching slots.

Commands

save — Save a command slot
  • Usage: slot save <name> <command> [flags]
  • Flags:
    • --tags – Tags for the slot (repeatable)
    • --description – Description for the slot
    • --var – Default template variable as key=value (repeatable)
    • --force – Overwrite existing slot
render — Render a saved command slot
  • Usage: slot render <name> [key=value...]
list/ls — List saved slots
  • Usage: slot list [flags]

  • Flags:

    • --tags – Filter by tags (repeatable)
    • --tsv – Output in TSV format
remove/rm — Delete a saved slot
  • Usage: slot remove <name>
init — Generate shell integration snippets
  • Usage: slot init <bash|zsh> [flags]
  • Flags:
    • --fzf – Enable fzf integration (binds to Ctrl-X and Ctrl-Z keys)

Templating

In addition to your own key=value arguments, the following variables are always available inside templates:

  • SLOTS_FILE – Full path to the slots YAML file
  • SLOTS_DIR – Directory containing the slots YAML file
  • CLI_ARGS – All arguments after --, joined into a single space-delimited string
  • CLI_ARGS_SPLIT – Same arguments as above, but preserved as a list ([]string) for iteration

All templates use Go’s text/template syntax, with extra functions from slim-sprig.

Slots can define default variables with vars. Command-line key=value arguments override slot variables.

slots:
  - name: deploy
    description: Deploy manifest
    cmd: kubectl apply -f {{.file}} -n {{.namespace}}
    vars:
      file: k8s.yml
      namespace: default
    tags:
      - k8s

Variable precedence is:

  1. Slot vars
  2. Built-in variables such as SLOTS_FILE and SLOTS_DIR
  3. Command-line key=value arguments

Includes

To include other slot files, use include:

include:
  - ./shared.yaml
  - ./team/slots.yaml
slots:
  - name: deploy
    cmd: kubectl apply -f {{.file}}
    vars:
      file: k8s.yml

Include paths are resolved relative to the file that declares them. Recursive includes fail with an error. list and render can use included slots. save writes new slots to the root slots file; remove deletes the visible slot from whichever file defines it.

Demo

Demo

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors