From 757dadf04893a47d2bca98d6d2f1b23145723e1f Mon Sep 17 00:00:00 2001 From: lhark Date: Tue, 16 Apr 2019 12:45:41 -0400 Subject: [PATCH] [neomutt] Add error detection to account loading script --- config/neomutt/folder-hooks.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/config/neomutt/folder-hooks.sh b/config/neomutt/folder-hooks.sh index 30f4f96..cad0c62 100755 --- a/config/neomutt/folder-hooks.sh +++ b/config/neomutt/folder-hooks.sh @@ -1,14 +1,23 @@ #!/bin/sh +acc_dir="$HOME/.config/neomutt/accounts/" + # Select default account -find ~/.config/neomutt/accounts/ -name "*.mail" -printf "source '%p'\n" -quit +default="$(find "$acc_dir" -name "*.mail" -printf "source '%p'\n" -quit)" + +if [ -z "$default" ]; then + >&2 echo "No mail accounts found in $acc_dir" + exit 1 +fi + +printf '%s\n' "$default" # Order of the keys to use for the account switch macro chars="1234567890azertyuiopqsdfghjklmwxcvbn" i=1 # Setup folder hooks for all the accounts -for f in ~/.config/neomutt/accounts/*.mail; do +for f in "$acc_dir"*.mail; do account="$(basename -s '.mail' "$f")" printf 'folder-hook =%s '\''source %s'\''\n' "$account" "$f" key="$(printf '%s' "$chars" | cut -c "$i")"