git-gui: allow opening currently selected file in default app
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ó <zoli.szabo@gmail.com> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
Zoli Szabó committed
Dec 30, 2019 at 15:56 UTC
786f4d24057b13184aaff8a5fa2d82a9c0180783
1 file changed
+24
-5
git-gui.sh
+24
-5
@@ -2248,9 +2248,8 @@ proc do_git_gui {} {
2248
}
2249
}
2250
2251
-proc do_explore {} {
2252
- global _gitworktree
2253
- set explorer {}
2251
+# Get the system-specific explorer app/command.
2252
+proc get_explorer {} {
2253
if {[is_Cygwin] || [is_Windows]} {
2254
set explorer "explorer.exe"
2255
} elseif {[is_MacOSX]} {
@@ -2259,9 +2258,23 @@ proc do_explore {} {
2258
# freedesktop.org-conforming system is our best shot
2259
set explorer "xdg-open"
2260
}
2261
+ return $explorer
2262
+}
2263
+
2264
+proc do_explore {} {
2265
+ global _gitworktree
2266
+ set explorer [get_explorer]
2267
eval exec $explorer [list [file nativename $_gitworktree]] &
2268
}
2269
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
+ exec $explorer [file nativename $full_file_path] &
2276
+}
2277
+
2278
set is_quitting 0
2279
set ret_code 1
2280
@@ -3513,9 +3526,11 @@ tlabel .vpane.lower.diff.header.file \
3526
-justify left
3527
tlabel .vpane.lower.diff.header.path \
3528
-background gold \
3516
- -foreground black \
3529
+ -foreground blue \
3530
-anchor w \
3518
- -justify left
3531
+ -justify left \
3532
+ -font [eval font create [font configure font_ui] -underline 1] \
3533
+ -cursor hand2
3534
pack .vpane.lower.diff.header.status -side left
3535
pack .vpane.lower.diff.header.file -side left
3536
pack .vpane.lower.diff.header.path -fill x
@@ -3530,8 +3545,12 @@ $ctxm add command \
3545
-type STRING \
3546
-- $current_diff_path
3547
}
3548
+$ctxm add command \
3549
+ -label [mc Open] \
3550
+ -command {do_file_open $current_diff_path}
3551
lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3552
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}
3554
3555
# -- Diff Body
3556
#