Skip to content

Instantly share code, notes, and snippets.

@izmailoff
Last active December 13, 2015 17:28
Show Gist options
  • Save izmailoff/4948284 to your computer and use it in GitHub Desktop.
Save izmailoff/4948284 to your computer and use it in GitHub Desktop.
Universal SCM (Source Control Management) commands. If you always forget which SCM you are using (SVN, GIT, etc) this script is supposed to help you to abstract their common commands like: commit, update, diff. Include it in your bashrc or bash_profile
#!/bin/bash
# Run this file to register these functions in your shell.
# You can include it in your .bashrc or .bash_profile like this:
# . ./scmhelper.sh
###############################################################################
# Helper function that figures out which SCM
# you are using.
function getScmType()
{
currentDir=$(pwd)
finished=false
scmName='unknown'
while(! $finished); do
if [ -d '.git' ]; then
scmName='git'
finished=true
else if [ -d '.svn' ]; then
scmName='svn'
finished=true
else if [ '/' = "$(pwd)" ]; then
finished=true
else
cd ..
fi
fi
fi
done
cd "$currentDir"
}
###############################################################################
###############################################################################
# Functions that you use directly.
# You can avoid repeating code by putting all
# commands in a map/array, but I'm too lazy to do that now.
# Further improvements are coming soon.
function scmguidiff()
{
getScmType
case $scmName in
git)
git difftool -y -t meld
;;
svn)
svn diff --diff-cmd="meld"
;;
*)
echo "unknown SCM"
;;
esac
}
function scmdiff()
{
getScmType
case $scmName in
git)
git diff
;;
svn)
svn diff
;;
*)
echo "unknown SCM"
;;
esac
}
function scmup()
{
getScmType
case $scmName in
git)
git pull
;;
svn)
svn up
;;
*)
echo "unknown SCM"
;;
esac
}
function scmstatus()
{
getScmType
case $scmName in
git)
git status
;;
svn)
svn st
;;
*)
echo "unknown SCM"
;;
esac
}
function scmst()
{
scmstatus
}
function scmcommit()
{
getScmType
if [ $# -eq 0 -o -z "$1" ]; then
echo "ERROR: Empty commit message."
return
fi
case $scmName in
git)
git commit -a -m "$1"
;;
svn)
svn commit -m "$1"
;;
*)
echo "unknown SCM"
;;
esac
}
function scmlog()
{
getScmType
case $scmName in
git)
git log
;;
svn)
svn log -l 5
;;
*)
echo "unknown SCM"
;;
esac
}
###############################################################################
@izmailoff
Copy link
Author

To use it after you ran the script just type the name of the function:

 scmlog
 scmcommit "my message"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment