From 5e6be9fab896f2b8c783ce7a06a27689741a501b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zoli=20Szab=C3=B3?= Date: Thu, 26 Dec 2019 19:13:25 +0200 Subject: [PATCH] git-gui: allow opening currently selected file in default app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many times there's the need to quickly open a source file (the one you're looking at in Git GUI) in the predefined text editor / IDE. Of course, the file can be searched for in your preferred file manager or directly in the text editor, but having the option to directly open the current file from Git GUI would be just faster. This change enables just that by: - clicking the diff header path (which is now highlighted as a hyperlink) - or diff header path context menu -> Open. Note: executable files will be run and not opened for editing. Signed-off-by: Zoli Szabó --- git-gui.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index c1be733e3ef75e..7317dc96f1bd55 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2248,9 +2248,8 @@ proc do_git_gui {} { } } -proc do_explore {} { - global _gitworktree - set explorer {} +# Get the system-specific explorer app/command. +proc get_explorer {} { if {[is_Cygwin] || [is_Windows]} { set explorer "explorer.exe" } elseif {[is_MacOSX]} { @@ -2259,7 +2258,21 @@ proc do_explore {} { # freedesktop.org-conforming system is our best shot set explorer "xdg-open" } - eval exec $explorer [list [file nativename $_gitworktree]] & + return $explorer +} + +proc do_explore {} { + global _gitworktree + set explorer [get_explorer] + exec $explorer [file nativename $_gitworktree] & +} + +# Open file relative to the working tree by the default associated app. +proc do_file_open {file} { + global _gitworktree + set explorer [get_explorer] + set full_file_path [file join $_gitworktree $file] + exec $explorer [file nativename $full_file_path] & } set is_quitting 0 @@ -3513,9 +3526,11 @@ tlabel .vpane.lower.diff.header.file \ -justify left tlabel .vpane.lower.diff.header.path \ -background gold \ - -foreground black \ + -foreground blue \ -anchor w \ - -justify left + -justify left \ + -font [eval font create [font configure font_ui] -underline 1] \ + -cursor hand2 pack .vpane.lower.diff.header.status -side left pack .vpane.lower.diff.header.file -side left pack .vpane.lower.diff.header.path -fill x @@ -3530,8 +3545,12 @@ $ctxm add command \ -type STRING \ -- $current_diff_path } +$ctxm add command \ + -label [mc Open] \ + -command {do_file_open $current_diff_path} lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y" +bind .vpane.lower.diff.header.path {do_file_open $current_diff_path} # -- Diff Body #