Skip to content

Instantly share code, notes, and snippets.

@jonnitto
Last active March 26, 2018 08:25
Show Gist options
  • Save jonnitto/cc28c412326552fe30a04bafcd92e4d1 to your computer and use it in GitHub Desktop.
Save jonnitto/cc28c412326552fe30a04bafcd92e4d1 to your computer and use it in GitHub Desktop.
Open Neos project from the Command Line
# With the command `NeosProject` you get the site package folder and available folders definded in `ADDITIONAL_FOLDER`
# With `codeProject` you open your project in Visual Studio Code
# With `atomProject` you open your project in Atom
# With `pstormProject` you open your project in PHP Storm
# To disable the fallback (open current folder), change the fallback variable to ""
NeosProject() {
# Places where site packages could are stored
local SITE_FOLDER=(".src" "_src" "Packages/Sites")
# Additional folder to open
local ADDITIONAL_FOLDER=("Packages/Plugins" "Web")
local FOLDER_ARRAY=()
local fallback="."
# Get the site folder
for f in "${SITE_FOLDER[@]}"
do
if [ -d $f -a ${#FOLDER_ARRAY[@]} == 0 ]
then FOLDER_ARRAY+=("${f}/$([ $(echo ${f}/* | wc -w) == 1 ] && basename ${f}/*)");
fi
done
# Get additional folder
for f in "${ADDITIONAL_FOLDER[@]}"
do
if [ -d "${f}" ]
then FOLDER_ARRAY+=($f)
fi
done
# Fallback
if [ -n "$fallback" -a ${#FOLDER_ARRAY[@]} == 0 ]
then FOLDER_ARRAY=($fallback)
fi;
echo "${FOLDER_ARRAY[@]}"
}
codeProject() {
# If we have a code workspace, open this instead
if [ -f *.code-workspace ];
then for f in *.code-workspace; do open "$f"; done;
else code $(NeosProject);
fi;
}
atomProject() {
atom $(NeosProject)
}
sublimeProject() {
sublime $(NeosProject)
}
pstormProject() {
pstorm $(NeosProject)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment