Skip to content

Instantly share code, notes, and snippets.

@rms1000watt
Created March 22, 2019 20:55
Show Gist options
  • Save rms1000watt/d2dde576d0e82ad49841d73753297527 to your computer and use it in GitHub Desktop.
Save rms1000watt/d2dde576d0e82ad49841d73753297527 to your computer and use it in GitHub Desktop.
ryan script for general functionality on Darwin
#!/usr/bin/env bash
set -e
help() {
echo "Usage:
ryan container CONTAINER_NAME # Get container ID
" 1>&2
exit 1
}
cmd_container() {
if [[ -z $1 ]]; then
echo "ERROR: Container name not provided" 1>&2
help
fi
containerName=${1}
containerID="$(docker ps -a | grep ${containerName} | cut -d' ' -f1 | tr '\n' ' ')"
if sed 's/[[:blank:]]*$//' <<< "${containerID}" | grep -q '[[:space:]]'; then
echo "ERROR: Multiple container IDs found: containerName=${containerName} containerID=${containerID}" 1>&2
exit 1
fi
echo $containerID
}
case "$1" in
container)
cmd_container ${@:2};;
*)
help; exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment