Skip to content

Commit

Permalink
Merge pull request ohmyzsh#4217 from mcornella/standard-open-command
Browse files Browse the repository at this point in the history
Implement and use a standard, cross-platform open command
  • Loading branch information
robbyrussell committed Aug 13, 2015
2 parents 4c1eda1 + b760a10 commit b8dbd9b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 43 deletions.
16 changes: 16 additions & 0 deletions lib/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ function take() {
cd $1
}

function open_command() {
local open_cmd

# define the open command
case "$OSTYPE" in
darwin*) open_cmd="open" ;;
cygwin*) open_cmd="cygstart" ;;
linux*) open_cmd="xdg-open" ;;
*) echo "Platform $OSTYPE not supported"
return 1
;;
esac

nohup $open_cmd "$@" &>/dev/null
}

#
# Get the value of an alias.
#
Expand Down
4 changes: 2 additions & 2 deletions plugins/fasd/fasd.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ $commands[fasd] ]; then # check if fasd is installed
fi
source "$fasd_cache"
unset fasd_cache

alias v='f -e vim'
alias o='a -e open'
alias o='a -e open_command'
fi

10 changes: 1 addition & 9 deletions plugins/frontend-search/frontend-search.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

function frontend() {

# get the open command
local open_cmd
if [[ $(uname -s) == 'Darwin' ]]; then
open_cmd='open'
else
open_cmd='xdg-open'
fi

# no keyword provided, simply show how call methods
if [[ $# -le 1 ]]; then
echo "Please provide a search-content and a search-term for app.\nEx:\nfrontend <search-content> <search-term>\n"
Expand Down Expand Up @@ -113,7 +105,7 @@ function frontend() {

echo "$url"

$open_cmd "$url"
open_command "$url"

}

Expand Down
15 changes: 4 additions & 11 deletions plugins/jira/jira.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
# Usage: jira # opens a new issue
# jira ABC-123 # Opens an existing issue
open_jira_issue () {
local open_cmd
if [[ "$OSTYPE" = darwin* ]]; then
open_cmd='open'
else
open_cmd='xdg-open'
fi

if [ -f .jira-url ]; then
jira_url=$(cat .jira-url)
elif [ -f ~/.jira-url ]; then
Expand All @@ -39,7 +32,7 @@ open_jira_issue () {

if [ -z "$1" ]; then
echo "Opening new issue"
$open_cmd "${jira_url}/secure/CreateIssue!default.jspa"
open_command "${jira_url}/secure/CreateIssue!default.jspa"
elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
jira_query $@
else
Expand All @@ -52,9 +45,9 @@ open_jira_issue () {
fi

if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
$open_cmd "$jira_url/issues/$jira_prefix$1$addcomment"
open_command "$jira_url/issues/$jira_prefix$1$addcomment"
else
$open_cmd "$jira_url/browse/$jira_prefix$1$addcomment"
open_command "$jira_url/browse/$jira_prefix$1$addcomment"
fi
fi
}
Expand Down Expand Up @@ -90,7 +83,7 @@ jira_query () {
return 1
fi
echo "Browsing issues ${verb} ${preposition} ${jira_name}"
$open_cmd "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC"
open_command "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC"
}

alias jira='open_jira_issue'
Expand Down
2 changes: 1 addition & 1 deletion plugins/lighthouse/lighthouse.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open_lighthouse_ticket () {
else
lighthouse_url=$(cat .lighthouse-url);
echo "Opening ticket #$1";
`open $lighthouse_url/tickets/$1`;
open_command "$lighthouse_url/tickets/$1";
fi
}

Expand Down
10 changes: 1 addition & 9 deletions plugins/node/node.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Open the node api for your current version to the optional section.
# TODO: Make the section part easier to use.
function node-docs {
# get the open command
local open_cmd
if [[ "$OSTYPE" = darwin* ]]; then
open_cmd='open'
else
open_cmd='xdg-open'
fi

$open_cmd "http://nodejs.org/docs/$(node --version)/api/all.html#all_$1"
open_command "http://nodejs.org/docs/$(node --version)/api/all.html#all_$1"
}
12 changes: 1 addition & 11 deletions plugins/web-search/web-search.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ function web_search() {
github "https://github.com/search?q="
)

# define the open command
case "$OSTYPE" in
darwin*) open_cmd="open" ;;
cygwin*) open_cmd="cygstart" ;;
linux*) open_cmd="xdg-open" ;;
*) echo "Platform $OSTYPE not supported"
return 1
;;
esac

# check whether the search engine is supported
if [[ -z "$urls[$1]" ]]; then
echo "Search engine $1 not supported."
Expand All @@ -41,7 +31,7 @@ function web_search() {
url="${(j://:)${(s:/:)urls[$1]}[1,2]}"
fi

nohup $open_cmd "$url" &>/dev/null
open_command "$url"
}


Expand Down

0 comments on commit b8dbd9b

Please sign in to comment.