commit 15afc5c304f76d956590d7a3e2c0f3af591ac971 parent 0f0b25533cf78694f0ec5b7d72c993154ed7c696 Author: awy <awy@awy.one> Date: Tue, 23 Dec 2025 23:54:00 +0300 reorder function working now Diffstat:
| M | bin/aew | | | 36 | +++++++++++++++++++----------------- |
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/bin/aew b/bin/aew @@ -328,28 +328,30 @@ EOF } reorder() { - # This looks so fucking hard to port. I need to think. tempfile="$(mktemp -u)" + tmp_out="$(mktemp -u)" trap 'rm -f $tempfile' HUP INT QUIT TERM PWR EXIT echo "# Carefully reorder these accounts with the desired numbers in the first column. # DO NOT reorder rows or rename the accounts in the second column." >"$tempfile" - sed -n " - / i[0-9] / s?\(.* i\|'<sync.*/\|\.muttrc.*\)??g p - " "$muttrc" >>"$tempfile" + sed -n 's/^\[\(.*\)\]/\1/p' "$accountsconf" | nl -w1 -s' ' >>"$tempfile" ${EDITOR:-vim} "$tempfile" || exit 1 - sed -i -e 's/#.*//' -e '/^$/d' "$tempfile" - default="$(sort -n "$tempfile" | head -n 1)" - default="${default#* }" - sed -ibu " - /.* i[0-9] .*.muttrc/d - /^source.*accounts.*.muttrc/d - " "$muttrc" 2>/dev/null - rm -f "$muttrc"bu - awk -v a="$accdir" -v d="$default" ' BEGIN { print "source "a"/"d".muttrc" } - { - print "macro index,pager i"$1" '\''<sync-mailbox><enter-command>source "a"/"$2".muttrc<enter><change-folder>!<enter>;<check-stats>'\'' \"switch to "$2"\"" - } - ' "$tempfile" >>"$muttrc" + awk ' + /^\[/ { exit } + { print } + ' "$accountsconf" > "$tmp_out" + echo >> "$tmp_out" + sed -e 's/#.*//' -e '/^[[:space:]]*$/d' "$tempfile" > "${tempfile}.clean" + sort -n "${tempfile}.clean" > "${tempfile}.sorted" + while read -r idx email; do + awk -v acct="[$email]" ' + $0 == acct { inblock=1; print; next } + inblock && /^\[/ { exit } + inblock { print } + ' "$accountsconf" >> "$tmp_out" + echo >> "$tmp_out" + done < "${tempfile}.sorted" + awk 'NF{blank=0} !NF{blank++} blank<2' "$tmp_out" > "$accountsconf" + rm -f "${tempfile}.clean" "${tempfile}.sorted" } while getopts "rfpXlhodTYD:y:i:I:s:S:u:a:n:P:x:m:t:" o; do case "${o}" in