You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.docker_shims.zsh 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. function docker-into {
  2. local dopts="${1}"
  3. local _path="${2}"
  4. local args="${3}"
  5. eval "/usr/bin/env docker ${dopts} run -it --rm --volume "${_path}:${_path}" --workdir "${_path}" ${args}"
  6. }
  7. function docker-build {
  8. local dopts="${1}"
  9. local args="${2}"
  10. local default_tag="$(basename ${PWD})"
  11. if [[ "${args}" != *'--help'* ]] || [[ "${args}" != *'-h'* ]]; then
  12. eval "/usr/bin/env docker ${dopts} build ${args}"
  13. return $?
  14. fi
  15. if [[ "${args}" != *'--tag'* ]] && [[ "${args}" != *'-t'* ]]; then
  16. args="--tag ${default_tag} ${args}"
  17. fi
  18. if [[ "${args}" != *'--force-rm'* ]] && [[ "${args}" != *'--no-force-rm'* ]]; then
  19. args="--force-rm ${args}"
  20. fi
  21. # TODO: loop and build each named target individually
  22. eval "/usr/bin/env docker ${dopts} build ${args}"
  23. }
  24. function docker {
  25. if [[ $# -eq 0 ]]; then
  26. docker-build "" "${PWD}"
  27. return $?
  28. fi
  29. ## Docker top level CLI options
  30. local dopts=''
  31. while true; do
  32. case "${1}" in
  33. --config\
  34. |-c|--context\
  35. |-H|--host\
  36. |-l|--log-level\
  37. |--tlscacert\
  38. |--tlscert\
  39. |--tlskey\
  40. )
  41. dopts="${dopts} ${1} ${2}"
  42. shift 2
  43. ;;
  44. -D|--debug\
  45. |-v|--version\
  46. |--tls\
  47. |--tlsverify\
  48. )
  49. dopts="${dopts} ${1}"
  50. shift
  51. ;;
  52. *)
  53. break
  54. ;;
  55. esac
  56. done
  57. if [[ $# -eq 0 ]]; then
  58. eval "/usr/bin/env docker ${dopts} --help"
  59. return $?
  60. fi
  61. local cmd="${1}"
  62. shift
  63. case "${cmd}" in
  64. into)
  65. local _path="${1}"
  66. shift
  67. docker-into "${dopts}" "${_path}" "${@}"
  68. ;;
  69. here) docker-into "${dopts}" "${PWD}" "${@}"
  70. ;;
  71. dive) eval "/usr/bin/env docker ${dopts} run --rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive -- ${@}"
  72. ;;
  73. nsenter|enter) eval "/usr/bin/env docker ${dopts} run --rm -it --privileged --pid=host justincormack/nsenter1"
  74. ;;
  75. bld|build) docker-build "${dopts}" "${@}"
  76. ;;
  77. net) eval "/usr/bin/env docker ${dopts} network ${@}"
  78. ;;
  79. ctx) eval "/usr/bin/env docker ${dopts} context ${@}"
  80. ;;
  81. ls) eval "/usr/bin/env docker ${dopts} images ${@}"
  82. ;;
  83. *) eval "/usr/bin/env docker ${dopts} ${cmd} ${@}"
  84. ;;
  85. esac
  86. return $?
  87. }