From d48aafa1a139e792afb3516f5d313db94f71658d Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Mon, 22 Apr 2019 12:43:42 -0400 Subject: [PATCH] ls and delete work with accnums --- bin/mw | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/mw b/bin/mw index 1e6f79c..8e7f22a 100755 --- a/bin/mw +++ b/bin/mw @@ -12,6 +12,9 @@ sslcert="/etc/ssl/certs/ca-certificates.crt" mwconfig="$muttdir/mutt-wizard.muttrc" muttrc="$muttdir/muttrc" +getaccounts() { accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /g;s/\..*//" | sort -n)" ;} +list() { getaccounts && echo "$accounts" ;} + getprofiles() { \ unset msmtp_header msmtp_profile mutt_profile mbsync_profile printf "Creating profiles for \`%s\`..." "$title" @@ -148,7 +151,7 @@ EOF read -r login printf "\033[0m" [ -z "$login" ] && login="$fulladdr" - accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /g;s/\..*//" | sort -n)" + getaccounts for x in $(seq 1 9); do echo "$accounts" | grep "$x" || { export idnum="$x"; break ;}; done getpass getprofiles @@ -214,18 +217,11 @@ confirm() { printf "Do you want to to %s? [y/N]\\n\t" "$@" && read -r input && ! printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1 return 0 ;} -list() { numbered="$(find "$accdir" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | nl)" - echo "$numbered" - [ "$(echo "$numbered" | wc -l)" = 0 ] && printf "No configured accounts.\\n" && return 1 -} - pick() { printf "Select an accounts to %s:\\n" "$1" list - printf "\033[36m\t" read -r input - printf "\033[0m" [ -z "$input" ] && return 1 - title="$(echo "$numbered" | grep "$input" | awk '{print $2}')" + title="$(echo "$accounts" | grep "$input" | awk '{print $2}')" [ -z "$title" ] && printf "Invalid response." && return 1 return 0 ;}