* [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor
@ 2007-06-06 4:28 Josh Triplett
2007-06-06 8:08 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Josh Triplett @ 2007-06-06 4:28 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1985 bytes --]
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 <josh@freedesktop.org>
---
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(-)
diff --git a/git-mergetool.sh b/git-mergetool.sh
index bb21b03..2053d43 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -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
--
1.5.2.1
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor
2007-06-06 4:28 [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor Josh Triplett
@ 2007-06-06 8:08 ` Junio C Hamano
2007-06-06 8:52 ` David Kastrup
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-06-06 8:08 UTC (permalink / raw)
To: Josh Triplett; +Cc: git
Josh Triplett <josh@freedesktop.org> writes:
> 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 <josh@freedesktop.org>
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)
fi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor
2007-06-06 8:08 ` Junio C Hamano
@ 2007-06-06 8:52 ` David Kastrup
2007-06-06 9:05 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: David Kastrup @ 2007-06-06 8:52 UTC (permalink / raw)
To: git
Junio C Hamano <junkio@cox.net> writes:
> Josh Triplett <josh@freedesktop.org> writes:
>
>> 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 <josh@freedesktop.org>
>
> 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.
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.
--
David Kastrup
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor
2007-06-06 8:52 ` David Kastrup
@ 2007-06-06 9:05 ` Junio C Hamano
2007-06-06 9:40 ` David Kastrup
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-06-06 9:05 UTC (permalink / raw)
To: David Kastrup; +Cc: git
David Kastrup <dak@gnu.org> writes:
> Junio C Hamano <junkio@cox.net> writes:
>
>> Josh Triplett <josh@freedesktop.org> writes:
>>
>>> 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 <josh@freedesktop.org>
>>
>> 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.
>
> 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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor
2007-06-06 9:05 ` Junio C Hamano
@ 2007-06-06 9:40 ` David Kastrup
2007-06-06 21:20 ` Theodore Tso
0 siblings, 1 reply; 6+ messages in thread
From: David Kastrup @ 2007-06-06 9:40 UTC (permalink / raw)
To: git
Junio C Hamano <gitster@pobox.com> writes:
> David Kastrup <dak@gnu.org> writes:
>
>> Junio C Hamano <junkio@cox.net> writes:
>>
>>> Josh Triplett <josh@freedesktop.org> writes:
>>>
>>>> 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 <josh@freedesktop.org>
>>>
>>> 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.
>>
>> 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
break
done
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.
--
David Kastrup
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor
2007-06-06 9:40 ` David Kastrup
@ 2007-06-06 21:20 ` Theodore Tso
0 siblings, 0 replies; 6+ messages in thread
From: Theodore Tso @ 2007-06-06 21:20 UTC (permalink / raw)
To: David Kastrup; +Cc: git
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-06-06 21:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 4:28 [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor Josh Triplett
2007-06-06 8:08 ` Junio C Hamano
2007-06-06 8:52 ` David Kastrup
2007-06-06 9:05 ` Junio C Hamano
2007-06-06 9:40 ` David Kastrup
2007-06-06 21:20 ` Theodore Tso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).