Skip to content

Bash aliases

Maksym Zaporozhets edited this page Jan 8, 2024 · 5 revisions

Bash aliases and environment variables for easier development

The same configurations may be applied to other shells, but we use bash in our examples. Here is a set of handy things for your ~/.bash_aliases file:

force_color_prompt=yes
shopt -s autocd
set completion-ignore-case On

# Let's make the prompt more colorful and show Git branch if available
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\][\d \t] \[\033[01;33m\]\w\[\033[01;31m\]\[\033[01;34m\]$(__git_ps1)\[\033[01;31m\] > \[\033[01;32m\]'

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\w\a\]$PS1"
    ;;
*)
    ;;
esac

# List files and directories in a human-readable format and sort them by size
alias duhs='du -hs * | sort -h'

# PHP xDebug 3.x config
export XDEBUG_SESSION=PHPSTORM

# === Mandatory Dockerizer variables ===
export DOCKERIZER_PROJECTS_ROOT_DIR=${HOME}/misc/apps/
export DOCKERIZER_SSL_CERTIFICATES_DIR=${HOME}/misc/certs/
# === AWS variables ===
export AWS_ACCESS_KEY_ID=<aws_access_key_id>
export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
export DOCKERIZER_AWS_S3_REGION=<default_aws_s3_region>
export DOCKERIZER_AWS_S3_BUCKET_PREFIX=<default_aws_s3_bucket_prefix>

# === Show a list of Docker containers and their composition locations ===
COMPOSITIONS() {
    local info='{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}\t{{.Status}}\t{{.Names}}\t{{.Label "com.docker.compose.project.working_dir"}}'

    docker container ls --all --filter label=com.docker.compose.project --format "table $info"
}

# === docker compose aliases ===
alias DOWN='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml down'
alias DOWNV='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml down --volumes'
alias PS='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml ps'
alias RESTART='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml restart'
alias START='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml start'
alias STOP='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml stop'
alias UP='docker compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml up -d --force-recreate'

# === Dockerizer V3 aliases ===
# Path to Dockerizer to make other aliases shorter
alias DOCKERIZER='php -d xdebug.start_with_request=trigger ${DOCKERIZER_PROJECTS_ROOT_DIR}dockerizer_for_php/bin/dockerizer'
# Compositions
alias BUILD='DOCKERIZER composition:build-from-template'
# Magento
alias SETUP='DOCKERIZER magento:setup'
alias REINSTALL='DOCKERIZER magento:reinstall'
# MySQL
alias CONNECT='DOCKERIZER docker:mysql:connect -c $(DOCKERIZER composition:get-container-name mysql)'
alias IMPORTDB='DOCKERIZER docker:mysql:import-db -c $(DOCKERIZER composition:get-container-name mysql)'
alias EXPORTDB='DOCKERIZER docker:mysql:export-db -c $(DOCKERIZER composition:get-container-name mysql)'
# Dockerizer
alias WATCH='DOCKERIZER maintenance:traefik:update-networks -c reverse-proxy --watch'

# === Enter Docker containers ===
alias PHP='docker exec -it $(DOCKERIZER composition:get-container-name php) bash'
alias PHPROOT='docker exec -uroot -it $(DOCKERIZER composition:get-container-name php) bash'

# === PHP container aliases ===
# Run `composer install` inside a Docker container without entering it
alias CI='docker exec -it $(DOCKERIZER composition:get-container-name php) composer install'

# === Magento aliases ===
alias MAGENTO='docker exec -it $(DOCKERIZER composition:get-container-name php) php bin/magento'
alias CC='MAGENTO cache:clean'
alias CF='MAGENTO cache:flush'
alias IR='MAGENTO indexer:reindex'
alias SU='MAGENTO setup:upgrade'
alias SDC='MAGENTO setup:di:compile'
alias URN='MAGENTO dev:urn-catalog:generate .idea/misc.xml; sed -i "s/\/var\/www\/html/\$PROJECT_DIR\$/g" ../../.idea/misc.xml'
alias MODEDEV='MAGENTO deploy:mode:set developer'
alias MODEDEF='MAGENTO deploy:mode:set default'
alias MODEPROD='MAGENTO deploy:mode:set production'

alias CR='rm -rf var/cache/* var/page_cache/* var/view_preprocessed/* var/di/* var/generation/* generated/code/* generated/metadata/* pub/static/frontend/* pub/static/adminhtml/* pub/static/deployed_version.txt'
alias MCS='php -d xdebug.start_with_request=trigger ${DOCKERIZER_PROJECTS_ROOT_DIR}magento-coding-standard/vendor/bin/phpcs --standard=Magento2 --severity=1 '
alias MND='php -d xdebug.start_with_request=trigger ${DOCKERIZER_PROJECTS_ROOT_DIR}php-quality-tools/vendor/bin/phpmnd '

# === Other aliases ===
# Git aliases
alias PULL='git pull origin master'
alias PUSH='git push origin master'
alias PULLC='GIT_BRANCH=`git branch --show-current` ; git pull origin $GIT_BRANCH ; unset GIT_BRANCH'
alias PUSHC='GIT_BRANCH=`git branch --show-current` ; git push origin $GIT_BRANCH ; unset GIT_BRANCH'
alias GG='git gui &'
alias GS='git status'
alias GK='gitk --all &'

Run source ~/.bashrc in all opened terminal windows to apply changes. Alternatively, you can restart your computer.

Note that ~/misc/apps/ is a location created by Ubuntu post-installation scripts. This is why we sometimes use this path in the documentation. Replace it with your own location if needed.

Check the Ubuntu post-installation scripts for the latest alias updates. For example, see this script starting with force_color_prompt=yes.

Clone this wiki locally