Skip to content

Instantly share code, notes, and snippets.

@ChristianOellers
Last active June 11, 2023 15:01
Show Gist options
  • Save ChristianOellers/6d2f2608135f74488462b7a648111f7f to your computer and use it in GitHub Desktop.
Save ChristianOellers/6d2f2608135f74488462b7a648111f7f to your computer and use it in GitHub Desktop.
Bash aliases - Git + Docker - Advanced snippets + Concepts
#!/bin/bash
# - Angular
# - Apache
# - Composer
# - Docker
# - Git
# - Keys
# - MySQL
# - PHP
# - Symfony
# - Vagrant
# - Xdebug
# - Yarn
# - HELPERS
# - SYSTEM
# ---------------------------------------------------------------------------------------------------------------------------------- Angular
alias ngs="ng serve"
# ----------------------------------------------------------------------------------------------------------------------------------- Apache
# Control Apache server
# Requires 'sudo su - ...' if not allowed for user via 'sudo visudo'
alias apstt="sudo apachectl start"
alias aprst="sudo apachectl restart"
alias apstp="sudo apachectl stop"
# --------------------------------------------------------------------------------------------------------------------------------- Composer
# Bind
alias composer="php /usr/local/bin/composer.phar"
# Tools
alias compi="composer install"
alias compr="composer require" # Add parameter: Package name
alias compu="composer update"
alias compv="composer -v"
# Projects
alias compcrp="composer create-project" # Add parameter: Vendor package
#alias compcrpsym="composer create-project symfony/website-skeleton" # Add parameter: Project name
# ----------------------------------------------------------------------------------------------------------------------------------- Docker
# Check if Docker daemon is running before adding aliases - Suppress CLI notice:
# 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the Docker daemon running?'
if [[ -n `launchctl list | grep "docker.docker"` ]]
then
# Start/Stop
alias dcu="docker-compose up"
alias dcuf="docker-compose up -f"
alias dcdwn="docker-compose down"
# Build
alias dcb="docker-compose build"
alias dcbnc="docker-compose build --no-cache"
# Show containers
alias dps="docker ps"
alias dpsa="docker ps -a"
# Show images
alias dsi="docker images"
alias dsai="docker images -a"
# Monitor logs
alias dlogs="docker logs $(docker ps -q)"
# SSH login (in first running container)
# alias dssh="docker exec -it $(docker ps -q) /bin/bash" (?)
alias dssh="docker exec -it $(docker ps -q) sh"
# SSH login (container by name)
alias dexecit="docker exec -it" # Add: (%container name%) bash
# Stop all running containers
alias dstp="docker stop $(docker ps -q)"
# Delete containers: All
# alias drmc="docker rm $(docker ps -a -q)"
# Delete images: All unused / All
# alias drmi="docker rmi $(docker images -q)"
# WordPress - Cache flush
alias dwpcache="docker-compose run --rm wpcli"
else
# Docker is not running - Don't add aliases
echo ""
fi
# -------------------------------------------------------------------------------------------------------------------------------------- Git
# Misc
alias gs="git status"
alias gb="git branch"
alias gbcur="git branch --show-current"
# Cherry picking
# - Add hash as parameter
alias gchy="git cherry-pick"
# Clean up
# - Delete branch
# - Remove untracked/deleted files
# - Reset branch (all not pushed)
# - Reset branch (last commit)
alias gbdelete="git branch -d"
alias gclean="git clean -d -f"
alias grshard="git reset --hard"
alias grshead="git reset HEAD~1"
# Commit (sign all by default)
alias gcm="git commit -S -m"
alias gacm="git add .; git commit -S -m"
alias gacmp="git add .; git commit -S -m '.'; git push"
# Conflicts - Show unresolved
alias gcfl="git ls-files -u; git diff --name-status --diff-filter=U; git mergetool"
# Diffs
# - Diff current against primary branch (usually 'main') - Show all changed files
alias gdfm="git diff main --name-only"
# Hashes
# - Show hash of HEAD (usually current commit)
# - Show hash of branch (add name after command)
alias ghash="git rev-parse --short HEAD"
alias ghashb="git rev-parse --short"
# Patches
# - Create for all staged files (of 'git add .')
# alias gptchstage="git diff --cached > patch.patch"
alias gptch="git diff --cached > patch.patch"
# Create / Switch branch
alias gc="git checkout"
alias gcb="git checkout -b"
alias gcbm="git checkout main"
# Fetch / Pull
alias gf="git fetch"
alias gfo="git fetch origin"
alias gfu="git fetch upstream"
alias gp="git pull"
alias gpp="git push"
# Garbage collection - Fix issues like these:
# - 'Unlink of file '...' failed. Should I try again? (y/n)'
alias ggc="git gc"
# Logs
alias glog="git log --oneline"
alias gloglast="glog -n1"
alias glogmrg="glog --merges"
alias glognomrg="glog --no-merges"
alias glogs="git log --pretty=format:'%h%x09%an%x09%ad%x09%s'"
alias glogref="git log --reflog" # git reflog
# Merge
alias gm="git merge"
alias gmum="git merge upstream/main"
alias gms="git merge --squash"
alias gpo="git fetch origin; git pull origin"
alias gpu="git fetch upstream; git pull upstream"
# Push
alias gpsuo="git push --set-upstream origin"
# Remotes
alias gr="git remote"
alias grv="git remote -v"
alias grfull="git rev-parse --abbrev-ref --symbolic-full-name @{u}"
#alias grtoall="git branch -vv"
#alias grtoone="git status -sb"
# Remotes - Prune
alias grp="git remote prune"
alias grpo="grp origin"
# Stash
alias gsa="git stash apply" # Add numeric index (0, ...)
alias gsl="git stash list"
# ------------------------------------------------------------------------------------------------------------------------------------- Keys
# List GPG keys with external tool 'SMIMEsign'
alias gpgkeys="smimesign --list-keys"
# ------------------------------------------------------------------------------------------------------------------------------------ MySQL
# Add parameters: [DB name, -p]
alias mysqlu="mysql -u"
# -------------------------------------------------------------------------------------------------------------------------------------- PHP
# Test if SOAP is running on PHP server
alias phphassoap="php -i | grep Soap"
# phpinfo + Config file path
alias phpi="php -i"
alias phpini="php -i | grep php.ini"
alias phpinidir="php-config --ini-dir"
# ---------------------------------------------------------------------------------------------------------------------------------- Symfony
# CLI
alias symcon="php bin/console"
# Setup
alias symsetupca="symfony.exe server:ca:install"
# Server
alias symson="symfony server:start"
alias symsoff="symfony server:stop"
# Caches
alias symcsys="php bin/console cache:clear"
alias symcall="php bin/console cache:pool:clear cache.global_clearer"
# Doctrine
alias docmkmig="php bin/console make:migration"
alias docdbc="php bin/console doctrine:database:create"
alias docmig="php bin/console doctrine:migrations:migrate"
alias docqueryvar="php bin/console doctrine:query:sql 'SHOW VARIABLES'"
# Debug
alias symdbginf="php bin/console about" # Show Symfony, Kernel, PHP versions + other details
alias symdbgevt="php bin/console debug:event-dispatcher kernel.controller" # Show events
alias symdbgsec="php bin/console debug:config security" # Security config
alias symdbgcnt="php bin/console debug:container" # Inject containers (e.g. 'monolog.logger')
alias symdbgsrv="php bin/console debug:autowiring" # Show Services + Use cases
# Security - Check packages (needs to be installed)
alias symchksec="symfony check:security"
# ---------------------------------------------------------------------------------------------------------------------------------- Vagrant
# General
# alias vgrdst="vagrant destroy"
alias vgrh="vagrant halt"
alias vgrsh="vagrant ssh"
alias vgru="vagrant up"
# Boxes
alias vgrbl="vagrant box list"
# Update
alias vgrupv="vagrant up --provision"
alias vgrrl="vagrant reload"
# Management
alias vgrst="vagrant global-status"
alias vgrstpr="vagrant global-status -prune"
# -------------------------------------------------------------------------------------------------------------- Laravel Homestead
# Sync folders manually (even if outside Homestead)
alias vgrrs="vagrant rsync"
# Sync folders automatically (only if project is in Homestead folder)
alias vgrrsa="vagrant rsync-auto --no-rsync-chown"
# ----------------------------------------------------------------------------------------------------------------------------------- Xdebug
alias logxd="tail -f /var/log/xdebug/xdebug.log"
# ------------------------------------------------------------------------------------------------------------------------------------- Yarn
alias ydev="yarn dev"
alias ydevsrv="yarn dev-server"
# ---------------------------------------------------------------------------------------------------------------------------------- HELPERS
# Reload Bash config
# Warning: Adds new commands to exisiting old ones!
alias rcfg="source ~/.bashrc"
# Clean unneeded OS-specific dot-files like '._*'.
# Especially useful in encrypted containers + Cloud storage synchronisation
# - https://coderwall.com/p/yf7yjq/clean-up-osx-dotfiles
alias sweephidden="find . -type f -name '._*' -delete"
# -------------------------------------------------------------------------------------------------------------------------- Tools
# List GPG keys with external tool 'SMIMEsign'
alias gpgkeys="smimesign --list-keys"
# ----------------------------------------------------------------------------------------------------------------------------------- SYSTEM
# Search functions (configurable)
alias gl="grep -lir"
# Go to previous folders
# 1) Just move
# 2) Show folder+file index
alias c1c="cd .."
alias c2c="cd ..; cd .."
alias c3c="cd ..; cd ..; cd .."
alias c1="cd ..; ll"
alias c2="cd ..; cd ..; ll"
alias c3="cd ..; cd ..; cd ..; ll"
# CHMOD fixes
# Example issue: php 'require' fails (either user or this)
alias chfiles="chmod -R 0644"
alias chfolders="chmod -R 0755"
# - Clear current view (keep history)
# - Clear all of view (delete history)
alias cls="clear"
alias c="clear"
alias res="reset"
# View
alias ll="ls -al"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment