Skip to content

Commit b548468

Browse files
authored
Optional dmenu support in sndev (#2603)
If dmenu is installed, `sndev start` will now prompt the user to select which profiles should be used with docker-compose. However, this means COMPOSE_PROFILES in .env.local is now ignored during `sndev start` if dmenu is installed, but not during `sndev delete`. This means that `sndev delete` would not delete containers previously started by `sndev start` anymore. To fix this, and since I think this is what it should have done anyway, `sndev delete` now also ignores COMPOSE_PROFILES from .env.local and always deletes all containers instead.
1 parent 8c045c5 commit b548468

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

sndev

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,35 @@ docker__exec() {
3939
sndev__start() {
4040
shift
4141

42-
43-
4442
if [ $# -eq 0 ]; then
45-
docker__compose up --build
46-
exit 0
43+
if command -v dmenu > /dev/null 2>&1; then
44+
# use dmenu if installed to select a profile
45+
profiles=$(sndev__dmenu_profile)
46+
if [ -z "$profiles" ]; then
47+
exit 1
48+
fi
49+
COMPOSE_PROFILES="$profiles" docker__compose up --build
50+
else
51+
docker__compose up --build
52+
fi
53+
else
54+
docker__compose up "$@"
4755
fi
56+
}
4857

49-
docker__compose up "$@"
58+
sndev__dmenu_profile() {
59+
# dmenu allows to select multiple profiles with CTRL+Enter
60+
# in which case it will immediately write the selected profile to stdout
61+
# so we loop over each line of the output and add each profile to an array
62+
# to make sure we don't add duplicates
63+
profiles="minimal payments wallets email search images capture"
64+
selected=()
65+
while read -r sel; do
66+
if [[ ! " ${selected[*]} " =~ " ${sel} " ]]; then
67+
selected+=("$sel")
68+
fi
69+
done < <(echo "$profiles" | tr ' ' '\n' | dmenu)
70+
printf '%s,' "${selected[@]}" | sed 's/,$//'
5071
}
5172

5273
sndev__help_start() {
@@ -180,7 +201,7 @@ sndev__delete() {
180201
printf "this deletes containers, volumes, and orphans - are you sure? [y/N] "
181202
read -r answer
182203
if [ "$answer" = "y" ]; then
183-
docker__compose down --volumes --remove-orphans
204+
COMPOSE_PROFILES="*" docker__compose down --volumes --remove-orphans
184205
else
185206
echo "delete cancelled"
186207
fi

0 commit comments

Comments
 (0)