Skip to content

Commit fce80f1

Browse files
committed
git-gui: add possibility to open 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: - Diff header path context menu -> Open; - or double-clicking the diff header path. One "downside" of the approach is that executable files will be run and not opened for editing. Signed-off-by: Zoli Szabó <[email protected]>
1 parent 23cbe42 commit fce80f1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

git-gui.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,8 +2248,8 @@ proc do_git_gui {} {
22482248
}
22492249
}
22502250
2251-
proc do_explore {} {
2252-
global _gitworktree
2251+
# Get the system-specific explorer app/command.
2252+
proc get_explorer {} {
22532253
set explorer {}
22542254
if {[is_Cygwin] || [is_Windows]} {
22552255
set explorer "explorer.exe"
@@ -2259,9 +2259,25 @@ proc do_explore {} {
22592259
# freedesktop.org-conforming system is our best shot
22602260
set explorer "xdg-open"
22612261
}
2262+
return $explorer
2263+
}
2264+
2265+
proc do_explore {} {
2266+
global _gitworktree
2267+
set explorer [get_explorer]
22622268
eval exec $explorer [list [file nativename $_gitworktree]] &
22632269
}
22642270
2271+
# Trigger opening a file (relative to the working tree) by the default
2272+
# associated app of the OS (e.g. a text editor or IDE).
2273+
# FIXME: What about executables (will be run, not opened for editing)?
2274+
proc do_file_open {file} {
2275+
global _gitworktree
2276+
set explorer [get_explorer]
2277+
set full_file_path [file join $_gitworktree $file]
2278+
eval exec $explorer [list [file nativename $full_file_path]] &
2279+
}
2280+
22652281
set is_quitting 0
22662282
set ret_code 1
22672283
@@ -3530,8 +3546,14 @@ $ctxm add command \
35303546
-type STRING \
35313547
-- $current_diff_path
35323548
}
3549+
$ctxm add command \
3550+
-label [mc Open] \
3551+
-command {
3552+
do_file_open $current_diff_path
3553+
}
35333554
lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
35343555
bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3556+
bind .vpane.lower.diff.header.path <Double-1> {do_file_open $current_diff_path}
35353557
35363558
# -- Diff Body
35373559
#

0 commit comments

Comments
 (0)