From 2d0bfcf81846ea4cb0fe2a42f3dac7f2c60e77b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 5 Aug 2015 00:27:51 +0200 Subject: [PATCH 1/3] Implement cross-platform open function open_command() For now this supports: - Mac OS X - Linux (presumably works on all versions) - Cygwin (Windows) --- lib/functions.zsh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/functions.zsh b/lib/functions.zsh index 17f5f9cbf..0d632a268 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -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. # From d1d06b5675bebbe54f3d876eb993b6e89d8963c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 5 Aug 2015 00:32:57 +0200 Subject: [PATCH 2/3] 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 --- .../frontend-search/frontend-search.plugin.zsh | 10 +--------- plugins/jira/jira.plugin.zsh | 15 ++++----------- plugins/node/node.plugin.zsh | 10 +--------- plugins/web-search/web-search.plugin.zsh | 12 +----------- 4 files changed, 7 insertions(+), 40 deletions(-) diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh index b9fb8634c..f7485621b 100644 --- a/plugins/frontend-search/frontend-search.plugin.zsh +++ b/plugins/frontend-search/frontend-search.plugin.zsh @@ -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 \n" @@ -113,7 +105,7 @@ function frontend() { echo "$url" - $open_cmd "$url" + open_command "$url" } diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index ca540c84c..9a8932702 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -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 @@ -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 @@ -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 } @@ -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' diff --git a/plugins/node/node.plugin.zsh b/plugins/node/node.plugin.zsh index 39d8b10d9..2463815ac 100644 --- a/plugins/node/node.plugin.zsh +++ b/plugins/node/node.plugin.zsh @@ -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" } diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index d407edb96..7c3ad9046 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -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." @@ -41,7 +31,7 @@ function web_search() { url="${(j://:)${(s:/:)urls[$1]}[1,2]}" fi - nohup $open_cmd "$url" &>/dev/null + open_command "$url" } From b760a10cb27e5e17ad32e51ffac3374334fa4888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 5 Aug 2015 01:02:17 +0200 Subject: [PATCH 3/3] Use standard open command in fasd and lighthouse plugins --- plugins/fasd/fasd.plugin.zsh | 6 +++--- plugins/lighthouse/lighthouse.plugin.zsh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/fasd/fasd.plugin.zsh b/plugins/fasd/fasd.plugin.zsh index 472ab2b0f..b11f0b511 100644 --- a/plugins/fasd/fasd.plugin.zsh +++ b/plugins/fasd/fasd.plugin.zsh @@ -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' -fi + alias v='f -e vim' + alias o='a -e open_command' +fi diff --git a/plugins/lighthouse/lighthouse.plugin.zsh b/plugins/lighthouse/lighthouse.plugin.zsh index 7661c6add..48cddbccc 100644 --- a/plugins/lighthouse/lighthouse.plugin.zsh +++ b/plugins/lighthouse/lighthouse.plugin.zsh @@ -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 }