Skip to content

Commit 77e2153

Browse files
chriscoolgitster
authored andcommitted
web--browse: use custom commands defined at config time
Currently "git web--browse" is restricted to a set of commands defined in the script. You can subvert the "browser.<tool>.path" to force "git web--browse" to use a different command, but if you have a command whose invocation syntax does not match one of the current tools then you would have to write a wrapper script for it. This patch adds a git config variable "browser.<tool>.cmd" which allows a more flexible browser choice. If you run "git web--browse" with -t/--tool, -b/--browser or the "web.browser" config variable set to an unrecognized tool then "git web--browse" will query the "browser.<tool>.cmd" config variable. If this variable exists, then "git web--browse" will treat the specified tool as a custom command and will use a shell eval to run the command with the URLs added as extra parameters. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ad9db3 commit 77e2153

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

git-web--browse.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ USAGE='[--browser=browser|--tool=browser] [--config=conf.var] url/file ...'
2323
NONGIT_OK=Yes
2424
. git-sh-setup
2525

26+
valid_custom_tool()
27+
{
28+
browser_cmd="$(git config "browser.$1.cmd")"
29+
test -n "$browser_cmd"
30+
}
31+
2632
valid_tool() {
2733
case "$1" in
2834
firefox | iceweasel | konqueror | w3m | links | lynx | dillo | open)
2935
;; # happy
3036
*)
31-
return 1
37+
valid_custom_tool "$1" || return 1
3238
;;
3339
esac
3440
}
@@ -122,7 +128,7 @@ else
122128

123129
init_browser_path "$browser"
124130

125-
if ! type "$browser_path" > /dev/null 2>&1; then
131+
if test -z "$browser_cmd" && ! type "$browser_path" > /dev/null 2>&1; then
126132
die "The browser $browser is not available as '$browser_path'."
127133
fi
128134
fi
@@ -157,4 +163,9 @@ case "$browser" in
157163
dillo)
158164
"$browser_path" "$@" &
159165
;;
166+
*)
167+
if test -n "$browser_cmd"; then
168+
( eval $browser_cmd "$@" )
169+
fi
170+
;;
160171
esac

0 commit comments

Comments
 (0)