-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathalias.sh
100 lines (77 loc) · 2.7 KB
/
alias.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
# @title: Alias and functions
# @description: 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) # skipcq: SH-2034
nounderline=$(tput rmul) # skipcq: SH-2034
bold=$(tput bold) # skipcq: SH-2034
normal=$(tput sgr0) # skipcq: SH-2034
# Helper: function for alias index
# arg $1 : Title
# arg $2 : grep argument
_guide_alias_() {
printf "%s%s aliases%s\n\n" "$underline" "$1" "$nounderline";
alias | grep "$2" | sed "s/^\([^=]*\)=\(.*\)/\1 \t=> \2/" | sed "s/['|\']//g" | sort;
} # skipcq: SH-1056