Files
q-tools/bin/hgmenu
2015-07-24 16:29:18 +03:00

135 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
function usage {
echo -e ' Mercurial menu
note: some commands require color= in [extensions]
Usage: hgmenu [args]
hgmenu will interactively query for a command to use.
[args] will be passed on to that command
'
}
function argsreq {
echo Arguments required
exit
}
while getopts h opt
do case "$opt" in
h)
usage
exit
;;
esac
done
PRC="cat"
hash highbeam 2> /dev/null && PRC="highbeam"
export HB_RULES='"^\[.\]" "$G" \
'
echo 'Mercurial:
[a] Add files to track*
[c] Commit changes to local repository
[d] Difference of current and previous versions
[l] Log
[m] Merge conflicting change sets
[p] Pull changes from remote repository
[P] Push changes to remote repository
[r] Remove files*
[u] Update from local repository
[s] Status
[t] Start thg, graphical repository viewer
[v] View, internal graphical viewer
[X] Add the required extensions to your ~/.hgrc
[q] Quit
* Requires arguments
' | $PRC
echo Current arguments: "$@"
read -p "Command: " -N 1 CMD
echo ""
LESS="less -R -S"
case "$CMD" in
a)
[[ -z "$@" ]] && argsreq
find "$@" \( -type d -name .hg -prune \) -o -type f -print
read -p "Add all these files? y/n" foo
[[ $foo = "n" ]] && exit
hg add "$@"
;;
c)
[[ -z "$@" ]] || {
echo Commiting files:
find "$@" \( -type d -name .hg -prune \) -o -type f -print
}
[[ -z "$@" ]] && {
hg status -mard
}
read -e -p "Commit message: " MSG
hg commit -m "$MSG" "$@"
;;
d)
hg diff --color always "$@"| $LESS
;;
l)
hg log -G --color always "$@" | $LESS
;;
m)
hg merge "$@"
;;
p)
hg pull "$@"
;;
P)
hg push "$@"
;;
r)
[[ -z "$@" ]] && argsreq
find "$@" \( -type d -name .hg -prune \) -o -type f -print
read -p "Remove all these files? y/n" foo
[[ $foo = "n" ]] && exit
hg remove "$@"
;;
u)
hg update "$@"
;;
s)
hg status --color always "$@" | $LESS
;;
t)
thg "$@"&
;;
v)
hg view "$@"&
;;
q)
exit
;;
X)
grep -q "color\s*=" ~/.hgrc || {
grep -q "^[extensions]" ~/.hgrc && {
sed '0,/^\[extensions\]/s//[extensions]\ncolor=/' ~/.hgrc
} || {
echo -e "[extensions]\ncolor="
}
}
grep -q "hgk\s*=" ~/.hgrc || {
grep -q "^[extensions]" ~/.hgrc && {
sed '0,/^\[extensions\]/s//[extensions]\nhgk=/' ~/.hgrc
} || {
echo -e "[extensions]\nhgk="
}
}
;;
*)
echo Command $CMD not recognized
;;
esac