Skip to content

Instantly share code, notes, and snippets.

@chooban
Created October 28, 2016 13:31
Show Gist options
  • Save chooban/ce9988c3239a4e5be753cd47e10bad3e to your computer and use it in GitHub Desktop.
Save chooban/ce9988c3239a4e5be753cd47e10bad3e to your computer and use it in GitHub Desktop.
#!/bin/bash
function dimg {
docker images $@ |
sed "s/ \+/;/g" |
column -s\; -t |
sed "1s/.*/\x1B[1m&\x1B[m/"
}
function docker_fit {
# docker fit output
docker $@ |
sed '
1s/ *NAMES$//g;
s/ *[a-z]\+_[a-z]\+$//g;
s/"\(.*\)"/\1/g;
s/ seconds/s/g;
s/ minutes/m/g;
s/ hours/h/g;
s/About a minute/1m/g;
s/About an hour/1h/g;
s/Exited (\([0-9]\+\)) \(.*\)ago/exit(\1)~\2/;
s/->/→/g
' |
sed "s/ \+/;/g" |
column -s\; -t |
sed "1s/.*/\x1B[1m&\x1B[m/"
}
function dlc {
# cache docker last container id DOCKER_CACHE
1>&2 docker ps -l
export DOCKER_CACHE=$(docker ps -lq)
}
function dlo {
if [[ -t 1 ]]; then
while read data; do
args+="$data"
done
docker logs $args
return
fi
if [[ $DOCKER_CACHE != "" ]]; then
docker logs $DOCKER_CACHE
return
fi
docker logs $@
}
alias dl='docker ps -lq'
alias dll='docker_fit ps -l'
alias dps='docker_fit ps -a'
alias docker-clean-exited-containers='docker ps -aqf status=exited | xargs -n1 docker rm'
alias docker-remove-untagged-images="docker rmi \$(docker images | grep \"^<none>\" | awk '{print $3}')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment