From 173fa0905ce4fb77264d27f470b7852b6d7e77f6 Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Tue, 25 Jan 2022 10:08:07 +0100 Subject: [PATCH] Fix naming of docker-env containers to only use valid names --- templates/zshrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/zshrc b/templates/zshrc index 0f6d8ef..36b3c96 100644 --- a/templates/zshrc +++ b/templates/zshrc @@ -152,8 +152,9 @@ function docker-env() { echo "Usage: docker-env [command]" return 1 else - index=$(docker ps -a --filter "name=docker-env-$1-*" --format '{% raw %}{{.Names}}{% endraw %}' | perl -e 'my $max = 0; while (<>) {my ($n) = $_ =~ /(\d+)$/; if ($n > $max) { $max = $n };}; print $max+1;') - docker run --rm --name "docker-env-$1-$index" -it -v "$(pwd):/work_dir" -w "/work_dir" "$1" "${2:-bash}" + name=$(echo -n $1| grep -Eo '^[^:]+') + index=$(docker ps -a --filter "name=docker-env-$name-*" --format '{% raw %}{{.Names}}{% endraw %}' | perl -e 'my $max = 0; while (<>) {my ($n) = $_ =~ /(\d+)$/; if ($n > $max) { $max = $n };}; print $max+1;') + docker run --rm --name "docker-env-$name-$index" -it -v "$(pwd):/work_dir" -w "/work_dir" "$1" "${2:-bash}" fi }