Skip to content

Instantly share code, notes, and snippets.

@iBobik
Last active October 26, 2019 12:10
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/ba6eb36cb959b7ce88f50298069ec39f to your computer and use it in GitHub Desktop.
Save iBobik/ba6eb36cb959b7ce88f50298069ec39f to your computer and use it in GitHub Desktop.
My Bash tweeks for Docker and Drupal
# Customize bash prompt to print current GIT branch and Docker Machine name.
export PSORIG="\u \W \$ "
function CUSTOMPROMPT() {
BRANCH="$(git branch 2>/dev/null | grep '*' | cut -d" " -f2-)"
if [ -n "$BRANCH" ] ; then
export PS1=$PSORIG$(echo -en "\[\033[01;33m\]$BRANCH > \[\033[00m\]")
else
export PS1="$PSORIG"
fi
if [ -n "$DOCKER_MACHINE_NAME" ] ; then
export PS1=$PS1$(echo -en "\[\033[00;36m\]$DOCKER_MACHINE_NAME > \[\033[00m\]")
fi
update_terminal_cwd
}
PROMPT_COMMAND="CUSTOMPROMPT; $PROMPT_COMMAND"
# 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
}
@iBobik
Copy link
Author

iBobik commented Dec 20, 2017

how it works

@iBobik
Copy link
Author

iBobik commented Oct 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment