#!/bin/bash function usage { echo -e ' Mercurial menu note: some commands require color= in [extensions] This tool mainly exists as a menu command for Midnight Commander. 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" \ "|.*|" "$W" \ "^#\s.*" "$Y" \ ' COLORED=0 grep -q "color\s*=" ~/.hgrc && { COLORED=1 COLORSTR="--color always" } 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] | Thg | X repository viewer [v] | View | internal X viewer [X] | Install | color and view 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 $COLORSTR } read -e -p "Commit message: " MSG hg commit -m "$MSG" "$@" ;; d) hg diff $COLORSTR "$@" | $LESS ;; l) hg log -G $COLORSTR "$@" | $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 $COLORSTR "$@" | $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=" >> ~/.hgrc } echo "Added color support" } grep -q "hgk\s*=" ~/.hgrc || { grep -q "^[extensions]" ~/.hgrc && { sed '0,/^\[extensions\]/s//[extensions]\nhgk=/' ~/.hgrc } || { echo -e "[extensions]\nhgk=" >> ~/.hgrc } echo "Added X view support" } ;; *) echo Command $CMD not recognized ;; esac