Last active
February 13, 2017 14:54
-
-
Save calbertts/f7b63feee855bfe1bfe341e5d3868a91 to your computer and use it in GitHub Desktop.
Stops and/or removes a docker container
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
# Stops and/or removes a docker container | |
stopc() { | |
export FZF_DEFAULT_OPTS='--height 90% --reverse --border' | |
local container=$(docker ps --format '{{.Names}} => {{.Image}}' | fzf-tmux --reverse --multi | awk -F '\\=>' '{print $1}') | |
if [[ $container != '' ]]; then | |
echo -e "\n \033[1mDocker container:\033[0m" $container | |
printf " \033[1mRemove?: \033[0m" | |
local cmd=$(echo -e "No\nYes" | fzf-tmux --reverse --multi) | |
if [[ $cmd != '' ]]; then | |
if [[ $cmd == 'No' ]]; then | |
echo -e "\n Stopping $container ...\n" | |
history -s stopc | |
history -s docker stop $container | |
docker stop $container > /dev/null | |
else | |
echo -e "\n Stopping $container ..." | |
history -s stopc | |
history -s docker stop $container | |
docker stop $container > /dev/null | |
echo -e " Removing $container ...\n" | |
history -s stopc | |
history -s docker rm $container | |
docker rm $container > /dev/null | |
fi | |
fi | |
fi | |
export FZF_DEFAULT_OPTS="" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment