Mac – How to build a custom command with options

command linegitmac

I want to make a command on my Mac to do the following:

git add .
git commit -m CUSTOM_COMMEND_BY_COMMAND
git push
cap deploy

I seem to be calling those very often. I was wondering what's the best way to build a command such as:

qwik_dply -m "fixed a big"

Best Answer

You could do this using a custom bash function. Add that to your .bash_profile:

function qwik_dply {
    local msg=$1
    if [ -z "$msg" ] ; then
        msg="No message"
    fi
    git add .
    git commit -m "$msg"
    git push
    cap deploy
}

Call from bash using qwik_dply "Some text"


Alternatively, make it a proper script:

#!/usr/bin/env bash
msg=$1
if [ -z "$msg" ] ; then
    echo "Usage: qwik_dply <message>"
    exit 1
fi
git add .
git commit -m "$msg"
git push
cap deploy

Save as qwik_dply.sh, run chmod ugo+x qwik_dply.sh and mv it to /usr/bin or any other directory on your $PATH.

Then, run using qwik_dply.sh "Some message". You could remove the file name extension, of course.

Related Question