Skip to content

Instantly share code, notes, and snippets.

@harperreed
Created January 29, 2014 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harperreed/8693689 to your computer and use it in GitHub Desktop.
Save harperreed/8693689 to your computer and use it in GitHub Desktop.
Name space your shell commands

#Name space your shell commands

From the awesome jim blandy

Create a directory to hold all your little project-specific scriptlets; mine is ~/moz/bin.

Then, create a script in your personal bin directory --- my little script is called ~/bin/moz --- that reads something like:

#!/usr/bin/env bash
PATH=$HOME/moz/bin:$PATH
exec "$@"

Then, you create your little utility scripts, like ~/moz/bin/clean-hg-unknowns:

#!/usr/bin/env bash

hg status -nu0 . | xargs -0 rm

Now, you can invoke that anywhere like this:

$ moz clean-hg-unknowns

Note that the "$@" is kind of a magic thing: it gets all the quoting, etc. exactly right --- the arguments your subcommand gets are exactly those that the 'moz' prefix got, just with the 'moz' dropped. It won't be confused by spaces, leading dashes, embedded quotes, and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment