Skip to content

Commit cb81cae

Browse files
committed
[guitool] feature to specify keyboard shortcuts for custom tools
This feature will add following introduce following optional configuration key into gitconfig guitool.<name>.gitgui-shortcut Specifies a keyboard shortcut for the custom tool in the git-gui application. The value must be a valid string ( without "<" , ">" wrapper ) understood by the TCL/TK 's bind command.See https://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm for more details about the supported values. Avoid creating shortcuts that conflict with existing built-in `git gui` shortcuts. Example: [guitool "Terminal"] cmd = gnome-terminal -e zsh noconsole = yes gitgui-shortcut = "Control-y" [guitool "Sync"] cmd = "git pull; git push" gitgui-shortcut = "Alt-s" Signed-off-by: Harish.K <[email protected]>
1 parent 69fdb92 commit cb81cae

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/tools.tcl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ proc tools_create_item {parent args} {
3838
}
3939

4040
proc tools_populate_one {fullname} {
41-
global tools_menubar tools_menutbl tools_id
41+
global tools_menubar tools_menutbl tools_id repo_config
4242

4343
if {![info exists tools_id]} {
4444
set tools_id 0
@@ -61,9 +61,25 @@ proc tools_populate_one {fullname} {
6161
}
6262
}
6363

64-
tools_create_item $parent command \
65-
-label [lindex $names end] \
66-
-command [list tools_exec $fullname]
64+
set accel_key_bound 0
65+
if {[info exists repo_config(guitool.$fullname.gitgui-shortcut)]} {
66+
set accel_key $repo_config(guitool.$fullname.gitgui-shortcut)
67+
if { [ catch { bind . <$accel_key> [list tools_exec $fullname] } msg ] } {
68+
puts stderr "Failed to bind keyboard shortcut '$accel_key' for custom tool '$fullname'. Error: $msg"
69+
} else {
70+
tools_create_item $parent command \
71+
-label [lindex $names end] \
72+
-command [list tools_exec $fullname] \
73+
-accelerator $accel_key
74+
set accel_key_bound true
75+
}
76+
}
77+
78+
if { ! $accel_key_bound } {
79+
tools_create_item $parent command \
80+
-label [lindex $names end] \
81+
-command [list tools_exec $fullname]
82+
}
6783
}
6884

6985
proc tools_exec {fullname} {

0 commit comments

Comments
 (0)