From 93d9431890540dfdc1021dffca3eeebdc19d338d Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 24 Apr 2018 23:47:26 +0200 Subject: Check for Microsoft's WSL in open_command (#6751) This will work only on files and directories in a DrvFs mount, i.e. that can be translated to a Windows drive path. For example: /mnt/c/Users/user. Files and folders inside the LXSS directory can't be handled in Windows, they must be ONLY used by the WSL subsystem. That's why you won't be able to open your $HOME directory, for instance. See https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/ --- lib/functions.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/functions.zsh') diff --git a/lib/functions.zsh b/lib/functions.zsh index f30653784..7410ae645 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -25,7 +25,9 @@ function open_command() { case "$OSTYPE" in darwin*) open_cmd='open' ;; cygwin*) open_cmd='cygstart' ;; - linux*) open_cmd='xdg-open' ;; + linux*) [[ $(uname -a) =~ "Microsoft" ]] && \ + open_cmd='cmd.exe /c start' || \ + open_cmd='xdg-open' ;; msys*) open_cmd='start ""' ;; *) echo "Platform $OSTYPE not supported" return 1 -- cgit v1.2.3-70-g09d2 From 12086593a432d754d9c28bf6a66a1196e79877a3 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 29 Jun 2018 20:20:26 +0200 Subject: open_command: simplify code --- lib/functions.zsh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/functions.zsh') diff --git a/lib/functions.zsh b/lib/functions.zsh index 7410ae645..f448dbce8 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -16,9 +16,6 @@ function take() { } function open_command() { - emulate -L zsh - setopt shwordsplit - local open_cmd # define the open command @@ -36,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 } -- cgit v1.2.3-70-g09d2 From f898ada8e3d25c7d1ea309b487711a4e0a2c07b6 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 29 Jun 2018 20:20:56 +0200 Subject: open_command: fix and improve command for WSL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add double quotes to command so that the next argument isn't interpreted as the title for the start command. - If the first argument is a valid path, convert it to Windows path notation. If `wslpath` fails—because it's a path from inside WSL, which cannot be converted to Windows path notation— fail with an error code. This last circumstance will show an error like so: wslpath: path: Result not representable --- lib/functions.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/functions.zsh') diff --git a/lib/functions.zsh b/lib/functions.zsh index f448dbce8..dd8311611 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -22,9 +22,10 @@ function open_command() { case "$OSTYPE" in darwin*) open_cmd='open' ;; cygwin*) open_cmd='cygstart' ;; - linux*) [[ $(uname -a) =~ "Microsoft" ]] && \ - open_cmd='cmd.exe /c start' || \ - 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 -- cgit v1.2.3-70-g09d2 From 7cba6bb038fb699c44532992ee75e836b6576ac7 Mon Sep 17 00:00:00 2001 From: sam-lunt Date: Mon, 2 Jul 2018 10:05:24 -0500 Subject: Enable passing multiple directories to take (#6900) * enable passing multiple directories to take * Update take function Do not call cd if mkdir fails --- lib/functions.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/functions.zsh') diff --git a/lib/functions.zsh b/lib/functions.zsh index dd8311611..1066fed57 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -11,8 +11,7 @@ function upgrade_oh_my_zsh() { } function take() { - mkdir -p $1 - cd $1 + mkdir -p $@ && cd ${@:$#} } function open_command() { -- cgit v1.2.3-70-g09d2 From 2c1ff85bb2389a2ebdbf0150fd9287855cf348a8 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 9 Aug 2018 19:49:02 +0200 Subject: core: fix alias_value function Fixes #5835 --- lib/functions.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/functions.zsh') diff --git a/lib/functions.zsh b/lib/functions.zsh index 1066fed57..4ef8920f6 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -51,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] } # -- cgit v1.2.3-70-g09d2 From 55575b88f9e47d88fab02c26fc69e4af48af1cd9 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 25 Feb 2019 23:20:47 +0100 Subject: lib: optimize default and env_default --- lib/functions.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/functions.zsh') diff --git a/lib/functions.zsh b/lib/functions.zsh index 4ef8920f6..9f8736bd7 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -79,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 } @@ -93,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 } -- cgit v1.2.3-70-g09d2