d1d06b5675bebbe54f3d876eb993b6e89d8963c7

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Use standard open command in current plugins

Substitutes the current duplicate logic for the standard
and cross-platform function open_command in plugins:

  frontend-search, jira, node, web-search

Diff

  1diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh
  2index b9fb8634c66f15619247713d82febeeb28fbfeeb..f7485621bf444e479a6bd23e37eef220d733d317 100644
  3--- a/plugins/frontend-search/frontend-search.plugin.zsh
  4+++ b/plugins/frontend-search/frontend-search.plugin.zsh
  5@@ -2,14 +2,6 @@
  6 
  7 function frontend() {
  8 
  9-  # get the open command
 10-  local open_cmd
 11-  if [[ $(uname -s) == 'Darwin' ]]; then
 12-    open_cmd='open'
 13-  else
 14-    open_cmd='xdg-open'
 15-  fi
 16-
 17   # no keyword provided, simply show how call methods
 18   if [[ $# -le 1 ]]; then
 19     echo "Please provide a search-content and a search-term for app.\nEx:\nfrontend <search-content> <search-term>\n"
 20@@ -113,7 +105,7 @@ function frontend() {
 21 
 22   echo "$url"
 23 
 24-  $open_cmd "$url"
 25+  open_command "$url"
 26 
 27 }
 28 
 29diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh
 30index ca540c84c1229cbea6d0bb0ae721499e2ce41364..9a89327028a8acb9d36dbcd10a7eaf343f29a41f 100644
 31--- a/plugins/jira/jira.plugin.zsh
 32+++ b/plugins/jira/jira.plugin.zsh
 33@@ -11,13 +11,6 @@
 34 # Usage: jira           # opens a new issue
 35 #        jira ABC-123   # Opens an existing issue
 36 open_jira_issue () {
 37-  local open_cmd
 38-  if [[ "$OSTYPE" = darwin* ]]; then
 39-    open_cmd='open'
 40-  else
 41-    open_cmd='xdg-open'
 42-  fi
 43-
 44   if [ -f .jira-url ]; then
 45     jira_url=$(cat .jira-url)
 46   elif [ -f ~/.jira-url ]; then
 47@@ -39,7 +32,7 @@ open_jira_issue () {
 48 
 49   if [ -z "$1" ]; then
 50     echo "Opening new issue"
 51-    $open_cmd "${jira_url}/secure/CreateIssue!default.jspa"
 52+    open_command "${jira_url}/secure/CreateIssue!default.jspa"
 53   elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
 54     jira_query $@
 55   else 
 56@@ -52,9 +45,9 @@ open_jira_issue () {
 57     fi
 58     
 59     if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
 60-      $open_cmd  "$jira_url/issues/$jira_prefix$1$addcomment"
 61+      open_command  "$jira_url/issues/$jira_prefix$1$addcomment"
 62     else
 63-      $open_cmd  "$jira_url/browse/$jira_prefix$1$addcomment"
 64+      open_command  "$jira_url/browse/$jira_prefix$1$addcomment"
 65     fi
 66   fi
 67 }
 68@@ -90,7 +83,7 @@ jira_query () {
 69         return 1
 70     fi
 71     echo "Browsing issues ${verb} ${preposition} ${jira_name}"
 72-    $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"
 73+    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"
 74 }
 75 
 76 alias jira='open_jira_issue'
 77diff --git a/plugins/node/node.plugin.zsh b/plugins/node/node.plugin.zsh
 78index 39d8b10d99324b60c6b01155ac8b9401b4b57aa0..2463815aca572c54cb08dda1bc4a69335225aacd 100644
 79--- a/plugins/node/node.plugin.zsh
 80+++ b/plugins/node/node.plugin.zsh
 81@@ -1,13 +1,5 @@
 82 # Open the node api for your current version to the optional section.
 83 # TODO: Make the section part easier to use.
 84 function node-docs {
 85-  # get the open command
 86-  local open_cmd
 87-  if [[ "$OSTYPE" = darwin* ]]; then
 88-    open_cmd='open'
 89-  else
 90-    open_cmd='xdg-open'
 91-  fi
 92-
 93-  $open_cmd "http://nodejs.org/docs/$(node --version)/api/all.html#all_$1"
 94+  open_command "http://nodejs.org/docs/$(node --version)/api/all.html#all_$1"
 95 }
 96diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh
 97index d407edb964f67a222a630eb16c22573d6e05e655..7c3ad9046458199d8cbf224cae49c0081425dedd 100644
 98--- a/plugins/web-search/web-search.plugin.zsh
 99+++ b/plugins/web-search/web-search.plugin.zsh
100@@ -14,16 +14,6 @@ function web_search() {
101     github      "https://github.com/search?q="
102   )
103 
104-  # define the open command
105-  case "$OSTYPE" in
106-    darwin*)  open_cmd="open" ;;
107-    cygwin*)  open_cmd="cygstart" ;;
108-    linux*)   open_cmd="xdg-open" ;;
109-    *)        echo "Platform $OSTYPE not supported"
110-              return 1
111-              ;;
112-  esac
113-
114   # check whether the search engine is supported
115   if [[ -z "$urls[$1]" ]]; then
116     echo "Search engine $1 not supported."
117@@ -41,7 +31,7 @@ function web_search() {
118     url="${(j://:)${(s:/:)urls[$1]}[1,2]}"
119   fi
120 
121-  nohup $open_cmd "$url" &>/dev/null
122+  open_command "$url"
123 }
124 
125