Skip to content

Instantly share code, notes, and snippets.

@iBobik
Created October 26, 2019 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iBobik/6499a52fc2f9f86f2c331042d1ca74cd to your computer and use it in GitHub Desktop.
Save iBobik/6499a52fc2f9f86f2c331042d1ca74cd to your computer and use it in GitHub Desktop.
My ZSH tweeks for Docker and Drupal
# Set env variables for Docker Machine
function dmenv() {
VM=${1}
# docker-machine start $VM
eval $(docker-machine env $VM)
}
# Dockers stats with container names
function dstats() {
docker stats $(docker ps --format '{{.Names}}')
}
# Get login link for Drupal superuser
function uli() {
dsh "" "" "drush uli"
}
# Open shell into app or php service of current Docker Compose project
# dsh [service] [user] [command]
function dsh() {
USER=${2:-www-data}
SERVICE=${1}
PROJECT=$(pwd | rev | cut -d '/' -f1 | rev | sed 's/[^a-zA-Z0-9-]//g')
if [[ $SERVICE ]]; then
CONTAINER=${PROJECT}_${SERVICE}_1
elif [[ $(docker ps | grep ${PROJECT}_php_1) ]]; then
CONTAINER=${PROJECT}_php_1
else
CONTAINER=${PROJECT}_web_1
fi
docker exec -itu $USER $CONTAINER ${3:-bash}
}
# Database dump from Drupal project
function ddump() {
FILE=${1:-dump.sql.gz}
dsh "" "" "drush sql-dump --gzip" > $FILE
}
# Customize prompt
PROMPT='%(?..%F{red}?%? )' # Status code
PROMPT=$PROMPT'%9c $ ' # Directory
# Add GIT branch to prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1 > /'
}
setopt PROMPT_SUBST
PROMPT=$PROMPT'%{%F{yellow}%}$(parse_git_branch)%{%F{none}%}' # GIT branch
# Add Docker Machine to prompt
get_docker_machine() {
if [ -n "$DOCKER_MACHINE_NAME" ] ; then
echo "$DOCKER_MACHINE_NAME > "
fi
}
PROMPT=$PROMPT'%{%F{cyan}%}$(get_docker_machine)%{%F{none}%}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment