git-mergetool: Make default smarter by considering user's desktop environment and editor
PATCH 1/1 git-mergetool: Make default smarter by considering user's desktop environment and editor
Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE. When considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the user might prefer.
---
Arguably, kdiff3 should now move down next to meld, below the other non-graphical tools, so that if the user doesn't run KDE or GNOME they get a non-KDE, non-GNOME tool. This patch doesn't do that, though.
git-mergetool.sh | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
git-mergetool.sh +13 -1
@@ -304,7 +304,13 @@ if test -z "$merge_tool"; then fi if test -z "$merge_tool" ; then - if type kdiff3 >/dev/null 2>&1 && test -n "$DISPLAY"; then + # Try tools that match the user's desktop environment + if test x"$KDE_FULL_SESSION" = x"true" && type kdiff3 >/dev/null 2>&1 && test -n "$DISPLAY"; then + merge_tool="kdiff3"; + elif test x"$GNOME_DESKTOP_SESSION_ID" != x"" && type meld >/dev/null 2>&1 && test -n "$DISPLAY"; then + merge_tool=meld + # Try any graphical tool + elif type kdiff3 >/dev/null 2>&1 && test -n "$DISPLAY"; then merge_tool="kdiff3"; elif type tkdiff >/dev/null 2>&1 && test -n "$DISPLAY"; then merge_tool=tkdiff
@@ -312,6 +318,12 @@ if test -z "$merge_tool" ; then merge_tool=xxdiff elif type meld >/dev/null 2>&1 && test -n "$DISPLAY"; then merge_tool=meld + # Try tools specific to the user's editor + elif echo "${VISUAL:-$EDITOR}" | grep '^emacs' > /dev/null 2>&1 && type emacs >/dev/null 2>&1; then + merge_tool=emerge + elif echo "${VISUAL:-$EDITOR}" | grep '^vim' > /dev/null 2>&1 && type vimdiff >/dev/null 2>&1; then + merge_tool=vimdiff + # Try other tools elif type opendiff >/dev/null 2>&1; then merge_tool=opendiff elif type emacs >/dev/null 2>&1; then
Signature · 1 line
1.5.2.1
Quoted 5 lines · Josh Triplett
Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE. When considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the user might prefer.
Signed-off-by Josh Triplett <[email protected]>
The basic idea is sound. However...
(1) I wonder if we can get rid of the horribly long if .. elif
chain by using shell function and then iterate a list of them;
(2) echo "${VISUAL-$EDITOR}" | grep '^emacs'???
Some people may have explicit path (/home/me/bin/emacs), and/or runs a variant of emacs called 'xemacs'. Same for vim.
Something like...
test_xstuff () {
test -n "$DISPLAY" && type "$1" >/dev/null 2>&1
test_kdiff3 () {
test_xstuff kdiff3
}
test_tkdiff () {
test_xstuff tkdiff
}
test_estuff() {
type "$1" >/dev/null 2>&1 &&
case "${VISUAL-$EDITOR}" in *"$1"*) : ;; *) false ;; esac
}
test_emerge () {
test_estuff emacs
}
test_vimdiff () {
test_estuff vim
}
choose_merge_tool () {
for t in "$@"
do
if test_$t
then
echo "$t"
break
fi
done
}
if test -z "$merge_tool"
then
merge_tool_candidates='kdiff3 tkdiff xxdiff meld opendiff ...'
if test -n "$GNOME_DESCTOP_SESSION_ID"
then
merge_tool_candidates="meld $merge_tool_candidates"
elif test -n "$KDE_FULL_SESSION"
then
merge_tool_candidates="kdiff3 $merge_tool_candidates"
elif
...
fi
merge_tool=$(choose_merge_tool $merge_tool_candidates)
fiQuoted 10 lines · Junio C Hamano
Quoted 5 lines · Josh Triplett
Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE. When considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the user might prefer.
Signed-off-by Josh Triplett <[email protected]>The basic idea is sound. However...
Quoted 8 lines
(1) I wonder if we can get rid of the horribly long if .. elif
chain by using shell function and then iterate a list of them;(2) echo "${VISUAL-$EDITOR}" | grep '^emacs'???
Some people may have explicit path (
/home/me/bin/emacs), and/or runs a variant of emacs called 'xemacs'. Same for vim.
Actually, a lot of people run as editor a program called "emacsclient" or "gnuclient": this one connects to an existing Emacs session and passes its arguments to it. And of course, this is what git-mergetool should then also do.
Signature · 1 line
David Kastrup
Quoted 17 lines · David Kastrup
Quoted 15 lines · Junio C Hamano
Quoted 5 lines · Josh Triplett
Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE. When considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the user might prefer.
Signed-off-by Josh Triplett <[email protected]>The basic idea is sound. However...
(1) I wonder if we can get rid of the horribly long if .. elif
chain by using shell function and then iterate a list of them;(2) echo "${VISUAL-$EDITOR}" | grep '^emacs'???
Quoted 8 lines
Quoted 3 lines
Some people may have explicit path (
/home/me/bin/emacs), and/or runs a variant of emacs called 'xemacs'. Same for vim.Actually, a lot of people run as editor a program called "emacsclient" or "gnuclient": this one connects to an existing Emacs session and passes its arguments to it. And of course, this is what git-mergetool should then also do.
I do that too, but that is covered by the prefix rule Josh has, so it is Ok.
Quoted 23 lines · Junio C Hamano
Quoted 21 lines · David Kastrup
Quoted 18 lines · Junio C Hamano
Quoted 5 lines · Josh Triplett
Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE. When considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the user might prefer.
Signed-off-by Josh Triplett <[email protected]>The basic idea is sound. However...
(1) I wonder if we can get rid of the horribly long if .. elif
chain by using shell function and then iterate a list of them;(2) echo "${VISUAL-$EDITOR}" | grep '^emacs'???
Some people may have explicit path (
/home/me/bin/emacs), and/or runs a variant of emacs called 'xemacs'. Same for vim.
Quoted 7 lines
Quoted 4 lines
Actually, a lot of people run as editor a program called "emacsclient" or "gnuclient": this one connects to an existing Emacs session and passes its arguments to it. And of course, this is what git-mergetool should then also do.
I do that too, but that is covered by the prefix rule Josh has, so it is Ok.
Another note: in my usual Emacs session, EDITOR is set to /usr/local/emacs-22/bin/emacsclient
which would not be covered... So that should probably be
useemacs=0
for i in ${VISUAL-$EDITOR}
do
case "`basename $i`" in [xX][eE]macs*|[eE]macs*|gnuclient*)
useemacs=1
esac
breakdone
This should work even when we are talking about something like EDITOR="C:\My Programs\XEmacs\gnuclient.exe" -n "C:\My Programs\XEmacs\XEmacs"
And it does not require starting grep for something which the shell can perfectly well handle on its own. Yes, it does need basename. I don't see a good way to avoid that.
Signature · 1 line
David Kastrup
This is what I've been experimenting in my tree; what do people think?
if test -z "$merge_tool" ; then
if test -n "$DISPLAY"; then
merge_tool_candidates="kdiff3 tkdiff xxdiff meld gvimdiff" if test "$GNOME_DESKTOP_SESSION_ID"x != ""x; then
merge_tool_candidates="meld $merge_tool_candidates"
fi
if test "$KDE_FULL_SESSION"x = "true"x; then
merge_tool_candidates="kdiff3 $merge_tool_candidates"
fi
fi
if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then
merge_tool_candidates="$merge_tool_candidates emerge"
fi
if echo "${VISUAL:-$EDITOR}" | grep 'vim' > /dev/null 2>&1; then
merge_tool_candidates="$merge_tool_candidates vimdiff"
fi
merge_tool_candidates="$merge_tool_candidates opendiff emerge vimdiff" echo "merge tool candidates: $merge_tool_candidates"
for i in $merge_tool_candidates; do
if test $i = emerge ; then
cmd=emacs
else
cmd=$i
fi
if type $cmd > /dev/null 2>&1; then
echo merge_tool chosen is $i
merge_tool=$i
break
fi
done
fi
- Ted