Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Populate the "Tools" menu entry in Git GUI
#!/bin/bash
#
# Copyright (c) 2018 Patryk Szczepankiewicz. All rights reserved.
#
# For more info, see:
# http://blog.desktopobjects.net/2018/06/populate-tools-menu-entry-in-git-gui.html
#
VERBOSE_PRINT_OUT=1
FORCE_ASSIGN_FOR_ALL=1
# FORCE_CONSOLE_FOR_ALL=1
MANDATORY_SUPPOSED_TRUE=true
GIT_BUILTIN_ALWAYS_TRUE=true
WIN_BUILTIN_ALWAYS_TRUE=true
# =================================================================================================
#
#
# M A I N F U N C T I O N A L I T Y F O R T H E L I S T
#
#
# =================================================================================================
function ONE_FILE_APP_SET ()
{
local TOOL_CATEGORY=$1
local TOOL_CMD_FULL_NAME=$2
local TOOL_CMD_COMMANDLINE=$3
[ -z "$TOOL_CATEGORY" ] || TOOL_CMD_FULL_NAME="$TOOL_CATEGORY/$TOOL_CMD_FULL_NAME"
local oldVal=""
[ -n "$VERBOSE_PRINT_OUT" ] && echo "Configuring '$TOOL_CMD_FULL_NAME' tools entry..."
[ -n "$FORCE_ASSIGN_FOR_ALL" ] || oldVal=$(git config --global --get guitool."$TOOL_CMD_FULL_NAME".cmd)
[ -n "$oldVal" ] || git config --global guitool."$TOOL_CMD_FULL_NAME".cmd "$TOOL_CMD_COMMANDLINE"
[ -n "$oldVal" ] || git config --global guitool."$TOOL_CMD_FULL_NAME".needsfile yes
[ -n "$oldVal" ] || git config --global guitool."$TOOL_CMD_FULL_NAME".noconsole yes
[ -z "$FORCE_CONSOLE_FOR_ALL" ] || git config --global guitool."$TOOL_CMD_FULL_NAME".noconsole no
}
# =================================================================================================
#
#
# S T A N D A R D B O I L E R P L A T E C O D E
#
#
# =================================================================================================
AU3ROOT_INF=$AU3ROOT
[ -d "$AU3ROOT_INF" ] || AU3ROOT_INF=$autoit3dir
[ -d "$AU3ROOT_INF" ] || AU3ROOT_INF=$SYSTEMDRIVE/Progra~1/AutoIt3
[ -d "$AU3ROOT_INF" ] || AU3ROOT_INF=$SYSTEMDRIVE/Progra~2/AutoIt3
AU3ROOT_NIX=${AU3ROOT_INF//\\//}
AU3ROOT_WIN=${AU3ROOT_INF////\\}
GITROOT_INF=$GITROOT
[ -d "$GITROOT_INF" ] || GITROOT_INF=$SYSTEMDRIVE/Progra~1/Git
[ -d "$GITROOT_INF" ] || GITROOT_INF=$SYSTEMDRIVE/Progra~2/Git
GITROOT_NIX=${GITROOT_INF//\\//}
GITROOT_WIN=${GITROOT_INF////\\}
# =================================================================================================
#
#
# C U S T O M B O I L E R P L A T E C O D E
#
#
# =================================================================================================
#
# NPP TOOL INFO
#
NPP_PATH_x=""
[ -a "/c/Progra~2/Notepad++/notepad++.exe" ] && NPP_PATH_x="/c/Progra~2/Notepad++/notepad++.exe"
[ -a "/c/Progra~1/Notepad++/notepad++.exe" ] && NPP_PATH_x="/c/Progra~1/Notepad++/notepad++.exe"
#
# MELD TOOL INFO
#
MELD_ROOT=""
MELD_EXE=""
[ -a "/c/Progra~2/Meld" ] && MELD_ROOT="/c/Progra~2/Meld"
[ -a "/c/Progra~1/Meld" ] && MELD_ROOT="/c/Progra~1/Meld"
[ -z "$MELD_ROOT" ] || MELD_EXE="$MELD_ROOT/Meld.exe"
#
# WINMERGE TOOL INFO
#
WINMERGE_ROOT=""
WINMERGE_EXE=""
[ -a "/c/Progra~2/WinMerge" ] && WINMERGE_ROOT="/c/Progra~2/WinMerge"
[ -a "/c/Progra~1/WinMerge" ] && WINMERGE_ROOT="/c/Progra~1/WinMerge"
[ -z "$WINMERGE_ROOT" ] || WINMERGE_EXE="$WINMERGE_ROOT/WinMergeU.exe"
# =================================================================================================
#
#
# I N T E R N A L C O N F / D I F F / E D I T
#
#
# =================================================================================================
echo "Configure internal diff/merge tools..."
DIFFAPP_CMDLINE=""
#
# $BASE set to the name of a temporary file containing the common base for the merge, if available;
# $LOCAL set to the name of a temporary file containing the contents of the file on the current branch;
# $REMOTE set to the name of a temporary file containing the contents of the file to be merged,
# and $MERGED
#
# NOTE: git difftool falls back to git mergetool config variables
# when the difftool equivalents have not been defined.
# (IN THEORY)
#
# SPECIFIC MELD COMMANDS
#
if [ -a "$MELD_EXE" ]; then
DIFFAPP_CMDLINE="$MELD_EXE \"\$LOCAL\" \"\$REMOTE\""
MERGEAPP_CMDLINE="$MELD_EXE \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\" --output=\"\$MERGED\""
echo Configuring specific Meld commands...
git config --global difftool.meld.cmd "$DIFFAPP_CMDLINE"
git config --global mergetool.meld.cmd "$MERGEAPP_CMDLINE"
git config --global merge.tool meld
git config --global merge.guitool meld
git config --global diff.tool meld
fi
#
# SPECIFIC WINMERGE COMMANDS
#
if [ -a "$WINMERGE_EXE" ]; then
DIFFAPP_CMDLINE="$WINMERGE_EXE \"\$LOCAL\" \"\$REMOTE\""
MERGEAPP_CMDLINE="$WINMERGE_EXE \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\" --output=\"\$MERGED\""
#MERGEAPP_CMDLINE="$WINMERGE_EXE \"\$PWD/$REMOTE\" \"\$PWD/\$BASE\" \"\$PWD/\$LOCAL\" --output=\"\$PWD/\$MERGED\""
echo Configuring specific WinMerge commands...
git config --global difftool.winmerge.cmd "$DIFFAPP_CMDLINE"
git config --global mergetool.winmerge.cmd "$MERGEAPP_CMDLINE"
git config --global merge.tool winmerge
git config --global merge.guitool winmerge
git config --global diff.tool winmerge
git config --global diff.guitool winmerge
fi
#
# PLACEHOLDER COMMANDS
#
# "\"\${DEFAULT_FILE_COMPARISON_PROGRAM//\\\\\\\\//}\" \"\$LOCAL\" \"\$REMOTE\""
#
if [ -a "$DIFFAPP_CMDLINE" ]; then
echo Configuring generic WinDiff-style commands...
git config --global mergetool.windiff.cmd "$DIFFAPP_CMDLINE"
git config --global diff.tool windiff
git config --global diff.guitool windiff
fi
# By default, Git uses whatever you've set as your default text editor or
# else falls back to the Vi editor to create and edit your commit and tag
# messages. To change that default to something else, you can use the
# core.editor setting:
#
# git config --global core.editor emacs
#
# =================================================================================================
#
#
# M I S C ( T O P - L E V E L ) R U N T O O L S
#
TOOL_CATEGORY=""
# =================================================================================================
echo "Configure default editing capabilities..."
EDIT_IN_NOP_CMD="FAKECMD FAKEPARAM"
EDIT_IN_NOP_TXT="FAKETEXT1 FAKETEXT2"
EDIT_IN_NOP_TEST=false
EDIT_IN_NPP_CMD="$NPP_PATH_x \"\$FILENAME\""
EDIT_IN_NPP_TXT="Edit in Notepad++"
EDIT_IN_NPP_TEST="[ -a $NPP_PATH_x ]"
EDIT_IN_SCITE_CMD="\"$AU3ROOT_NIX/SciTE/SciTE.exe\" \"\$FILENAME\""
EDIT_IN_SCITE_TXT="Edit in SciTE"
EDIT_IN_SCITE_TEST="[ -f $AU3ROOT_NIX/SciTE/SciTE.exe ]"
$EDIT_IN_NOP_TEST && ONE_FILE_APP_SET "$TOOL_CATEGORY" "$EDIT_IN_NOP_TXT" "$EDIT_IN_NOP_CMD"
$EDIT_IN_NPP_TEST && ONE_FILE_APP_SET "$TOOL_CATEGORY" "$EDIT_IN_NPP_TXT" "$EDIT_IN_NPP_CMD"
$EDIT_IN_SCITE_TEST && ONE_FILE_APP_SET "$TOOL_CATEGORY" "$EDIT_IN_SCITE_TXT" "$EDIT_IN_SCITE_CMD"
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Explore Parent" "explorer \"\${FILENAME////\\\\\\\\}\\..\""
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Move to Recycle Bin" "recycle \"\$FILENAME\""
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git" "cd \"\$FILENAME\";git gui"
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-Blame" "git gui blame \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-DiffTool --no-prompt" "git difftool --no-prompt \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-MergeTool --no-prompt" "git mergetool --no-prompt \"\$FILENAME\""
# =================================================================================================
#
#
# C L I P B O A R D C A P A B I L I T I E S
#
TOOL_CATEGORY=".. File/Clip"
# =================================================================================================
echo "Configure $TOOL_CATEGORY capabilities..."
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Unix path" "echo \"\$FILENAME\" | clip"
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Unix path, Absolute" "echo \"\$PWD/\$FILENAME\" | clip"
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Windows path" "echo \"\${FILENAME////\\\\\\\\}\" | clip"
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Windows path, Absolute" "echo \"\${PWD////\\\\\\\\}\\\\\\\\\${FILENAME////\\\\\\\\}\" | clip"
# =================================================================================================
#
#
# M O R E E X T E R N A L T O O L S ( B I S )
#
TOOL_CATEGORY=".. File/Delete"
# =================================================================================================
echo "Configure $TOOL_CATEGORY capabilities..."
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Move to Recycle Bin" "recycle \"\$FILENAME\""
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Move Parent to Recycle Bin" "recycle \"\$FILENAME/..\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "WARNING/Delete" "rm \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "WARNING/WARNING/Recursive Delete" "rm -r \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "WARNING/WARNING/Recursive Parent Delete" "rm -r \"\$FILENAME/..\""
#$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "WARNING/Shred-Delete" "shred \"\$FILENAME\""
# =================================================================================================
#
#
# S H E L L C A P A B I L I T I E S
#
TOOL_CATEGORY=".. File/Execute"
# =================================================================================================
echo "Configure $TOOL_CATEGORY capabilities..."
[ -f "$AU3ROOT_NIX/AutoIt3.exe" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through AutoIt3 Shell" "\"$AU3ROOT_NIX/AutoIt3.exe\" \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Bash Shell" "\"\$FILENAME\""
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through MsDos Shell" "\"/c/Windows/system32/cmd.exe /c \"\$FILENAME\""
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Use Default ShellRun" "\"start \"\$FILENAME\""
# =================================================================================================
#
#
# M O R E E X T E R N A L T O O L S ( B I S )
#
TOOL_CATEGORY=".... Edit"
# =================================================================================================
echo "Configure $TOOL_CATEGORY capabilities..."
EMACS_PATH_n=/c/Progra~n/Emacs/bin/emacs.exe
EMACS_PATH_u=/c/Progra~n/Emacs/emacs.bat
EMACS_PATH_w=/c/Progra~n/NirCmd-for-Emacs/emacs.bat
EMACS_PATH_x=""
[ -a "$EMACS_PATH_n" ] && EMACS_PATH_x=$EMACS_PATH_n
[ -a "$EMACS_PATH_u" ] && EMACS_PATH_x=$EMACS_PATH_u
[ -a "$EMACS_PATH_w" ] && EMACS_PATH_x=$EMACS_PATH_w
EMACS_PATH_u=/c/Progra~n/Emacs/dired.bat
EMACS_PATH_w=/c/Progra~n/NirCmd-for-Emacs/dired.bat
DIRED_PATH_x=""
[ -a "$DIRED_PATH_u" ] && DIRED_PATH_x=$DIRED_PATH_u
[ -a "$DIRED_PATH_w" ] && DIRED_PATH_x=$DIRED_PATH_w
# RECOMMENDED
$EDIT_IN_NOP_TEST && ONE_FILE_APP_SET "$TOOL_CATEGORY" "$EDIT_IN_NOP_TXT" "$EDIT_IN_NOP_CMD"
$EDIT_IN_NPP_TEST && ONE_FILE_APP_SET "$TOOL_CATEGORY" "$EDIT_IN_NPP_TXT" "$EDIT_IN_NPP_CMD"
$EDIT_IN_SCITE_TEST && ONE_FILE_APP_SET "$TOOL_CATEGORY" "$EDIT_IN_SCITE_TXT" "$EDIT_IN_SCITE_CMD"
# OPTIONAL
[ -a "$EMACS_PATH_x" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Edit in Emacs" "$EMACS_PATH_x \"\$FILENAME\""
[ -a "$EMACS_PATH_x" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" ".. Parent/Edit Parent in Emacs" "$EMACS_PATH_x \"\$FILENAME/..\""
[ -a "$DIRED_PATH_x" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" ".. Parent/Edit Parent in Dired" "$DIRED_PATH_x \"\$FILENAME/..\""
# =================================================================================================
#
#
# M O R E E X T E R N A L T O O L S ( T E R )
#
TOOL_CATEGORY="...... Submodule"
#
# =================================================================================================
echo "Configure $TOOL_CATEGORY capabilities..."
$WIN_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Explore" "explorer \"\${FILENAME////\\\\\\\\}\""
# TODO: find the right command for _This_ -- use %GITROOT% ?
# ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-Bash" "cd \"\$FILENAME\";git gui"
[ -a "$MELD_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Meld" "$MELD_EXE \"\$FILENAME\""
# =================================================================================================
#
#
# M O R E E X T E R N A L T O O L S ( M A I N )
#
TOOL_CATEGORY="........ Version Control"
# =================================================================================================
echo "Configure $TOOL_CATEGORY capabilities..."
# BUILT-IN
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-Blame" "git gui blame \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-DiffTool --no-prompt" "git difftool --no-prompt \"\$FILENAME\""
$GIT_BUILTIN_ALWAYS_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "Run through Git-MergeTool --no-prompt" "git mergetool --no-prompt \"\$FILENAME\""
# OPTIONAL MELD
[ -a "$MELD_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "... Meld/Run through Meld" "$MELD_EXE \"\$FILENAME\""
[ -a "$MELD_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "... Meld/.. Parent/Run Parent through Meld" "$MELD_EXE \"\$FILENAME/..\""
[ -a "$WINMERGE_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "... Meld/Run through Meld as Git-DiffTool --no-prompt" "git difftool --tool meld --no-prompt \"\$FILENAME\""
[ -a "$WINMERGE_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "... Meld/.. Parent/Run Parent through Meld as Git-DiffTool --no-prompt" "git difftool --tool meld --no-prompt \"\$FILENAME/..\""
# OPTIONAL WINMERGE
[ -a "$WINMERGE_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "... WinMerge/Run through WinMerge as Git-DiffTool --no-prompt" "git difftool --tool winmerge --no-prompt \"\$FILENAME\""
[ -a "$WINMERGE_EXE" ] && ONE_FILE_APP_SET "$TOOL_CATEGORY" "... WinMerge/Run Parent through WinMerge as Git-DiffTool --no-prompt" "git difftool --tool winmerge --no-prompt \"\$FILENAME/..\""
# =================================================================================================
#
# S O U R C E M A N A G E M E N T
#
# - f o r -
#
# C U S T O M S C A F F O L D I N G
#
##### ##### ##### TOOL_CATEGORY=".......... Coded Automation"
# =================================================================================================
##### ##### ##### echo "Configure $TOOL_CATEGORY capabilities..."
# CUSTOM
# $MANDATORY_SUPPOSED_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "AutoIt3 SyntaxCheck" "/c/Progra~n/AutoIt3/Extras/AutoTesting.Setup/Setup.Sub/Setup.Packages/ccf/Au3Bin.cpy/_SyntaxCheck_A1.exe \"\$FILENAME\""
# $MANDATORY_SUPPOSED_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "AutoIt3 SyntaxCheck Parent" "/c/Progra~n/AutoIt3/Extras/AutoTesting.Setup/Setup.Sub/Setup.Packages/ccf/Au3Bin.cpy/_SyntaxCheck_A1.exe \"\$FILENAME/..\""
# $MANDATORY_SUPPOSED_TRUE && ONE_FILE_APP_SET "$TOOL_CATEGORY" "AutoIt3 SyntaxCheck Working Copy" "/c/Progra~n/AutoIt3/Extras/AutoTesting.Setup/Setup.Sub/Setup.Packages/ccf/Au3Bin.cpy/_SyntaxCheck_A1.exe \"\$PWD\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.