o9s
is a microblog
home archives search feed blogroll


Bash Aliases With Arguments

They are not possible. Use functions instead.

Below is a function to commit to git. It accepts the commit message as a parameter.

gcm() {
    if [ -z "$1" ]
        then
            echo "No commit message"
    else
        git commit -m $1
    fi
}

Regular aliases are much simpler. Here’s an alias to add all the files in the working directory to git.

alias ga="git add ."

If you’re on macOS, add those to ~/.bash_profile and then use the following command.

source ~/.bash_profile

You can now use

ga
gcm "My commit message"

instead of

git add .
git commit -m "My commit message"
Posted on 2018-01-20   #bash  






← Next post    ·    Previous post →