Last active
October 11, 2024 11:10
-
-
Save Winslett/db6f2c51a96bf8b7a380952ddeee40ab to your computer and use it in GitHub Desktop.
Pretty Project Directories
This file contains hidden or 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 | |
if [[ -a ./.postgres-version ]]; then | |
[[ `postgres --version` =~ '([0-9]+)\.' ]] | |
linked_version=${match[1]} | |
desired_version=`cat ./.postgres-version` | |
if [[ $linked_version != $desired_version ]]; then | |
pkill -HUP postgres | |
brew unlink postgresql@${linked_version} | |
brew link postgresql@${desired_version} | |
fi | |
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