mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-22 05:40:08 +00:00
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`.
This commit is contained in:
parent
c9c11d605f
commit
7f8851f52f
1 changed files with 15 additions and 13 deletions
|
@ -1,29 +1,31 @@
|
||||||
alias pjo="pj open"
|
alias pjo="pj open"
|
||||||
|
|
||||||
function pj () {
|
pj () {
|
||||||
cmd="cd"
|
emulate -L zsh
|
||||||
file=$1
|
setopt shwordsplit
|
||||||
|
|
||||||
if [[ "open" == "$file" ]] then
|
cmd="cd"
|
||||||
|
project=$1
|
||||||
|
|
||||||
|
if [[ "open" == "$project" ]]; then
|
||||||
shift
|
shift
|
||||||
file=$*
|
project=$*
|
||||||
cmd=(${(s: :)EDITOR})
|
cmd=$EDITOR
|
||||||
else
|
else
|
||||||
file=$*
|
project=$*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for project in $PROJECT_PATHS; do
|
for basedir ($PROJECT_PATHS); do
|
||||||
if [[ -d $project/$file ]] then
|
if [[ -d "$basedir/$project" ]]; then
|
||||||
$cmd "$project/$file"
|
$cmd "$basedir/$project"
|
||||||
unset project # Unset project var
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "No such project $1"
|
echo "No such project '${project}'."
|
||||||
}
|
}
|
||||||
|
|
||||||
function _pj () {
|
_pj () {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
typeset -a projects
|
typeset -a projects
|
||||||
|
|
Loading…
Reference in a new issue