diff --git a/tests/t1300-ls.sh b/tests/t1300-ls.sh new file mode 100755 index 0000000..ca2d81e --- /dev/null +++ b/tests/t1300-ls.sh @@ -0,0 +1,515 @@ +#!/bin/sh +# + +test_description='list functionality + +This test checks various list functionality including +sorting, output filtering and line numbering. +' +. ./test-lib.sh + +TEST_TODO_=todo.cfg + +cat > todo.txt < "${TEST_TODO1_}" + +test_todo_session 'checking TODOTXT_SORT_COMMAND' <>> todo.sh ls +2 aaa zzz this line should be first. +3 bbb yyy this line should be second. +1 ccc xxx this line should be third. +-- +TODO: 3 of 3 tasks shown from $HOME/todo.txt + +>>> todo.sh -d "$TEST_TODO1_" ls +1 ccc xxx this line should be third. +3 bbb yyy this line should be second. +2 aaa zzz this line should be first. +-- +TODO: 3 of 3 tasks shown from $HOME/todo.txt +EOF + +# +# check the final filter +# +TEST_TODO2_=todo2.cfg +sed -e "s%^.*export TODOTXT_FINAL_FILTER=.*$%export TODOTXT_FINAL_FILTER=\"sed 's/^\\\(..\\\{20\\\}\\\).....*$/\\\1.../'\"%" "${TEST_TODO_}" > "${TEST_TODO2_}" + +test_todo_session 'checking TODOTXT_FINAL_FILTER' <>> todo.sh -d "$TEST_TODO2_" ls +2 aaa zzz this line s... +3 bbb yyy this line s... +1 ccc xxx this line s... +-- +TODO: 3 of 3 tasks shown from $HOME/todo.txt +EOF + +# +# check the p command line option +# +cat > todo.txt <>> todo.sh ls +01 (A) @con01 +prj01 -- Some project 01 task, pri A +02 (A) @con01 +prj02 -- Some project 02 task, pri A +03 (A) @con02 +prj03 -- Some project 03 task, pri A +04 (A) @con02 +prj04 -- Some project 04 task, pri A +05 (B) @con01 +prj01 -- Some project 01 task, pri B +06 (B) @con01 +prj02 -- Some project 02 task, pri B +07 (B) @con02 +prj03 -- Some project 03 task, pri B +08 (B) @con02 +prj04 -- Some project 04 task, pri B +09 (C) @con01 +prj01 -- Some project 01 task, pri C +10 (C) @con01 +prj02 -- Some project 02 task, pri C +11 (C) @con02 +prj03 -- Some project 03 task, pri C +12 (C) @con02 +prj04 -- Some project 04 task, pri C +13 (D) @con01 +prj01 -- Some project 01 task, pri D +14 (D) @con01 +prj02 -- Some project 02 task, pri D +15 (D) @con02 +prj03 -- Some project 03 task, pri D +16 (D) @con02 +prj04 -- Some project 04 task, pri D +17 @con01 +prj01 -- Some project 01 task, no priority +18 @con01 +prj02 -- Some project 02 task, no priority +19 @con02 +prj03 -- Some project 03 task, no priorty +20 @con02 +prj04 -- Some project 04 task, no priority +-- +TODO: 20 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -p ls +01 (A) @con01 +prj01 -- Some project 01 task, pri A +02 (A) @con01 +prj02 -- Some project 02 task, pri A +03 (A) @con02 +prj03 -- Some project 03 task, pri A +04 (A) @con02 +prj04 -- Some project 04 task, pri A +05 (B) @con01 +prj01 -- Some project 01 task, pri B +06 (B) @con01 +prj02 -- Some project 02 task, pri B +07 (B) @con02 +prj03 -- Some project 03 task, pri B +08 (B) @con02 +prj04 -- Some project 04 task, pri B +09 (C) @con01 +prj01 -- Some project 01 task, pri C +10 (C) @con01 +prj02 -- Some project 02 task, pri C +11 (C) @con02 +prj03 -- Some project 03 task, pri C +12 (C) @con02 +prj04 -- Some project 04 task, pri C +13 (D) @con01 +prj01 -- Some project 01 task, pri D +14 (D) @con01 +prj02 -- Some project 02 task, pri D +15 (D) @con02 +prj03 -- Some project 03 task, pri D +16 (D) @con02 +prj04 -- Some project 04 task, pri D +17 @con01 +prj01 -- Some project 01 task, no priority +18 @con01 +prj02 -- Some project 02 task, no priority +19 @con02 +prj03 -- Some project 03 task, no priorty +20 @con02 +prj04 -- Some project 04 task, no priority +-- +TODO: 20 of 20 tasks shown from $HOME/todo.txt +EOF + +# +# check the P,@,+ command line options +# +cat > todo.txt <>> todo.sh ls +01 (A) @con01 +prj01 -- Some project 01 task, pri A +02 (A) @con01 +prj02 -- Some project 02 task, pri A +03 (A) @con02 +prj03 -- Some project 03 task, pri A +04 (A) @con02 +prj04 -- Some project 04 task, pri A +05 (B) @con01 +prj01 -- Some project 01 task, pri B +06 (B) @con01 +prj02 -- Some project 02 task, pri B +07 (B) @con02 +prj03 -- Some project 03 task, pri B +08 (B) @con02 +prj04 -- Some project 04 task, pri B +09 (C) @con01 +prj01 -- Some project 01 task, pri C +10 (C) @con01 +prj02 -- Some project 02 task, pri C +11 (C) @con02 +prj03 -- Some project 03 task, pri C +12 (C) @con02 +prj04 -- Some project 04 task, pri C +13 (D) @con01 +prj01 -- Some project 01 task, pri D +14 (D) @con01 +prj02 -- Some project 02 task, pri D +15 (D) @con02 +prj03 -- Some project 03 task, pri D +16 (D) @con02 +prj04 -- Some project 04 task, pri D +17 @con01 +prj01 -- Some project 01 task, no priority +18 @con01 +prj02 -- Some project 02 task, no priority +19 @con02 +prj03 -- Some project 03 task, no priorty +20 @con02 +prj04 -- Some project 04 task, no priority +-- +TODO: 20 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh ls @con01 +01 (A) @con01 +prj01 -- Some project 01 task, pri A +02 (A) @con01 +prj02 -- Some project 02 task, pri A +05 (B) @con01 +prj01 -- Some project 01 task, pri B +06 (B) @con01 +prj02 -- Some project 02 task, pri B +09 (C) @con01 +prj01 -- Some project 01 task, pri C +10 (C) @con01 +prj02 -- Some project 02 task, pri C +13 (D) @con01 +prj01 -- Some project 01 task, pri D +14 (D) @con01 +prj02 -- Some project 02 task, pri D +17 @con01 +prj01 -- Some project 01 task, no priority +18 @con01 +prj02 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -P ls @con01 +01 @con01 +prj01 -- Some project 01 task, pri A +02 @con01 +prj02 -- Some project 02 task, pri A +05 @con01 +prj01 -- Some project 01 task, pri B +06 @con01 +prj02 -- Some project 02 task, pri B +09 @con01 +prj01 -- Some project 01 task, pri C +10 @con01 +prj02 -- Some project 02 task, pri C +13 @con01 +prj01 -- Some project 01 task, pri D +14 @con01 +prj02 -- Some project 02 task, pri D +17 @con01 +prj01 -- Some project 01 task, no priority +18 @con01 +prj02 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -+ ls @con01 +01 (A) @con01 -- Some project 01 task, pri A +02 (A) @con01 -- Some project 02 task, pri A +05 (B) @con01 -- Some project 01 task, pri B +06 (B) @con01 -- Some project 02 task, pri B +09 (C) @con01 -- Some project 01 task, pri C +10 (C) @con01 -- Some project 02 task, pri C +13 (D) @con01 -- Some project 01 task, pri D +14 (D) @con01 -- Some project 02 task, pri D +17 @con01 -- Some project 01 task, no priority +18 @con01 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -@ ls @con01 +01 (A) +prj01 -- Some project 01 task, pri A +02 (A) +prj02 -- Some project 02 task, pri A +05 (B) +prj01 -- Some project 01 task, pri B +06 (B) +prj02 -- Some project 02 task, pri B +09 (C) +prj01 -- Some project 01 task, pri C +10 (C) +prj02 -- Some project 02 task, pri C +13 (D) +prj01 -- Some project 01 task, pri D +14 (D) +prj02 -- Some project 02 task, pri D +17 +prj01 -- Some project 01 task, no priority +18 +prj02 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -P -@ ls @con01 +01 +prj01 -- Some project 01 task, pri A +02 +prj02 -- Some project 02 task, pri A +05 +prj01 -- Some project 01 task, pri B +06 +prj02 -- Some project 02 task, pri B +09 +prj01 -- Some project 01 task, pri C +10 +prj02 -- Some project 02 task, pri C +13 +prj01 -- Some project 01 task, pri D +14 +prj02 -- Some project 02 task, pri D +17 +prj01 -- Some project 01 task, no priority +18 +prj02 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -P -@ -+ -P -@ -+ ls @con01 +01 (A) @con01 +prj01 -- Some project 01 task, pri A +02 (A) @con01 +prj02 -- Some project 02 task, pri A +05 (B) @con01 +prj01 -- Some project 01 task, pri B +06 (B) @con01 +prj02 -- Some project 02 task, pri B +09 (C) @con01 +prj01 -- Some project 01 task, pri C +10 (C) @con01 +prj02 -- Some project 02 task, pri C +13 (D) @con01 +prj01 -- Some project 01 task, pri D +14 (D) @con01 +prj02 -- Some project 02 task, pri D +17 @con01 +prj01 -- Some project 01 task, no priority +18 @con01 +prj02 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt + +>>> todo.sh -P -@ -+ -P -@ -+ -P -@ -+ ls @con01 +01 -- Some project 01 task, pri A +02 -- Some project 02 task, pri A +05 -- Some project 01 task, pri B +06 -- Some project 02 task, pri B +09 -- Some project 01 task, pri C +10 -- Some project 02 task, pri C +13 -- Some project 01 task, pri D +14 -- Some project 02 task, pri D +17 -- Some project 01 task, no priority +18 -- Some project 02 task, no priority +-- +TODO: 10 of 20 tasks shown from $HOME/todo.txt +EOF + +# +# check the line number padding +# +cat > todo.txt <>> todo.sh ls +001 hex00 this is one line +002 hex01 this is another line +003 hex02 this is another line +004 hex03 this is another line +005 hex04 this is another line +006 hex05 this is another line +007 hex06 this is another line +008 hex07 this is another line +009 hex08 this is another line +010 hex09 this is another line +011 hex0A this is another line +012 hex0B this is another line +013 hex0C this is another line +014 hex0D this is another line +015 hex0E this is another line +016 hex0F this is another line +017 hex10 this is line is a multiple of 16 +018 hex11 this is another line +019 hex12 this is another line +020 hex13 this is another line +021 hex14 this is another line +022 hex15 this is another line +023 hex16 this is another line +024 hex17 this is another line +025 hex18 this is another line +026 hex19 this is another line +027 hex1A this is another line +028 hex1B this is another line +029 hex1C this is another line +030 hex1D this is another line +031 hex1E this is another line +032 hex1F this is another line +033 hex20 this is line is a multiple of 16 +034 hex21 this is another line +035 hex22 this is another line +036 hex23 this is another line +037 hex24 this is another line +038 hex25 this is another line +039 hex26 this is another line +040 hex27 this is another line +041 hex28 this is another line +042 hex29 this is another line +043 hex2A this is another line +044 hex2B this is another line +045 hex2C this is another line +046 hex2D this is another line +047 hex2E this is another line +048 hex2F this is another line +049 hex30 this is line is a multiple of 16 +050 hex31 this is another line +051 hex32 this is another line +052 hex33 this is another line +053 hex34 this is another line +054 hex35 this is another line +055 hex36 this is another line +056 hex37 this is another line +057 hex38 this is another line +058 hex39 this is another line +059 hex3A this is another line +060 hex3B this is another line +061 hex3C this is another line +062 hex3D this is another line +063 hex3E this is another line +064 hex3F this is another line +065 hex40 this is line is a multiple of 16 +066 hex41 this is another line +067 hex42 this is another line +068 hex43 this is another line +069 hex44 this is another line +070 hex45 this is another line +071 hex46 this is another line +072 hex47 this is another line +073 hex48 this is another line +074 hex49 this is another line +075 hex4A this is another line +076 hex4B this is another line +077 hex4C this is another line +078 hex4D this is another line +079 hex4E this is another line +080 hex4F this is another line +081 hex50 this is line is a multiple of 16 +082 hex51 this is another line +083 hex52 this is another line +084 hex53 this is another line +085 hex54 this is another line +086 hex55 this is another line +087 hex56 this is another line +088 hex57 this is another line +089 hex58 this is another line +090 hex59 this is another line +091 hex5A this is another line +092 hex5B this is another line +093 hex5C this is another line +094 hex5D this is another line +095 hex5E this is another line +096 hex5F this is another line +097 hex60 this is line is a multiple of 16 +098 hex61 this is another line +099 hex62 this is another line +100 hex63 this is another line +101 hex64 this is another line +102 hex65 this is another line +103 hex66 this is another line +104 hex67 this is another line +105 hex68 this is another line +106 hex69 this is another line +107 hex6A this is another line +108 hex6B this is another line +109 hex6C this is another line +110 hex6D this is another line +111 hex6E this is another line +112 hex6F this is another line +-- +TODO: 112 of 112 tasks shown from $HOME/todo.txt +EOF + +test_done diff --git a/todo.cfg b/todo.cfg index e41de59..051a7a6 100644 --- a/todo.cfg +++ b/todo.cfg @@ -52,4 +52,15 @@ export TMP_FILE="$TODO_DIR/todo.tmp" # === BEHAVIOR === ## customize list output +# +# TODOTXT_SORT_COMMAND will filter after line numbers are +# inserted, but before colorization, and before hiding of +# priority, context, and project. +# # export TODOTXT_SORT_COMMAND='env LC_COLLATE=C sort -f -k2' + +# TODOTXT_FINAL_FILTER will filter list output after colorization, +# priority hiding, context hiding, and project hiding. That is, +# just before the list output is displayed. +# +# export TODOTXT_FINAL_FILTER='cat' diff --git a/todo.sh b/todo.sh index a773375..04a9d1d 100755 --- a/todo.sh +++ b/todo.sh @@ -208,6 +208,7 @@ help() TODOTXT_VERBOSE=1 is same as option -v TODOTXT_DEFAULT_ACTION="" run this when called with no arguments TODOTXT_SORT_COMMAND="sort ..." customize list output + TODOTXT_FINAL_FILTER="sed ..." customize list after color, P@+ hiding EndHelp if [ -d "$TODO_ACTIONS_DIR" ] @@ -347,8 +348,9 @@ TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1} TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0} TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-} TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2} +TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat} -export TODOTXT_VERBOSE TODOTXT_PLAIN TODOTXT_CFG_FILE TODOTXT_FORCE TODOTXT_PRESERVE_LINE_NUMBERS TODOTXT_AUTO_ARCHIVE TODOTXT_DATE_ON_ADD TODOTXT_SORT_COMMAND +export TODOTXT_VERBOSE TODOTXT_PLAIN TODOTXT_CFG_FILE TODOTXT_FORCE TODOTXT_PRESERVE_LINE_NUMBERS TODOTXT_AUTO_ARCHIVE TODOTXT_DATE_ON_ADD TODOTXT_SORT_COMMAND TODOTXT_FINAL_FILTER # Default color map export NONE='' @@ -509,6 +511,7 @@ _list() { s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g ''' \ + | eval ${TODOTXT_FINAL_FILTER} \ ) echo -ne "$filtered_items${filtered_items:+\n}"