Skip to content

Instantly share code, notes, and snippets.

@shaunmolloy
Last active August 22, 2019 07:37
Show Gist options
  • Save shaunmolloy/dab65a8eb5fdd3c602da92c41ed09a7d to your computer and use it in GitHub Desktop.
Save shaunmolloy/dab65a8eb5fdd3c602da92c41ed09a7d to your computer and use it in GitHub Desktop.
docker-ps - Filter docker ps by service to get url
#!/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