Last active
October 17, 2022 03:45
-
-
Save gnuget/e49a7e80816b4abb3e4e47e47b74ed46 to your computer and use it in GitHub Desktop.
my-local-enviroment-wrapper.plugin.zsh
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
# I just extended https://github.com/JoshuaBedford/lando-zsh/ to support ddev and docksal | |
# all the credit is for Joshua Bedford. | |
# | |
# To use it, add `my-local-enviroment-wrapper` to the plugins array in your zshrc file eg: | |
# plugins=(git my-local-enviroment-wrapper) | |
# | |
# Put this file at: ~/.oh-my-zsh/custom/plugins/my-local-enviroment-wrapper.plugin.zsh | |
# and set your projects folder path in your ~/.zshrc eg: | |
# export ZSH_SITES_DIRECTORY="$HOME/Projects" | |
# | |
: ${ZSH_SITES_DIRECTORY:="$HOME/Sites"} | |
: ${LANDO_ZSH_CONFIG_FILE:=.lando.yml} | |
: ${DOCKSAL_ZSH_CONFIG_FILE:=.docksal} | |
: ${DDEV_ZSH_CONFIG_FILE:=.ddev} | |
# Enable the commands. | |
function composer \ | |
drush { | |
if checkForSitesDirectory && checkForLandoFile; then | |
lando "$0" "$@" | |
elif checkForSitesDirectory && checkForDocksalFile; then | |
fin "$0" "$@" | |
elif checkForSitesDirectory && checkForDDEVFile; then | |
ddev "$0" "$@" | |
else | |
command "$0" "$@" | |
fi | |
} | |
# Check if we are within the Sites Directory. | |
checkForSitesDirectory() { | |
# Only bother checking within the Sites directory. | |
if [[ "$PWD/" != "$ZSH_SITES_DIRECTORY"/* ]]; then | |
# Not within $ZSH_SITES_DIRECTORY | |
return 1 | |
fi | |
return 0 | |
} | |
checkForLandoFile() { | |
local curr_dir="$PWD" | |
# Checking for file: $LANDO_ZSH_CONFIG_FILE within $ZSH_SITES_DIRECTORY... | |
while [[ "$curr_dir" != "$ZSH_SITES_DIRECTORY" ]]; do | |
if [[ -f "$curr_dir/$LANDO_ZSH_CONFIG_FILE" ]]; then | |
return 0 | |
fi | |
curr_dir="${curr_dir:h}" | |
done | |
# Could not find $LANDO_ZSH_CONFIG_FILE in the current directory | |
# or in any of its parents up to $ZSH_SITES_DIRECTORY. | |
return 1 | |
} | |
checkForDocksalFile() { | |
local curr_dir="$PWD" | |
# Checking for file: $LANDO_ZSH_CONFIG_FILE within $ZSH_SITES_DIRECTORY... | |
while [[ "$curr_dir" != "$ZSH_SITES_DIRECTORY" ]]; do | |
if [[ -d "$curr_dir/$DOCKSAL_ZSH_CONFIG_FILE" ]]; then | |
return 0 | |
fi | |
curr_dir="${curr_dir:h}" | |
done | |
# Could not find $LANDO_ZSH_CONFIG_FILE in the current directory | |
# or in any of its parents up to $ZSH_SITES_DIRECTORY. | |
return 1 | |
} | |
checkForDDEVFile() { | |
local curr_dir="$PWD" | |
# Checking for file: $LANDO_ZSH_CONFIG_FILE within $ZSH_SITES_DIRECTORY... | |
while [[ "$curr_dir" != "$ZSH_SITES_DIRECTORY" ]]; do | |
if [[ -d "$curr_dir/$DDEV_ZSH_CONFIG_FILE" ]]; then | |
return 0 | |
fi | |
curr_dir="${curr_dir:h}" | |
done | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment