mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 02:35:38 +01:00
feat(plugin): propose dockolor
This commit is contained in:
parent
28aa676b74
commit
242e20a025
1 changed files with 73 additions and 0 deletions
73
plugins/dockolor/dockolor.plugin.sh
Executable file
73
plugins/dockolor/dockolor.plugin.sh
Executable file
|
|
@ -0,0 +1,73 @@
|
||||||
|
dockolor_has_awk() {
|
||||||
|
if command -v awk >/dev/null 2>&1; then
|
||||||
|
echo true
|
||||||
|
else
|
||||||
|
echo false
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
dockolor_colorize() {
|
||||||
|
docker ps "$@" --no-trunc | awk '
|
||||||
|
BEGIN {
|
||||||
|
RED = "\033[0;31m"
|
||||||
|
GREEN = "\033[0;32m"
|
||||||
|
YELLOW = "\033[1;33m"
|
||||||
|
RESET = "\033[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# skip the first line because it containt header
|
||||||
|
# reminder, NR > built-in var in awk
|
||||||
|
NR == 1 {
|
||||||
|
print $0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
# set the color in fc of the status
|
||||||
|
{
|
||||||
|
line = $0
|
||||||
|
lower = tolower(line)
|
||||||
|
if (lower ~ /up/ || lower ~ /running/) {
|
||||||
|
color = GREEN
|
||||||
|
} else if (lower ~ /paused/) {
|
||||||
|
color = YELLOW
|
||||||
|
} else if (lower ~ /exited/ || lower ~ /dead/) {
|
||||||
|
color = RED
|
||||||
|
} else {
|
||||||
|
color = RESET
|
||||||
|
}
|
||||||
|
printf "%s%s%s\n", color, line, RESET
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
|
dockolor_dps() {
|
||||||
|
if [ "$(dockolor_has_awk)" = false ]; then
|
||||||
|
echo "You have installed dockolor but you don't have awk installed"
|
||||||
|
docker ps "$@" --no-trunc
|
||||||
|
else
|
||||||
|
dockolor_colorize "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# main function
|
||||||
|
dockolor() {
|
||||||
|
dockolor_dps "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# if the user have the docker plugin loaded
|
||||||
|
# we remove the alias
|
||||||
|
# and replace it with the colored version of it
|
||||||
|
if alias dps >/dev/null 2>&1; then
|
||||||
|
unalias dps
|
||||||
|
fi
|
||||||
|
|
||||||
|
if alias dpsa >/dev/null 2>&1; then
|
||||||
|
unalias dpsa
|
||||||
|
fi
|
||||||
|
|
||||||
|
dps() {
|
||||||
|
dockolor_dps "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
dpsa() {
|
||||||
|
dockolor_dps -a "$@"
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue