gobbledygook88 / claw

A simple command line tool for storing commands and text snippets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLAW 🦖

Build Status

A simple way to save commonly run commands or snippets.

There is the ability to share and collaborate on commands, e.g. in a work environment. This is done via git and the concept of spaces which we will go into detail later.

This tool is intended to work alongside dotfiles e.g. .bash_aliases or .functions but is slightly more portable if rsync isn't preferred.

Much of the code has been heavily inspired by the wonderful Unix password manager pass. At its core, claw is basically pass without GPG.

What's in the name?

Claw was the name for a similar command-line tool project of mine that never saw it past the design phase. The current feature-set is just a fraction of what was initially planned. That project may still happen or eventually be merged into this tool. Recycling is cool.

Table of contents

Installation

Ubuntu

apt install claw

MacOS

brew install claw

Claw uses what is defined in $EDITOR, so be sure to configure this.

Dependencies

  • bash
  • tree
  • xclip
  • gnu-getopt (if on MacOS)
  • git (optional, but recommended)
  • fzf (optional, for better search functionality)

Usage

Initialise Claw

claw init [dirname]

By default, a directory at $HOME/.claw/_default/ will be created. To use another name, or to create another space, specify a directory name.

Display help

For full usage information, run

claw help

Save new command

claw create foo/bar

This will create a new file in the currently active space.

Display saved commands

claw show foo/bar

Add the -c flag to copy the command directly to the clipboard.

claw show -c foo/bar

Use the -p flag to display the full path to the saved command.

claw show -p foo/bar

Edit existing command

claw edit foo/bar

Search saved commands

claw search query

Useful tips

Save the last run command

claw create foo/bar "$(echo !!)"

Configure work environment

source $(claw show -p work/env)

Search Claw commands

Scan through Claw commands (interactively)

Use hjkl or arrow keys to navigate the tree. Commands are displayed on the left, with paging.

Hit enter to

  • Copy to clipboard
  • .sh -> $ /path/to/script.sh
  • No file extension: just paste contents into command line

### Commands with environment variables

Environment variables are detected. If any variable is not defined, then we display a message and/or prompt for input.

If using claw create inline, be sure to escape $ symbols.

Spaces

Spaces are a simple way to organise commands and scripts for different environments. You may have multiple projects on the go and each will have its own set of commands to run, e.g. for NodeJS or database administration.

Here is a more illustrative example:

  • ``

Git support

claw git init [dirname]

Runs git init in $HOME/.claw/_default/. Providing dirname will track the given local directory.

To track another repository, run

claw git clone git@url/to/remote:repo.git

By default, this will clone the remote repository into $HOME/.claw/repo/. To provide another name use the following

claw git clone git@url/to/remote:repo.git another_name

Any extra git repositories are automatically made into a space. On the other hand, any space can be made into a git repository.

Environment variables

The following environment variables are available to use:

  • CLAW_DIR: The base directory to store all claw related files. Default: $HOME/.claw/
  • CLAW_DEFAULT_SPACE: Name of the default space. Default: _default.

Development

  • Clone repo: git clone https://github.com/gobbledygook88/claw.git
  • apt install shellcheck or brew install shellcheck
  • pip install bashate
  • Run test scripts
    • ./tests/staticanalysis.sh
    • ./tests/run_all.sh

Inspiration

  • pass: The Standard Unix Password Store
  • pgcli

TODO

  • Bash autocompletion
  • Git flow
  • Interactive prompt
  • Packaging for unix repositories and MacOS brew
  • Easy creation of man pages for saved commands

About

A simple command line tool for storing commands and text snippets

License:GNU General Public License v3.0


Languages

Language:Shell 100.0%