From 5147e89b6b11160625cf1634292003b91e209adb Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Tue, 25 Jun 2019 09:16:23 +0300 Subject: [PATCH] gitmenu for mc --- bin/gitmenu | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 bin/gitmenu diff --git a/bin/gitmenu b/bin/gitmenu new file mode 100755 index 0000000..e795677 --- /dev/null +++ b/bin/gitmenu @@ -0,0 +1,112 @@ +#!/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 + +