Last active
March 13, 2024 15:53
-
-
Save Winslett/db6f2c51a96bf8b7a380952ddeee40ab to your computer and use it in GitHub Desktop.
Pretty Project Directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compdef _p p | |
function _p () { | |
_files -W /Users/`whoami`/Projects/ - | |
return 1 | |
} | |
function p () { | |
if [[ $1 == 'open' ]]; then | |
REPLACEMENT="s/\\/Users\\/`whoami`\\/Projects\\///g" | |
CURRENT_PROJECT_DIR=`pwd | gsed $REPLACEMENT` | |
open https://$CURRENT_PROJECT_DIR | |
else | |
string=`echo $1 | gsed 's/\.git$//' | gsed 's/[:\@\/]/ /g'` | |
a=("${(s/ /)string}") | |
domain=$a[1] | |
organization=$a[2] | |
code_base=$a[3] | |
projects_path=$HOME/Projects | |
full_path=$projects_path/$domain/$organization/$code_base | |
if [[ -d $full_path ]]; then | |
cd /Users/`whoami`/Projects/$1 | |
if [[ -a ./.nvmrc ]]; then | |
nvm use | |
fi | |
else | |
mkdir -p $projects_path/$domain/$organization | |
cd $projects_path/$domain/$organization | |
git clone git@$domain:$organization/$code_base.git | |
cd $code_base | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment