From 7f8851f52f9ebb03bc5be0246ee2b591196bdd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 11 Aug 2016 01:33:36 +0200 Subject: [PATCH] Refactor pj function - Use `emulate -L zsh` to make all variables local. - Use `shwordsplit` to interpret `$cmd` spaces correctly. - Rename `$project` and `$file` variables to the more appropriate `$basedir` and `$project`. --- plugins/pj/pj.plugin.zsh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/pj/pj.plugin.zsh b/plugins/pj/pj.plugin.zsh index 1d89af00b..f9d7f8e27 100644 --- a/plugins/pj/pj.plugin.zsh +++ b/plugins/pj/pj.plugin.zsh @@ -1,29 +1,31 @@ alias pjo="pj open" -function pj () { - cmd="cd" - file=$1 +pj () { + emulate -L zsh + setopt shwordsplit - if [[ "open" == "$file" ]] then + cmd="cd" + project=$1 + + if [[ "open" == "$project" ]]; then shift - file=$* - cmd=(${(s: :)EDITOR}) + project=$* + cmd=$EDITOR else - file=$* + project=$* fi - for project in $PROJECT_PATHS; do - if [[ -d $project/$file ]] then - $cmd "$project/$file" - unset project # Unset project var + for basedir ($PROJECT_PATHS); do + if [[ -d "$basedir/$project" ]]; then + $cmd "$basedir/$project" return fi done - echo "No such project $1" + echo "No such project '${project}'." } -function _pj () { +_pj () { emulate -L zsh typeset -a projects