Last active
August 22, 2019 07:37
-
-
Save shaunmolloy/dab65a8eb5fdd3c602da92c41ed09a7d to your computer and use it in GitHub Desktop.
docker-ps - Filter docker ps by service to get url
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
#!/usr/bin/env bash | |
# docker-ps | |
# Filter docker ps by service to get url | |
if [ "$#" -gt 0 ] | |
then | |
copy="$(\ | |
docker ps | \ | |
grep -n $@ | \ | |
perl -lne 'print "$1" while /[, ]?(0\.0\.0\.0:[0-9]{1,})/g;' | \ | |
tail -n 1)" | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
# Copy to clipboard | |
if [ "$OSTYPE" == "linux-gnu" ] | |
then | |
# Linux | |
echo "$copy" | xclip -sel clip | |
elif [ "$OSTYPE" == "darwin18" ] | |
then | |
# Mac | |
echo "$copy" | pbcopy | |
fi | |
# Output to terminal | |
echo -e "${bold}Copied to clipboard:${normal}\n" | |
echo "$copy" | |
else | |
docker ps | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment