From 084d259248589f688352bad2ec04a39d0a5d0321 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Mon, 27 Nov 2017 23:21:27 +0200
Subject: [PATCH] Docker aliases!

A new shell script, `wrapper`, that (similar to what git does) in case an
excutable of the format `command-subcommand` is available (command being
the name called, $0), calling `command subcommand` will be call
`command-subcommand`. For example: calling `docker dev` will call
`docker-dev` if such an executable exists. So now `docker` (in
`~/Documents/bin/` is a symlink to `wrapper`. Changed my docker shell
aliases to scripts.
---
 .bashrc                    | 20 +-------------------
 Documents/bin/docker       |  1 +
 Documents/bin/docker-Build |  3 +++
 Documents/bin/docker-dev   |  3 +++
 Documents/bin/wrapper      | 12 ++++++++++++
 5 files changed, 20 insertions(+), 19 deletions(-)
 create mode 120000 Documents/bin/docker
 create mode 100755 Documents/bin/docker-Build
 create mode 100755 Documents/bin/docker-dev
 create mode 100755 Documents/bin/wrapper

diff --git a/.bashrc b/.bashrc
index 15ab928..47b6dd5 100644
--- a/.bashrc
+++ b/.bashrc
@@ -52,7 +52,6 @@ alias ecr-login='eval $(aws ecr get-login)'
 alias hostlocal='docker run --rm --privileged --net=host gliderlabs/hostlocal'
 alias apt-daily="sudo /bin/sh -c 'apt-get update && apt-get dist-upgrade --download-only --yes && apt-get autoclean'"
 alias flatpak-daily='flatpak --user update --no-deploy'
-alias docker-build='docker build -t "$(basename $PWD)" ./'
 alias cdtemp='cd $(mktemp -d)'
 alias 0-day-cleanup='ssh xbmc.shore.co.il "sudo -u debian-transmission find /srv/library/Comics -name *.part -path *0-Day\ Week\ of* -delete"'
 alias httpbin='gunicorn httpbin:app'
@@ -73,7 +72,7 @@ alias clean-swp="find \$HOME/ -name '*.swp' -delete"
 alias unssh="ssh -o \"UserKnownHostsFile /dev/null\" -o \"StrictHostKeyChecking no\""
 alias todo="vim \$HOME/Documents/TODO.yml"
 alias sudo="sudo "
-alias presentation='docker run -itv "$PWD:/project" adarnimrod/presentation'
+alias presentation='docker dev adarnimrod/presentation'
 alias prune_prerun='find "$HOME" -maxdepth 1 -name ".prerun.*" -print0 | grep -zv "$(pgrep -u "$(id -u)" bash)" | xargs -0r rm '
 alias netdata='docker run --detach --name netdata --cap-add SYS_PTRACE --volume /proc:/host/proc:ro --volume /sys:/host/sys:ro --volume /var/run/docker.sock:/var/run/docker.sock --publish 19999:19999 firehol/netdata'
 alias json-tool='python3 -m json.tool'
@@ -102,23 +101,6 @@ gen_csr () {
     openssl req -new -newkey rsa:4096 -nodes -out "$1.csr" -keyout "$1.key"
 }
 
-docker_dev () {
-    local root repo uid
-    root="$(git rev-parse --show-toplevel)"
-    repo="$(basename "$root")"
-    uid="$(id -u)"
-    docker build -t "$repo:dev" "$root"
-    docker run --interactive \
-               --publish-all \
-               --name "$repo" \
-               --rm \
-               --tty \
-               --volume "$HOME:$HOME" \
-               --volume "$root:$root" \
-               --user "$uid" \
-               --workdir "$PWD" "$repo:dev" /bin/sh -l
-}
-
 sync_comics () {
     local this_month last_month format
     format='+xbmc.shore.co.il:/srv/library/Comics/0-Day\ Week\ of\ %Y.%m.*'
diff --git a/Documents/bin/docker b/Documents/bin/docker
new file mode 120000
index 0000000..22cb46f
--- /dev/null
+++ b/Documents/bin/docker
@@ -0,0 +1 @@
+wrapper
\ No newline at end of file
diff --git a/Documents/bin/docker-Build b/Documents/bin/docker-Build
new file mode 100755
index 0000000..dafc807
--- /dev/null
+++ b/Documents/bin/docker-Build
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+docker build -t "$(basename "$PWD")" ./
diff --git a/Documents/bin/docker-dev b/Documents/bin/docker-dev
new file mode 100755
index 0000000..9415795
--- /dev/null
+++ b/Documents/bin/docker-dev
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+docker run --rm -Pitv "$PWD:/volume" "$@"
diff --git a/Documents/bin/wrapper b/Documents/bin/wrapper
new file mode 100755
index 0000000..1b8af53
--- /dev/null
+++ b/Documents/bin/wrapper
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -eu
+
+basename="$(basename "$0")"
+command="$(env -i which "$basename")" || { echo "$basename: not found"; exit 127; }
+if alias="$(which "$basename-${1:-}")"
+then
+    shift
+    "$alias" "$@"
+else
+    "$command" "$@"
+fi
-- 
GitLab