{"thread":{"id":"8461","subject":"[PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","startedAt":"2007-06-06T04:28:18Z","lastAt":"2007-06-06T21:20:31Z","messageCount":6,"participants":["Josh Triplett","Junio C Hamano","David Kastrup","Theodore Tso"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"44118","messageId":"466637E2.5040303@freedesktop.org","threadId":"8461","inReplyTo":null,"subject":"[PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","fromName":"Josh Triplett","fromEmail":"josh@freedesktop.org","sentAt":"2007-06-06T04:28:18Z","receivedAt":"2007-06-06T04:28:18Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE.  When\nconsidering emerge and vimdiff, check $VISUAL and $EDITOR to see which the\nuser might prefer.\n\nSigned-off-by: Josh Triplett <josh@freedesktop.org>\n---\n\nArguably, kdiff3 should now move down next to meld, below the other\nnon-graphical tools, so that if the user doesn't run KDE or GNOME they get a\nnon-KDE, non-GNOME tool.  This patch doesn't do that, though.\n\n git-mergetool.sh |   14 +++++++++++++-\n 1 files changed, 13 insertions(+), 1 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex bb21b03..2053d43 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -304,7 +304,13 @@ if test -z \"$merge_tool\"; then\n fi\n \n if test -z \"$merge_tool\" ; then\n-    if type kdiff3 >/dev/null 2>&1 && test -n \"$DISPLAY\"; then\n+    # Try tools that match the user's desktop environment\n+    if test x\"$KDE_FULL_SESSION\" = x\"true\" && type kdiff3 >/dev/null 2>&1 && test -n \"$DISPLAY\"; then\n+        merge_tool=\"kdiff3\";\n+    elif test x\"$GNOME_DESKTOP_SESSION_ID\" != x\"\" && type meld >/dev/null 2>&1 && test -n \"$DISPLAY\"; then\n+        merge_tool=meld\n+    # Try any graphical tool\n+    elif type kdiff3 >/dev/null 2>&1 && test -n \"$DISPLAY\"; then\n \tmerge_tool=\"kdiff3\";\n     elif type tkdiff >/dev/null 2>&1 && test -n \"$DISPLAY\"; then\n \tmerge_tool=tkdiff\n@@ -312,6 +318,12 @@ if test -z \"$merge_tool\" ; then\n \tmerge_tool=xxdiff\n     elif type meld >/dev/null 2>&1 && test -n \"$DISPLAY\"; then\n \tmerge_tool=meld\n+    # Try tools specific to the user's editor\n+    elif echo \"${VISUAL:-$EDITOR}\" | grep '^emacs' > /dev/null 2>&1 && type emacs >/dev/null 2>&1; then\n+\tmerge_tool=emerge\n+    elif echo \"${VISUAL:-$EDITOR}\" | grep '^vim' > /dev/null 2>&1 && type vimdiff >/dev/null 2>&1; then\n+\tmerge_tool=vimdiff\n+    # Try other tools\n     elif type opendiff >/dev/null 2>&1; then\n \tmerge_tool=opendiff\n     elif type emacs >/dev/null 2>&1; then\n-- \n1.5.2.1\n\n\n"},{"id":"44135","messageId":"7vabvd7bfg.fsf@assigned-by-dhcp.cox.net","threadId":"8461","inReplyTo":"466637E2.5040303@freedesktop.org","subject":"Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-06-06T08:08:03Z","receivedAt":"2007-06-06T08:08:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josh Triplett <josh@freedesktop.org> writes:\n\n> Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE.  When\n> considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the\n> user might prefer.\n>\n> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n\nThe basic idea is sound.  However...\n\n (1) I wonder if we can get rid of the horribly long if .. elif\n     chain by using shell function and then iterate a list of them;\n\n (2) echo \"${VISUAL-$EDITOR}\" | grep '^emacs'???\n\n     Some people may have explicit path (/home/me/bin/emacs),\n     and/or runs a variant of emacs called 'xemacs'.  Same for\n     vim.\n\nSomething like...\n\n        test_xstuff () {\n                test -n \"$DISPLAY\" && type \"$1\" >/dev/null 2>&1\n        test_kdiff3 () {\n                test_xstuff kdiff3\n        }\n        test_tkdiff () {\n                test_xstuff tkdiff\n        }\n        test_estuff() {\n                type \"$1\" >/dev/null 2>&1 &&\n                case \"${VISUAL-$EDITOR}\" in *\"$1\"*) : ;; *) false ;; esac\n        }\n        test_emerge () {\n                test_estuff emacs\n        }\n        test_vimdiff () {\n                test_estuff vim\n        }\n\n        choose_merge_tool () {\n                for t in \"$@\"\n                do\n                        if test_$t\n                        then\n                                echo \"$t\"\n                                break\n                        fi\n                done\n        }\n\n        if test -z \"$merge_tool\"\n        then\n                merge_tool_candidates='kdiff3 tkdiff xxdiff meld opendiff ...'\n                if test -n \"$GNOME_DESCTOP_SESSION_ID\"\n                then\n                        merge_tool_candidates=\"meld $merge_tool_candidates\"\n                elif test -n \"$KDE_FULL_SESSION\"\n                then\n                        merge_tool_candidates=\"kdiff3 $merge_tool_candidates\"\n                elif\n                        ...\n                fi\n                merge_tool=$(choose_merge_tool $merge_tool_candidates)\n        fi\n"},{"id":"44145","messageId":"86tztljwgk.fsf@lola.quinscape.zz","threadId":"8461","inReplyTo":"7vabvd7bfg.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-06-06T08:52:59Z","receivedAt":"2007-06-06T08:52:59Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Josh Triplett <josh@freedesktop.org> writes:\n>\n>> Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE.  When\n>> considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the\n>> user might prefer.\n>>\n>> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n>\n> The basic idea is sound.  However...\n>\n>  (1) I wonder if we can get rid of the horribly long if .. elif\n>      chain by using shell function and then iterate a list of them;\n>\n>  (2) echo \"${VISUAL-$EDITOR}\" | grep '^emacs'???\n>\n>      Some people may have explicit path (/home/me/bin/emacs),\n>      and/or runs a variant of emacs called 'xemacs'.  Same for\n>      vim.\n\nActually, a lot of people run as editor a program called \"emacsclient\"\nor \"gnuclient\": this one connects to an existing Emacs session and\npasses its arguments to it.  And of course, this is what git-mergetool\nshould then also do.\n\n-- \nDavid Kastrup\n"},{"id":"44148","messageId":"7vabvd5u7t.fsf@assigned-by-dhcp.cox.net","threadId":"8461","inReplyTo":"86tztljwgk.fsf@lola.quinscape.zz","subject":"Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-06T09:05:10Z","receivedAt":"2007-06-06T09:05:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Kastrup <dak@gnu.org> writes:\n\n> Junio C Hamano <junkio@cox.net> writes:\n>\n>> Josh Triplett <josh@freedesktop.org> writes:\n>>\n>>> Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE.  When\n>>> considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the\n>>> user might prefer.\n>>>\n>>> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n>>\n>> The basic idea is sound.  However...\n>>\n>>  (1) I wonder if we can get rid of the horribly long if .. elif\n>>      chain by using shell function and then iterate a list of them;\n>>\n>>  (2) echo \"${VISUAL-$EDITOR}\" | grep '^emacs'???\n>>\n>>      Some people may have explicit path (/home/me/bin/emacs),\n>>      and/or runs a variant of emacs called 'xemacs'.  Same for\n>>      vim.\n>\n> Actually, a lot of people run as editor a program called \"emacsclient\"\n> or \"gnuclient\": this one connects to an existing Emacs session and\n> passes its arguments to it.  And of course, this is what git-mergetool\n> should then also do.\n\nI do that too, but that is covered by the prefix rule Josh has,\nso it is Ok.\n"},{"id":"44156","messageId":"86lkexjua3.fsf@lola.quinscape.zz","threadId":"8461","inReplyTo":"7vabvd5u7t.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-06-06T09:40:04Z","receivedAt":"2007-06-06T09:40:04Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> David Kastrup <dak@gnu.org> writes:\n>\n>> Junio C Hamano <junkio@cox.net> writes:\n>>\n>>> Josh Triplett <josh@freedesktop.org> writes:\n>>>\n>>>> Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE.  When\n>>>> considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the\n>>>> user might prefer.\n>>>>\n>>>> Signed-off-by: Josh Triplett <josh@freedesktop.org>\n>>>\n>>> The basic idea is sound.  However...\n>>>\n>>>  (1) I wonder if we can get rid of the horribly long if .. elif\n>>>      chain by using shell function and then iterate a list of them;\n>>>\n>>>  (2) echo \"${VISUAL-$EDITOR}\" | grep '^emacs'???\n>>>\n>>>      Some people may have explicit path (/home/me/bin/emacs),\n>>>      and/or runs a variant of emacs called 'xemacs'.  Same for\n>>>      vim.\n>>\n>> Actually, a lot of people run as editor a program called \"emacsclient\"\n>> or \"gnuclient\": this one connects to an existing Emacs session and\n>> passes its arguments to it.  And of course, this is what git-mergetool\n>> should then also do.\n>\n> I do that too, but that is covered by the prefix rule Josh has,\n> so it is Ok.\n\nAnother note: in my usual Emacs session, EDITOR is set to\n/usr/local/emacs-22/bin/emacsclient\nwhich would not be covered...  So that should probably be\n\nuseemacs=0\nfor i in ${VISUAL-$EDITOR}\ndo\n        case \"`basename $i`\" in [xX][eE]macs*|[eE]macs*|gnuclient*)\n             useemacs=1\n        esac\n        break\ndone\n\nThis should work even when we are talking about something like\nEDITOR=\"C:\\My Programs\\XEmacs\\gnuclient.exe\" -n \"C:\\My Programs\\XEmacs\\XEmacs\"\n\nAnd it does not require starting grep for something which the shell\ncan perfectly well handle on its own.  Yes, it does need basename.  I\ndon't see a good way to avoid that.\n\n-- \nDavid Kastrup\n"},{"id":"44191","messageId":"20070606212031.GD9708@thunk.org","threadId":"8461","inReplyTo":"86lkexjua3.fsf@lola.quinscape.zz","subject":"Re: [PATCH] git-mergetool: Make default smarter by considering user's desktop environment and editor","fromName":"Theodore Tso","fromEmail":"tytso@mit.edu","sentAt":"2007-06-06T21:20:31Z","receivedAt":"2007-06-06T21:20:31Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"This is what I've been experimenting in my tree; what do people think?\n\nif test -z \"$merge_tool\" ; then\n    if test -n \"$DISPLAY\"; then\n\tmerge_tool_candidates=\"kdiff3 tkdiff xxdiff meld gvimdiff\"\n\tif test \"$GNOME_DESKTOP_SESSION_ID\"x != \"\"x; then\n\t    merge_tool_candidates=\"meld $merge_tool_candidates\"\n\tfi\n\tif test \"$KDE_FULL_SESSION\"x = \"true\"x; then\n\t    merge_tool_candidates=\"kdiff3 $merge_tool_candidates\"\n\tfi\n    fi\n    if echo \"${VISUAL:-$EDITOR}\" | grep 'emacs' > /dev/null 2>&1; then\n\tmerge_tool_candidates=\"$merge_tool_candidates emerge\"\n    fi\n    if echo \"${VISUAL:-$EDITOR}\" | grep 'vim' > /dev/null 2>&1; then\n\tmerge_tool_candidates=\"$merge_tool_candidates vimdiff\"\n    fi\n    merge_tool_candidates=\"$merge_tool_candidates opendiff emerge vimdiff\"\n    echo \"merge tool candidates: $merge_tool_candidates\"\n    for i in $merge_tool_candidates; do\n\tif test $i = emerge ; then\n\t    cmd=emacs\n\telse\n\t    cmd=$i\n\tfi\n\tif type $cmd > /dev/null 2>&1; then\n\t    echo merge_tool chosen is $i\n\t    merge_tool=$i\n\t    break\n\tfi\n    done\nfi\n\n\t\t\t\t\t\t- Ted\n"}]}