summaryrefslogtreecommitdiff
path: root/lib/functions.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/functions.zsh')
-rw-r--r--lib/functions.zsh24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/functions.zsh b/lib/functions.zsh
index f30653784..9f8736bd7 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -11,21 +11,20 @@ function upgrade_oh_my_zsh() {
}
function take() {
- mkdir -p $1
- cd $1
+ mkdir -p $@ && cd ${@:$#}
}
function open_command() {
- emulate -L zsh
- setopt shwordsplit
-
local open_cmd
# define the open command
case "$OSTYPE" in
darwin*) open_cmd='open' ;;
cygwin*) open_cmd='cygstart' ;;
- linux*) open_cmd='xdg-open' ;;
+ linux*) ! [[ $(uname -a) =~ "Microsoft" ]] && open_cmd='xdg-open' || {
+ open_cmd='cmd.exe /c start ""'
+ [[ -e "$1" ]] && { 1="$(wslpath -w "${1:a}")" || return 1 }
+ } ;;
msys*) open_cmd='start ""' ;;
*) echo "Platform $OSTYPE not supported"
return 1
@@ -34,9 +33,9 @@ function open_command() {
# don't use nohup on OSX
if [[ "$OSTYPE" == darwin* ]]; then
- $open_cmd "$@" &>/dev/null
+ ${=open_cmd} "$@" &>/dev/null
else
- nohup $open_cmd "$@" &>/dev/null
+ nohup ${=open_cmd} "$@" &>/dev/null
fi
}
@@ -52,8 +51,7 @@ function open_command() {
# 1 if it does not exist
#
function alias_value() {
- alias "$1" | sed "s/^$1='\(.*\)'$/\1/"
- test $(alias "$1")
+ (( $+aliases[$1] )) && echo $aliases[$1]
}
#
@@ -81,7 +79,7 @@ function try_alias_value() {
# 0 if the variable exists, 3 if it was set
#
function default() {
- test `typeset +m "$1"` && return 0
+ (( $+parameters[$1] )) && return 0
typeset -g "$1"="$2" && return 3
}
@@ -95,8 +93,8 @@ function default() {
# 0 if the env variable exists, 3 if it was set
#
function env_default() {
- env | grep -q "^$1=" && return 0
- export "$1=$2" && return 3
+ (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0
+ export "$1=$2" && return 3
}