From 07fc2644a237187dd4c5680e88f4adadbf533603 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Wed, 12 Aug 2015 12:06:23 -0600 Subject: Initial commit of the working files --- segments/vcs_compare.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 segments/vcs_compare.sh (limited to 'segments/vcs_compare.sh') diff --git a/segments/vcs_compare.sh b/segments/vcs_compare.sh new file mode 100755 index 0000000..988751c --- /dev/null +++ b/segments/vcs_compare.sh @@ -0,0 +1,68 @@ +# This checks if the current branch is ahead of +# or behind the remote branch with which it is tracked + +# Source lib to get the function get_tmux_pwd +source "${TMUX_POWERLINE_DIR_LIB}/tmux_adapter.sh" + +flat_symbol="โคš" + +run_segment() { + tmux_path=$(get_tmux_cwd) + cd "$tmux_path" + stats="" + if [ -n "${git_stats=$(__parse_git_stats)}" ]; then + stats="$git_stats" + elif [ -n "${svn_stats=$(__parse_svn_stats)}" ]; then + stats="$svn_stats" + elif [ -n "${hg_stats=$(__parse_hg_stats)}" ]; then + stats="$hg_stats" + fi + + if [ -n "$stats" ]; then + echo "${stats}" + fi + return 0 +} + +__parse_git_stats() { + type git >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + return + fi + + # check if git + [[ -z $(git rev-parse --git-dir 2> /dev/null) ]] && return + + tracking_branch=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)) + + # creates global variables $1 and $2 based on left vs. right tracking + set -- $(git rev-list --left-right --count $tracking_branch...HEAD) + + behind=$1 + ahead=$2 + + # print out the information + if [[ $behind -gt 0 ]] ; then + local ret="โ†“ $behind" + fi + if [[ $ahead -gt 0 ]] ; then + local ret="${ret}โ†‘ $ahead" + fi + echo "$ret" +} + +__parse_hg_stats() { + type hg >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + return + fi + # not yet implemented +} + +__parse_svn_stats() { + type svn >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + return + fi + # not yet implemented +} -- cgit v1.2.3