Skip to content

Instantly share code, notes, and snippets.

@dpie
Created September 15, 2010 04:06
Show Gist options
  • Save dpie/580226 to your computer and use it in GitHub Desktop.
Save dpie/580226 to your computer and use it in GitHub Desktop.
# Terminitor (Ruby gem) command shortcuts
# term PROJECT >> terminitor start PROJECT
# term PROJECT open >> terminitor open PROJECT
function term() {
if [ -z "$1" ]; then
echo Project argument required
else
local terminator_project="$1"
local terminitor_action="${2:-start}"
terminitor "$terminitor_action" "$terminator_project";
fi
}
@ilikepi
Copy link

ilikepi commented Sep 15, 2010

If you're going to be explicit with $terminator_action, you might as well be explicit about the other argument as well. Also, when taking arguments and passing them to another program, it's good to quote them. You can pass multiple words as a single argument using quotes, so you want to handle that case, even if you'd never actually use it:

$ term "my project name has spaces"

Here's my suggestion:

# Terminitor (Ruby gem) command shortcuts
# term PROJECT >> terminitor start PROJECT
# term PROJECT open >> terminitor open PROJECT
function term() {
  if [ -z "$1" ]; then
    echo Project argument required
  else
    local terminator_project="$1"
    local terminitor_action="${2:-start}"
    terminitor "$terminitor_action" "$terminator_project";
}

@dpie
Copy link
Author

dpie commented Sep 15, 2010

Thanks, that helped clarify a few things. What does the - in "-start" imply?

BTW you missed a fi before the ending }, but I fixed that in the updated gist.

@ilikepi
Copy link

ilikepi commented Sep 15, 2010

Woops, damnit.

${var:-default} is the syntax for specifying a default expansion value. The '-' doesn't imply anything really, it's just a syntax token.

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