From ada594a30b77c9f4b733b48044a5e6dcb5b412a5 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 17 Sep 2020 05:59:36 +0400 Subject: [PATCH] dm: support des aliases --- lib/bashrc.d/docker_aliases.shared | 39 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/bashrc.d/docker_aliases.shared b/lib/bashrc.d/docker_aliases.shared index 6bab1fc..c6369fb 100644 --- a/lib/bashrc.d/docker_aliases.shared +++ b/lib/bashrc.d/docker_aliases.shared @@ -1,11 +1,40 @@ # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 if [ -n "$UTOOLS_DOCKER_ALIASES" ]; then - if [ "$DOCKER_MACHINE_WRAPPED" == true ]; then - alias dm=__docker_machine_wrapper - else - alias dm=docker-machine - fi + #if [ "$DOCKER_MACHINE_WRAPPED" == true ]; then + # alias dm=__docker_machine_wrapper + #else + # alias dm=docker-machine + #fi + function dm() { + if [ "$1" == use -a -n "$2" -a -f ~/etc/default/dk ]; then + # chercher les aliases éventuels + local machine="$2"; shift; shift + machine="$( + CLUSTERDIRS=() + source ~/etc/default/dk + for clusterdir in "${CLUSTERDIRS[@]}"; do + if [ -f "$clusterdir/0config/configure.conf" ]; then + DM_ALIASES=() + source "$clusterdir/0config/configure.conf" + for alias_machine in "${DM_ALIASES[@]}"; do + if [ "${alias_machine%%:*}" == "$machine" ]; then + echo "${alias_machine#*:}" + exit + fi + done + fi + done + echo "$machine" + )" + set -- use "$machine" "$@" + fi + if [ "$DOCKER_MACHINE_WRAPPED" == true ]; then + __docker_machine_wrapper "$@" + else + docker-machine "$@" + fi + } if [ -n "$UTOOLS_BASH_COMPLETION" ]; then complete -F _docker_machine dm