refactored some stuff
This commit is contained in:
parent
d31941c80c
commit
b1cbc649cc
11 changed files with 445 additions and 56 deletions
102
zsh/files/lando.zsh
Normal file
102
zsh/files/lando.zsh
Normal file
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
SITES_DIRECTORY="$HOME/Sites"
|
||||
CONFIG_FILE="./.lando.yml"
|
||||
|
||||
# Enable wp command
|
||||
function wp() {
|
||||
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
|
||||
lando wp "$@"
|
||||
else
|
||||
command wp "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Enable composer command
|
||||
function composer() {
|
||||
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
|
||||
lando composer "$@"
|
||||
else
|
||||
command composer "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Enable artisan command
|
||||
function artisan() {
|
||||
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
|
||||
lando artisan "$@"
|
||||
else
|
||||
command artisan "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Enable yarn command
|
||||
function yarn() {
|
||||
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
|
||||
lando yarn "$@"
|
||||
else
|
||||
command yarn "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Enable npm command
|
||||
function npm() {
|
||||
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
|
||||
lando npm "$@"
|
||||
else
|
||||
command npm "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Enable gulp command
|
||||
function gulp() {
|
||||
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
|
||||
lando gulp "$@"
|
||||
else
|
||||
command gulp "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
checkForFile() {
|
||||
local current_directory="$PWD"
|
||||
|
||||
# Bash is backwards. 0 is true 1 (non-zero) is false.
|
||||
flag="1"
|
||||
|
||||
# Only bother checking for lando within the Sites directory.
|
||||
if [[ ":$PWD:" == *":$2"* ]]; then
|
||||
echo "Checking for file: $1 within $2..."
|
||||
|
||||
while true; do
|
||||
if [ $current_directory != "$2" ]; then
|
||||
if [ -f "$current_directory/$1" ]; then
|
||||
return "0"
|
||||
fi
|
||||
current_directory="$(dirname $current_directory)"
|
||||
else
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$flag" == "1" ]]; then
|
||||
echo "Could not find $1 in the current directory or in any of its parents up to $2."
|
||||
fi
|
||||
else
|
||||
echo "Checking for file: $1"
|
||||
|
||||
if [ -f "$1" ]; then
|
||||
echo "Found it"
|
||||
return 0
|
||||
else
|
||||
echo "Not Found"
|
||||
return "1"
|
||||
fi
|
||||
|
||||
if [[ "$flag" == "1" ]]; then
|
||||
echo "Could not find $1."
|
||||
fi
|
||||
fi
|
||||
|
||||
return $flag
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue