Skip to content

Commit

Permalink
Added human friendly aliases and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bearlike committed Mar 25, 2022
1 parent 9c10435 commit 1d16d8a
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions bash/alias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# Human friendly aliases and functions

: ' Personal Aliases and Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
alias zshconfig="nano ~/.zshrc"
alias ohmyzsh="nano ~/.oh-my-zsh"
alias cls='clear' # Sometimes I forget I'm not in Windows
alias py='/bin/python3'

: ' File Operations Aliases and Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
file-p-x() { chmod +x "$@"; }
file-p-all() { sudo chmod 777 -R "$@"; }
file-own-me() { sudo chown "$USER":"$(id -g "$USER")" -R "$@"; }

# Create a backup copy of a file
file-bk() { cp -a "$1" "$1".backup; }

# Create a backup copy of a file with date
file-bk-date () { cp -a "$1" "$1"."$(date_ddmmyyyy)".backup; }

# Create a backup copy of a file with datetime
file-bk-timedate () { cp -a "$1" "$1"."$(date_hhmmssddmmyyyy)".backup ; }

: ' Networking Aliases and Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
# Show user ports with process names and IDs
alias net-find-uports="sudo netstat -tulpn"

# Show all IPs associated with host
alias net-ip="sudo hostname -I"

# Show all docker related aliases
net-alias() { _guide_alias_ "Net operations" "netstat\|hostname -I" }

: ' Docker Aliases and Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
# Docker Compose
alias d-c="docker-compose"

# Get latest container ID
alias d-l="docker ps -l -q"

# Get container process
alias d-ps="docker ps"

# Get process included stop container
alias d-pa="docker ps -a"

# Get images
alias d-i="docker images"

# Get container IP
alias d-ip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'"

# Run deamonized container, e.g., $dkd base /bin/echo hello
alias d-kd="docker run -d -P"

# Run interactive container, e.g., $dki base /bin/bash
alias d-ki="docker run -i -t -P"

# Execute interactive container, e.g., $dex base /bin/bash
alias d-ex="docker exec -i -t"

# Prune all unused Docker objects
alias d-cl="docker system prune"

# Stop all containers
d-stop-all() { docker stop $(docker ps -a -q) }

# Show all docker related aliases
d-alias() { _guide_alias_ "Docker" "docker" }

# Bash into a running container
# arg $1 : container name/id
d-bash() { docker exec -it $1 bash }

: ' User aliases ends here. Below are helpers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
# Helper: Text Formatting
underline=$(tput smul)
nounderline=$(tput rmul)
bold=$(tput bold)
normal=$(tput sgr0)

# Helper: function for alias index
# arg $1 : Title
# arg $2 : grep argument
_guide_alias_() {
printf "${underline}${1} aliases${nounderline}\n\n"
alias | grep $2 | sed "s/^\([^=]*\)=\(.*\)/\1 \t=> \2/" | sed "s/['|\']//g" | sort
}

0 comments on commit 1d16d8a

Please sign in to comment.