#!/bin/bash function usage { echo -e ' Git menu note: some commands require color= in [extensions] This tool mainly exists as a menu command for Midnight Commander. Usage: gitmenu [args] gitmenu 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" \ ' echo '# GIT: [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 | [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 .git -prune \) -o -type f -print read -p "Add all these files? y/n" foo [[ $foo = "n" ]] && exit git add "$@" ;; c) [[ -z "$@" ]] || { echo Commiting files: find "$@" \( -type d -name .git -prune \) -o -type f -print } [[ -z "$@" ]] && { git status } read -e -p "Commit message: " MSG [[ -z "$@" ]] && { git commit -m "$MSG" -a } || { git commit -m "$MSG" "$@" } ;; d) git diff "$@" ;; l) git log "$@" ;; m) git merge "$@" ;; p) git pull "$@" ;; P) git push "$@" ;; r) [[ -z "$@" ]] && argsreq find "$@" \( -type d -name .git -prune \) -o -type f -print read -p "Remove all these files? y/n" foo [[ $foo = "n" ]] && exit git rm "$@" ;; s) git status "$@" ;; q) exit ;; *) echo Command $CMD not recognized ;; esac