Last active
December 30, 2023 06:54
-
-
Save rithask/51d263f5d10ffa25b1794fc27fc423ad to your computer and use it in GitHub Desktop.
Docker aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -r -d '' aliases << EOM | |
alias dps="docker ps" | |
alias dcu="docker compose up -d" | |
alias dcd="docker compose down" | |
alias dcf="docker compose up -d --force-recreate" | |
alias dcl="docker compose logs -f" | |
alias dcp="docker compose pull" | |
alias dsp="docker system prune --all" | |
alias dstats='docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"' | |
alias dkps="docker ps --format '{{.ID}} ~ {{.Names}} ~ {{.Status}} ~ {{.Image}}'" | |
EOM | |
# Check the SHELL environment variable | |
current_shell=$SHELL | |
# if the shell is bash or zsh, then add the aliases to the .bashrc or .zshrc file | |
if [ "$current_shell" = "/bin/bash" ]; then | |
echo "Your current shell is bash" | |
file=~/.bashrc | |
elif [ "$current_shell" = "/bin/zsh" ]; then | |
echo "Your current shell is zsh" | |
file=~/.zshrc | |
else | |
echo "Your current shell is not bash or zsh" | |
exit 1 | |
fi | |
if ! grep -q "Docker aliases - rithask" "$file"; then | |
echo "Adding aliases to $file" | |
echo "" >>"$file" | |
echo "# Docker aliases - rithask" >>"$file" | |
echo "$aliases" >>"$file" | |
echo "Done" | |
echo -n "Do you want to reload your shell? (y/n) [default: y] " | |
read -r reload_shell | |
if [ "$reload_shell" = "y" ] || [ -z "$reload_shell" ]; then | |
exec "$current_shell" | |
fi | |
else | |
echo "Aliases already added to $file" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment