You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.0 KiB
49 lines
1.0 KiB
10 years ago
|
#!/bin/zsh
|
||
|
|
||
|
#
|
||
|
# Original idea by DefV (Jan De Poorter)
|
||
|
# Source: https://gist.github.com/pjaspers/368394#comment-1016
|
||
|
#
|
||
|
# Usage:
|
||
|
# - Set `$PROJECT_PATHS` in your ~/.zshrc
|
||
|
# e.g.: PROJECT_PATHS=(~/src ~/work)
|
||
|
# - In ZSH you now can open a project directory with the command: `pj my-project`
|
||
|
# the plugin will locate the `my-project` directory in one of the $PROJECT_PATHS
|
||
|
# Also tab completion is supported.
|
||
|
# - `pjo my-project` will open the directory in $EDITOR
|
||
|
#
|
||
|
|
||
|
function pj() {
|
||
10 years ago
|
cmd="cd"
|
||
|
file=$1
|
||
|
|
||
|
if [[ "open" == "$file" ]] then
|
||
|
shift
|
||
|
file=$*
|
||
|
cmd=(${(s: :)EDITOR})
|
||
|
else
|
||
|
file=$*
|
||
|
fi
|
||
|
|
||
|
for project in $PROJECT_PATHS; do
|
||
|
if [[ -d $project/$file ]] then
|
||
|
$cmd "$project/$file"
|
||
|
unset project # Unset project var
|
||
|
return
|
||
10 years ago
|
fi
|
||
10 years ago
|
done
|
||
|
echo "No such project $1"
|
||
10 years ago
|
}
|
||
|
|
||
|
alias pjo="pj open"
|
||
|
|
||
|
function _pj () {
|
||
10 years ago
|
# might be possible to improve this using glob, without the basename trick
|
||
|
typeset -a projects
|
||
|
projects=($PROJECT_PATHS/*)
|
||
|
projects=$projects:t
|
||
|
_arguments '*:file:($projects)'
|
||
10 years ago
|
}
|
||
|
|
||
|
compdef _pj pj
|