Command Line Favs

Command Line Favs is a CLI utility for organizing your commonly used shell commands. Commands are stored as a Command Name (think Alias) to Command map within your ~/.favs file and can be organized into groups.

A ~/.favs file might look something like:

Installation

Command Line Favs is packaged a ruby gem. To install run:

gem install command-line-favs

Documentation

#comments are supported so are un-grouped commands like this one
#positional-based substitution is also suported
pr = "echo $0"

#a group for all your ssh commands
[ssh]
google = "ssh -P 25001 [email protected]"
work = "ssh [email protected]"

[dev]
build = "mvn -Pdev -U clean install"
arq = "mvn -Parq-jbossas-remote clean verify -Pdev"

[Demo]
files_mod = "hg status | awk 'NR>2{print $2}' | xargs cat"

You get the idea.

Getting help

A CLI utility is not complete without some decent help/documentation. Running fav with the --help flag will display all available options:

$ fav --help

The typically format for running a fav command is fav [options] command_name, where options usually contains an Action flag:

Fav a command

A command is added as a Fav by using the -a action flag. The following command will add a command as a Fav:

$ fav -a 'echo I am a Test Command' tc

Or to Fav a command to a group;

$ fav -a 'echo I am a Test Command in a group' -g Demo tgc

In the event that the group does not yet exist when adding a Fav to group, the group will be automatically added.

You can also always manually add a Fav by modifying your ~/.favs file.

String Substitution

There is support for position string substitution; the syntax is '$' (see the pr command in the examle .favs file).

Remove a Fav

A command is removed as a Fav by using the -r action flag. The following command will remove a command as a Fav:

$ fav -r tc

Or remove a group command:

$ fav -r -g Demo files_mod

You can also always manually remove a Fav by modifying your ~/.favs file.

List Avaliable Favs

List favs within a group:

fav -l -g ssh

List all commands:

fav -l -g

Run a Fav

To run a non-grouped command:

fav tc

To run a single grouped command:

$ fav -g TestGroup tgc

Or run the entire group of commands:

$ fav -g TestGroup --no_prompt

When running an entire group of commands the default behavior is to prompt on each command. This can be overridden by supplying the --no_prompt flag.

Future enhancements

  • Tab completion for groups and commands
  • Support the running of bash/zsh built-in commmands