Skip to content

Commit

Permalink
Fix web--browse
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdrive committed Sep 11, 2021
1 parent 86ff187 commit 1c3535f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 42 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ USAGE
* [-o|--refs-mode] [r|l|lr] # Specify url ref hash mode. r or l or lr or rl(default: l)
* [-v|--verbose] # Verbose mode.
* [-s|--simple] # Simple output mode.
* [-b|--browser] # open create url to GIT_GH_DIFF_URL_BROWSER cmd.
* [-b|--browser] # open create url to `git web--browse` cmd.
* [-p|--browser-option] [OPTION] # Specify `git web--browse` option.
* [-t|--output] [text|html|markdown] # Specify output text type. (default: markdown)
```

ENVIRONMENTS
----
```
GIT_GH_DIFF_URL_BROWSER_DARWIN # Browser command to be used if you are on MacOSX. (default: use chrome)
GIT_GH_DIFF_URL_BROWSER_LINUX # Browser command to be used if you are on Linux. (default: use chrome)
GIT_GH_DIFF_URL_BROWSER # Highest priority browser command.
GIT_GH_DIFF_URL_DEFAULT_BROWSER_OPTION # Default use `--browser-option` option. (default: "")
GIT_GH_DIFF_URL_DEFAULT_REFS_MODE # Default use `--refs-mode` option. (default: "l")
GIT_GH_DIFF_URL_DEFAULT_OUTPUT_TEXT_TYPE # Default use `--output` option. (default: "markdown")
```
Expand Down
52 changes: 17 additions & 35 deletions git-gh-diff-url
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
# * [-o|--refs-mode] [r|l|lr] # Specify url ref hash mode. r or l or lr or rl(default: l)
# * [-v|--verbose] # Verbose mode on.
# * [-s|--simple] # Simple mode on.
# * [-b|--browser] # open create url to GIT_GH_DIFF_URL_BROWSER cmd.
# * [-b|--browser] # open create url to `git web--browse` cmd.
# * [-p|--browser-option] [OPTION] # Specify `git web--browse` option.
# * [-t|--output] [text|html|markdown] # Specify output text type. (default: markdown)
#
# ENVIRONMENTS:
# GIT_GH_DIFF_URL_BROWSER_DARWIN # Browser command to be used if you are on MacOSX. (default: use chrome)
# GIT_GH_DIFF_URL_BROWSER_LINUX # Browser command to be used if you are on Linux. (default: use chrome)
# GIT_GH_DIFF_URL_BROWSER # Highest priority browser command.
# GIT_GH_DIFF_URL_DEFAULT_BROWSER_OPTION # Default use `--browser-option` option. (default: "")
# GIT_GH_DIFF_URL_DEFAULT_REFS_MODE # Default use `--refs-mode` option. (default: "l")
# GIT_GH_DIFF_URL_DEFAULT_OUTPUT_TEXT_TYPE # Default use `--output` option. (default: "markdown")
#
Expand Down Expand Up @@ -44,10 +43,8 @@

set -e

export GIT_GH_DIFF_URL_BROWSER_DARWIN="${GIT_GH_DIFF_URL_BROWSER_DARWIN:-"open -a '/Applications/Google Chrome.app'"}"
export GIT_GH_DIFF_URL_BROWSER_LINUX="${GIT_GH_DIFF_URL_BROWSER_LINUX:-"google-chrome"}"
export GIT_GH_DIFF_URL_BROWSER="${GIT_GH_DIFF_URL_BROWSER:-""}"
export GIT_GH_DEFAULT_REFS_MODE="${GIT_GH_DEFAULT_REFS_MODE:-"l"}"
export GIT_GH_DIFF_URL_DEFAULT_BROWSER_OPTION="${GIT_GH_DIFF_URL_DEFAULT_BROWSER_OPTION:-""}"
export GIT_GH_DIFF_URL_DEFAULT_REFS_MODE="${GIT_GH_DIFF_URL_DEFAULT_REFS_MODE:-"l"}"
export GIT_GH_DIFF_URL_DEFAULT_OUTPUT_TEXT_TYPE=${GIT_GH_DIFF_URL_DEFAULT_OUTPUT_TEXT_TYPE:-"markdown"}

git::gh:d:u::help() {
Expand All @@ -59,37 +56,15 @@ USAGE:
* [-o|--refs-mode] [r|l|lr] # Specify url ref hash mode. r or l or lr or rl(default: l)
* [-v|--verbose] # verbose mode
* [-s|--simple] # simple output mode
* [-b|--browser] # open create url to GIT_GH_DIFF_URL_BROWSER cmd.
* [-b|--browser] # open create url to \`git web--browse\` cmd.
* [-p|--browser-option] [OPTION] # Specify \`git web--browse\` option.
* [-t|--output] [text|html|markdown] # Specify output text type. (default: markdown)
HELP
}

git::gh:d:u::browser() {
local url=$1
$($(git::gh:d:u::browser_command) "${url}")
}

git::gh:d:u::browser_command() {
local browser_command

case "$(uname -s)" in
"Darwin")
browser_command="${GIT_GH_DIFF_URL_BROWSER_DARWIN}"
;;
"Linux")
browser_command="${GIT_GH_DIFF_URL_BROWSER_LINUX}"
;;
*)
echo "Unsupported platform" >&2
exit 1
;;
esac

if [[ -n ${GIT_GH_DIFF_URL_BROWSER} ]];then
browser_command="${GIT_GH_DIFF_URL_BROWSER}"
fi

echo "${browser_command}"
git web--browse "${__CONFIG_BROWSER_OPTION:-${GIT_GH_DIFF_URL_DEFAULT_BROWSER_OPTION}}" "${url}"
}

git::gh:d:u::branch_name() {
Expand Down Expand Up @@ -185,7 +160,7 @@ git::gh:d:u::main() {
_repo_url="$(git::gh:d:u::gh_repository_id)"
_left="$(git::gh:d:u::left)"
_right="$(git::gh:d:u::right)"
case "${__CONFIG_REFS_MODE:-"l"}" in
case "${__CONFIG_REFS_MODE:-"${GIT_GH_DIFF_URL_DEFAULT_REFS_MODE}"}" in
l)
_left=$(git::gh:d:u::head_hash "$left")
;;
Expand Down Expand Up @@ -226,7 +201,7 @@ git::gh:d:u::main() {



optspec=":-:r:l:o:t:vshb"
optspec=":-:r:l:o:t:p:vshb"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
Expand Down Expand Up @@ -260,6 +235,10 @@ while getopts "$optspec" optchar; do
browser)
__CONFIG_BROWSER=1
;;
browser-optoin)
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
__CONFIG_BROWSER_OPTION="${val}"
;;
output)
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
if [[ ${val} =~ ^(:?text|html|markdown)$ ]]; then
Expand Down Expand Up @@ -302,6 +281,9 @@ while getopts "$optspec" optchar; do
b)
__CONFIG_BROWSER=1
;;
t)
__CONFIG_BROWSER_OPTION="${OPTARG}"
;;
t)
if [[ ${OPTARG} =~ ^(:?text|html|markdown)$ ]]; then
GIT_GH_DIFF_URL_DEFAULT_OUTPUT_TEXT_TYPE="${OPTARG}"
Expand Down
8 changes: 5 additions & 3 deletions git-gh-diff-url.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
.PP
git\-gh\-diff\-url \- generate github refs diff url (github.com/user/repo/compare/...).

.PP


.SH USAGE
.PP
.RS
Expand All @@ -16,6 +19,7 @@ git\-gh\-diff\-url \- generate github refs diff url (github.com/user/repo/compar
* [\-v|\-\-verbose] # Verbose mode.
* [\-s|\-\-simple] # Simple output mode.
* [\-b|\-\-browser] # open create url to GIT\_GH\_DIFF\_URL\_BROWSER cmd.
* [\-p|\-\-browser\-option] [OPTION] # Specify `git web\-\-browse` option.
* [\-t|\-\-output] [text|html|markdown] # Specify output text type. (default: markdown)

.fi
Expand All @@ -26,9 +30,7 @@ git\-gh\-diff\-url \- generate github refs diff url (github.com/user/repo/compar
.RS

.nf
GIT\_GH\_DIFF\_URL\_BROWSER\_DARWIN # Browser command to be used if you are on MacOSX. (default: use chrome)
GIT\_GH\_DIFF\_URL\_BROWSER\_LINUX # Browser command to be used if you are on Linux. (default: use chrome)
GIT\_GH\_DIFF\_URL\_BROWSER # Highest priority browser command.
GIT\_GH\_DIFF\_URL\_DEFAULT\_BROWSER\_OPTION # Default use `\-\-browser\-option` option. (default: "")
GIT\_GH\_DIFF\_URL\_DEFAULT\_REFS\_MODE # Default use `\-\-refs\-mode` option. (default: "l")
GIT\_GH\_DIFF\_URL\_DEFAULT\_OUTPUT\_TEXT\_TYPE # Default use `\-\-output` option. (default: "markdown")

Expand Down

0 comments on commit 1c3535f

Please sign in to comment.