Skip to content

Commit a6fde25

Browse files
committed
git-gui: allow opening currently selected file
...in the default associated app (e.g. in a text editor / IDE). 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ó <[email protected]>
1 parent 23cbe42 commit a6fde25

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

git-gui.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,9 +2248,8 @@ proc do_git_gui {} {
22482248
}
22492249
}
22502250
2251-
proc do_explore {} {
2252-
global _gitworktree
2253-
set explorer {}
2251+
# Get the system-specific explorer app/command.
2252+
proc get_explorer {} {
22542253
if {[is_Cygwin] || [is_Windows]} {
22552254
set explorer "explorer.exe"
22562255
} elseif {[is_MacOSX]} {
@@ -2259,9 +2258,23 @@ proc do_explore {} {
22592258
# freedesktop.org-conforming system is our best shot
22602259
set explorer "xdg-open"
22612260
}
2261+
return $explorer
2262+
}
2263+
2264+
proc do_explore {} {
2265+
global _gitworktree
2266+
set explorer [get_explorer]
22622267
eval exec $explorer [list [file nativename $_gitworktree]] &
22632268
}
22642269
2270+
# Open file relative to the working tree by the default associated app.
2271+
proc do_file_open {file} {
2272+
global _gitworktree
2273+
set explorer [get_explorer]
2274+
set full_file_path [file join $_gitworktree $file]
2275+
eval exec $explorer [list [file nativename $full_file_path]] &
2276+
}
2277+
22652278
set is_quitting 0
22662279
set ret_code 1
22672280
@@ -3513,9 +3526,11 @@ tlabel .vpane.lower.diff.header.file \
35133526
-justify left
35143527
tlabel .vpane.lower.diff.header.path \
35153528
-background gold \
3516-
-foreground black \
3529+
-foreground blue \
35173530
-anchor w \
3518-
-justify left
3531+
-justify left \
3532+
-font [eval font create [font configure font_ui] -underline 1] \
3533+
-cursor hand2
35193534
pack .vpane.lower.diff.header.status -side left
35203535
pack .vpane.lower.diff.header.file -side left
35213536
pack .vpane.lower.diff.header.path -fill x
@@ -3530,8 +3545,12 @@ $ctxm add command \
35303545
-type STRING \
35313546
-- $current_diff_path
35323547
}
3548+
$ctxm add command \
3549+
-label [mc Open] \
3550+
-command {do_file_open $current_diff_path}
35333551
lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
35343552
bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3553+
bind .vpane.lower.diff.header.path <Button-1> {do_file_open $current_diff_path}
35353554
35363555
# -- Diff Body
35373556
#

0 commit comments

Comments
 (0)