Created
May 20, 2016 13:17
-
-
Save flatcap/9c2af67aaceec6ba5490a208dee8d0b8 to your computer and use it in GitHub Desktop.
Conditional Dates Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: