boop
boop

Reputation: 7787

Bash alias function with predefined argument

I have an alias gl which is an wrapper for git log.

Basically like this

function gitLog(){
  if [ $# -eq 0 ]
    then
      git log 
    else
      git log -n $1
}

alias gl=gitLog

I want to add an alias which just calls gitLog with an argument like this

alias gl10=gitLog(10)

I don't want to pass the argument from the command line. It shall just be a handy shortcut.

Is this possible?

Upvotes: 1

Views: 52

Answers (1)

Eugeniu Rosca
Eugeniu Rosca

Reputation: 5315

Simply, add it in your .bashrc like:

alias gl10="gitLog 10"

To apply the changes: source ~/.bashrc

Upvotes: 2

Related Questions