Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created May 20, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flatcap/9c2af67aaceec6ba5490a208dee8d0b8 to your computer and use it in GitHub Desktop.
Save flatcap/9c2af67aaceec6ba5490a208dee8d0b8 to your computer and use it in GitHub Desktop.
Conditional Dates Generator
#!/bin/bash
TEST_LIST=()
FORMAT_LIST=()
IFS=""
while :; do
read -p "Test: " TEST
[ -z "$TEST" ] && break;
read -p "Format: " FORMAT
[ -z "$FORMAT" ] && break;
TEST_LIST+=("$TEST")
FORMAT_LIST+=("$FORMAT")
done
read -p "Default format: " DEF_FORMAT
FORMAT_LIST+=("$DEF_FORMAT")
TEST_INDEX=0
FORMAT_INDEX=0
STRING="%[${FORMAT_LIST[FORMAT_INDEX]}]"
: $((FORMAT_INDEX++))
while :; do
T="${TEST_LIST[TEST_INDEX]}"
F="${FORMAT_LIST[FORMAT_INDEX]}"
[ -n "$T" ] || break
[ -n "$F" ] || break
STRING="%<[$T?$STRING&%[$F]>"
: $((TEST_INDEX++))
: $((FORMAT_INDEX++))
done
echo
echo "index_format:"
echo -e "\t$STRING"
echo
@flatcap
Copy link
Author

flatcap commented May 20, 2016

Generate index_format strings for the Conditional Dates feature for NeoMutt.

Test can be an optional number followed by a letter: (y)ears, (m)onths, (w)eeks, (d)ays, (H)ours, (M)inutes.
The format string is compatible with strftime(3), e.g. "%d-%m-%Y" for "DD-MM-YYYY".
Enter an empty string to finish.

Example run:

$ ./date.sh
Test: d
Format: %H:%M 
Test: m
Format: %a %d 
Test: y
Format: %b %d
Test: 
Default format: %m/%y 

index_format:
    %<[y?%<[m?%<[d?%[%H:%M ]&%[%a %d]>&%[%b %d]>&%[%m/%y ]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment