Browse Source

added docker wrapper function

master
ojizero 2 years ago
parent
commit
c6cf593a94
  1. 102
      .docker_shims.zsh
  2. 10
      .zshrc

102
.docker_shims.zsh

@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
function docker-into {
local dopts="${1}"
local _path="${2}"
local args="${3}"
zsh -c "/usr/bin/env docker ${dopts} run -it --rm --volume "${_path}:${_path}" --workdir "${_path}" ${args}"
}
function docker-build {
local dopts="${1}"
local args="${2}"
local default_tag="$(basename ${PWD})"
if [[ "${args}" != *'--help'* ]] || [[ "${args}" != *'-h'* ]]; then
zsh -c "/usr/bin/env docker ${dopts} build ${args}"
return $?
fi
if [[ "${args}" != *'--tag'* ]] && [[ "${args}" != *'-t'* ]]; then
args="--tag ${default_tag} ${args}"
fi
if [[ "${args}" != *'--force-rm'* ]] && [[ "${args}" != *'--no-force-rm'* ]]; then
args="--force-rm ${args}"
fi
# TODO: loop and build each named target individually
zsh -c "/usr/bin/env docker ${dopts} build ${args}"
}
function docker {
if [[ $# -eq 0 ]]; then
docker-build "" "${PWD}"
return $?
fi
## Docker top level CLI options
local dopts=''
while true; do
case "${1}" in
--config\
|-c|--context\
|-H|--host\
|-l|--log-level\
|--tlscacert\
|--tlscert\
|--tlskey\
)
dopts="${dopts} ${1} ${2}"
shift 2
;;
-D|--debug\
|-v|--version\
|--tls\
|--tlsverify\
)
dopts="${dopts} ${1}"
shift
;;
*)
break
;;
esac
done
if [[ $# -eq 0 ]]; then
zsh -c "/usr/bin/env docker ${dopts} --help"
return $?
fi
local cmd="${1}"
shift
case "${cmd}" in
into)
local _path="${1}"
shift
docker-into "${dopts}" "${_path}" "${@}"
;;
here) docker-into "${dopts}" "${PWD}" "${@}"
;;
bld|build) docker-build "${dopts}" "${@}"
;;
net) zsh -c "/usr/bin/env docker ${dopts} network ${@}"
;;
ctx) zsh -c "/usr/bin/env docker ${dopts} context ${@}"
;;
ls) zsh -c "/usr/bin/env docker ${dopts} images ${@}"
;;
*) zsh -c "/usr/bin/env docker ${dopts} ${cmd} ${@}"
;;
esac
return $?
}

10
.zshrc

@ -12,7 +12,13 @@ export ENABLE_CORRECTION="false" @@ -12,7 +12,13 @@ export ENABLE_CORRECTION="false"
plugins=(git z)
source $ZSH/oh-my-zsh.sh
source "${ZSH}/oh-my-zsh.sh"
# Define custom environment variables
#
export ZSH_PROFILE="${HOME}/.zshrc"
export DOTNET_CLI_TELEMETRY_OPTOUT=1
# Toolings
#
@ -22,6 +28,8 @@ eval "$(goenv init -)" @@ -22,6 +28,8 @@ eval "$(goenv init -)"
eval "$(rbenv init -)"
eval "$(thefuck --alias)"
source $(dirname $(readlink "${ZSH_PROFILE}"))/.docker_shims.zsh
# Aliases and functions
#

Loading…
Cancel
Save