From 7136604b57edfc3f9fb3c77f9262ebca47a7bb03 Mon Sep 17 00:00:00 2001 From: con-f-use Date: Mon, 10 Dec 2018 15:03:10 +0100 Subject: [PATCH] Fix dependency of docker aliases on docker plugin Some of the docker aliases use functions found in the docker plugin. If the plugin is not enabled, these aliases do not work. This commit only defines the aliases if the plugin is enabled. Also changed: `dkelc` now creates an explicit login shell, has the synonym `dkbash` and uses no backticks. Reason: on some docker images the status as login-shell is not set automatically, which causes e.g. `/etc/bash.bashrc` and `/etc/profile` not to be loaded in these images. Note: There should be a convenience function in `lib/helpers.bash` that checks if a plugin is available/enabled/disabled. The if-statement if rather clonky. --- aliases/available/docker.aliases.bash | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/aliases/available/docker.aliases.bash b/aliases/available/docker.aliases.bash index 5606b619..59322b39 100644 --- a/aliases/available/docker.aliases.bash +++ b/aliases/available/docker.aliases.bash @@ -9,7 +9,6 @@ alias dkps='docker ps' # List running Docker containers alias dkpsa='docker ps -a' # List all Docker containers alias dki='docker images' # List Docker images alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers -alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container case $OSTYPE in darwin*|*bsd*|*BSD*) @@ -20,12 +19,17 @@ case $OSTYPE in ;; esac -alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers -alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image -alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments -alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz -alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID -alias dkelc='docker exec -it `dklcid` bash' # Enter last container (works with Docker 1.3 and above) +if [ ! -z "$(command ls "${BASH_IT}/$subdirectory/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then +# Function aliases from docker plugin: + alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container + alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers + alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image + alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments + alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz + alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID +fi +alias dkelc='docker exec -it $(dklcid) bash --login' # Enter last container (works with Docker 1.3 and above) +alias dkbash='dkelc' alias dkex='docker exec -it ' # Useful to run any commands into container without leaving host alias dkri='docker run --rm -i ' alias dkrit='docker run --rm -it '