Browse Source

cleanup and improvements to docker_shim

master
ojizero 2 years ago
parent
commit
b406293817
  1. 36
      .docker_shims.zsh
  2. 4
      .zshrc

36
.docker_shims.zsh

@ -6,6 +6,20 @@ function docker-into { @@ -6,6 +6,20 @@ function docker-into {
eval "/usr/bin/env docker ${dopts} run -it --rm --volume "${_path}:${_path}" --workdir "${_path}" ${args}"
}
function docker-run {
local dopts="${1}"
local args="${2}"
if [[ "${args}" = *'--no-rm'* ]]; then
# --no-rm isn't a real flag so we remove it
args=$(echo "${args}" | sed -e 's/--no-rm//g')
elif [[ "${args}" != *'--rm'* ]]; then
args="--rm ${args}"
fi
eval "/usr/bin/env docker ${dopts} run ${args}"
}
function docker-build {
local dopts="${1}"
local args="${2}"
@ -22,7 +36,10 @@ function docker-build { @@ -22,7 +36,10 @@ function docker-build {
args="--tag ${default_tag} ${args}"
fi
if [[ "${args}" != *'--force-rm'* ]] && [[ "${args}" != *'--no-force-rm'* ]]; then
if [[ "${args}" = *'--no-force-rm'* ]]; then
# --no-force-rm isn't a real flag so we remove it
args=$(echo "${args}" | sed -e 's/--no-force-rm//g')
elif [[ "${args}" != *'--force-rm'* ]]; then
args="--force-rm ${args}"
fi
@ -44,6 +61,9 @@ function docker-build { @@ -44,6 +61,9 @@ function docker-build {
caches="${caches} --cache-from ${target_tag}"
done
else
# --no-progressive-build isn't a real flag so we remove it
args=$(echo "${args}" | sed -e 's/--no-progressive-build//g')
fi
eval "/usr/bin/env docker ${dopts} build ${caches} ${args}"
@ -81,12 +101,24 @@ function docker { @@ -81,12 +101,24 @@ function docker {
shift
;;
--no-shim)
__no_shim='__true__'
shift
echo 'The command will be run as is without Shim function intervening' >&2
;;
*)
break
;;
esac
done
if [[ "${__no_shim}" = '__true__' ]]; then
echo "Evaluating the command [[ /usr/bin/env docker ${dopts} ${@} ]] as is" >&2
eval "/usr/bin/env docker ${dopts} ${@}"
return $?
fi
if [[ $# -eq 0 ]]; then
eval "/usr/bin/env docker ${dopts} --help"
@ -110,6 +142,8 @@ function docker { @@ -110,6 +142,8 @@ function docker {
;;
bld|build) docker-build "${dopts}" "${@}"
;;
run) docker-run "${dopts}" "${@}"
;;
net) eval "/usr/bin/env docker ${dopts} network ${@}"
;;
ctx) eval "/usr/bin/env docker ${dopts} context ${@}"

4
.zshrc

@ -36,14 +36,16 @@ source "$(dirname $(readlink "${ZSH_PROFILE}"))/.docker_shims.zsh" @@ -36,14 +36,16 @@ source "$(dirname $(readlink "${ZSH_PROFILE}"))/.docker_shims.zsh"
alias f='\fuck'
alias k='\kubectl'
if type gls > /dev/null; then
alias ls='\gls -G --color=auto'
alias l='\gls -lhA --color=auto --group-directories-first'
alias ls='\gls -lhA --color=auto --group-directories-first'
else
alias l='\ls -lhA'
alias ls='\ls -lhA'
fi
alias d='\dirs -v'
alias p='\pushd'
alias pp='\popd'
alias tf='\terraform'
alias mkdir='\mkdir -vp'
alias ipglobal='\dig +short myip.opendns.com @resolver1.opendns.com'
alias nsenter='\docker run -it --rm --privileged --pid=host justincormack/nsenter1'

Loading…
Cancel
Save