Setting aliases using Linux bash shell script with arguments

Its useful to use shortcut commands for common tasks, especially when it comes to repository management.

I like to pipe diff output into vim and logs into less, but at times I have to switch between multiple repositories such as git, svn and bzr.

To use the same alias between the repositories, set up a script and give it an argument.

Create a script file to manage your aliases.

touch workwith.sh
chmod +x workwith.sh

Create an alias to make it easier to access. You may want to put this into your ".bashrc" profile.

alias workwith="source ~/bin/workwith.sh"

Modify your "workwith.sh" file and paste

#! /bin/bash

if [ "$1" = "git" ]; then
        alias d="git diff | vim -"
        alias commit='git commit -m'
elif [ "$1" = "svn" ]; then 
        alias d="svn diff | vim -"
        alias commit='svn commit -m'
elif [ "$1" = "bzr" ]; then
        alias d="bzr diff --diff-options='-U 5 -p' | vim -"
        alias commit='bzr commit -m'
else
        echo "Unknown command"
fi

Now, whenever you want to switch between the commands, type

workwith svn

workwith git

workwith bzr

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog