Making aliases for commonly used commands is nice if you know what commands you'll use a lot. But sometimes the same command is used several times in a row with different arguments. For example:

git fetch --some-option
git do-something-else
git another-command
# ... lots more of the same

In this case it would be nice to drop git each time. In some cases it may be multiple arguments a command should start with (e.g. sudo apt ...).

What software can do this?

Note: I saw a project like this trending on GitHub a long time ago but can no longer find it. Naturally it would be nice if someone remembers what I'm thinking of, but anything that fits the description (or is a workable alternative) is an acceptable answer.


If you use bash - you can make the following function

myprefix() { echo -n "> $1 "; while read -r line; do $1 $line; echo -n "> $1 "; done }

Then when you have a bunch of git commands you can issue

myprefix git

And press ctrl-c to recover.

  • You can insert the function in your .bashrc file. – jhilmer Jan 10 '17 at 16:46
  • Accepting for now as this is fits the basic idea of what I was looking for. Thanks! – Nateowami Jan 12 '17 at 2:59

On your alias since its shell syntax you are free to access command line parameters using $1 $2 $3 to puck parm1 parm2 parm3

alias gitdo="git do-something-else $1"    
alias gitand="git another-command $1 $2 "

just put these alias definitions into your ~/.bashrc file ... usage would then be

gitdo my-parm1

Alternative trick to alter prior command is to search for it then do in place edits ... say I just issued

git foo bar blah

then later in same terminal I can pull back that command either by simply using up arrow key or by doing a command line search

ctrl-r foo [enter]

which will retrive above to permit the edit and re-issue (ctrl-e to jump to end of line, ctrl-a jumps to line beginning, or ctrl arrow left right jumps words)

git woo bar blah

another search trick would be

history | grep foo
  • Thanks--but the ideas is that the aliases aren't generally known ahead of time. For example, say you're suddenly using the convert command a lot in one session. It doesn't make a lot of sense to go and create an alias for it (unless using it a ton). You're right though that this adds the ability to supply arguments (which not all aliases would accept). – Nateowami Jan 10 '17 at 16:36
  • Didn't know about the ctrl+r trick. Super helpful! Thanks. – Nateowami Jan 12 '17 at 2:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.