X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=cards%2Flist.sh;h=cd0d21f1e320aa958839b8fdbe75dec051286da9;hp=77c96b00019291f28066e0bf9d6123850ef9b13e;hb=79a7bb3560f305a48ecd2b2f2b9957c206fa6792;hpb=3ea5e66a2f2cac72cfde653f56330370e0b170de diff --git a/cards/list.sh b/cards/list.sh index 77c96b0..cd0d21f 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -121,11 +121,36 @@ print_cards(){ done } +filter_attendance(){ + fatt="$1" + attfile="$_DATA/mappings/attendance" + + if [ ! "$fatt" ]; then + # debug 'list all' + printf '%s\n' "$_DATA/vcard"/*.vcf + elif [ "${fatt#* }" = "${fatt}" ]; then + # debug "list $fatt" + grep -xiE "(${fatt}) .+vcf" "$attfile" \ + | while read vcf; do + printf '%s/vcard/%s\n' "$_DATA" "${vcf##* }" + done + else + # debug "filter ${fatt%% *}" + filter_attendance "${fatt#* }" \ + | while read vcf; do + grep -xiE "(${fatt%% *}) ${vcf##*/}" "$attfile" + done \ + | while read vcf; do + printf '%s/vcard/%s\n' "$_DATA" "${vcf##* }" + done + fi +} + filter_cards(){ local filter f fex='x;p;' filter="$(printf %s "${filter}" \ - | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\\\&;g; + | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\&;g; '"$upcase" )^" @@ -134,6 +159,8 @@ filter_cards(){ case $f in '') break ;; + COURSE:*) fatt="${fatt}${fatt:+ }${f#*:}" + ;; ANY:*) fex="/\n.*(\;[^:]*)?:[^\n]*(${f#*:})[^\n]*\r?\n/{${fex}}" ;; NAME:*) fex="/\n(N|FN|NICKNAME)(\;[^:]*)?:[^\n]*(${f#*:})[^\n]*\r?\n/{${fex}}" @@ -145,7 +172,8 @@ filter_cards(){ esac done - for cardfile in "${_DATA}"/vcard/*.vcf; do + # for cardfile in "${_DATA}"/vcard/*.vcf; do + filter_attendance "$fatt" |while read cardfile; do printf '%s\n' "$cardfile" cat "$cardfile" done \