#!/bin/zsh
-info="$(egrep -o '(^|&)(i=)[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
-edit="$(egrep -o '(^|&)(e=)[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&e=')"
-search="$(egrep -o '(^|&)(s=).+(&|$)' <<<"${QUERY_STRING}" |sed -r 's:^&?s=::;s:\+: :g;s:%:\\x:g')"
-search="$(echo -e "${search}" |sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' |head -n1)"
-new="$(egrep -o '(^|&)(n=).+(&|$)' <<<"${QUERY_STRING}" |sed -r 's:^&?n=::;s:\+: :g;s:%:\\x:g')"
-new="$(echo -e "${new}" |sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' |head -n1)"
+info="$(sed -rn 's:(^|.*&)i=([0-9]{10}_[0-9]{3}).*|.*:\2:;s:&.*::' <<<"${QUERY_STRING}")"
+edit="$(sed -r 's:(^|.*&)e=([0-9]{10}_[0-9]{3}).*|.*:\2:;s:&.*::' <<<"${QUERY_STRING}")"
+search="$(sed -r 's:(^|.*&)s=(.*)|.*:\2:;s:&.*::;s:\+: :g;s:%:\\x:g' <<<"${QUERY_STRING}")"
+search="$(echo -e "${search}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
+new="$(sed -r 's:(^|.*&)n=(.*)|.*:\2:;s:&.*::;s:\+: :g;s:%:\\x:g' <<<"${QUERY_STRING}")"
+new="$(echo -e "${new}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
cat <<TasksEND
<div id="LEFT">
TasksEND
if [ -n "$search" ]; then
echo "<h1>Tasks search results for: $search</h1>"
- for each in $(grep -ile "$search" Tasks/<0000000000-9999999999>_<000-999>.task); do
+ for each in $(grep -ile "$search" Tasks/<0000000000-9999999999>_<000-999>); do
id=$(sed -r 's:^.*/::;s:.task$::' <<<$each)
- echo "<div class='search'><a href='#task_$id'><h2>$(date -d @$(cut -d_ -f1 <<<"$id"))</h2></a>"
+ echo "<div class='search'><a href='${SCRIPTNAME}?p=Tasks&i=$id'><h2>$(date -d @$(cut -d_ -f1 <<<"$id"))</h2></a>"
grep -C1 -ie "$search" "$each" |sed "s:$search:<b>&</b>:g;s:$:<br>:g"
echo '</div>'
done
TaskEnd
[ -z "$new" ] && stat -c '' Tasks/<0000000000-9999999999>_<000-999>.meta && for each in Tasks/<0000000000-9999999999>_<000-999>.meta(.om); do
- headline="$(egrep -x 'headline=.+' "$each" |sed 's:headline=::')"
- status="$(egrep -x 'status=.+' "$each" |sed 's:status=::')"
- section="$(egrep -x 'section=.+' "$each" |sed 's:section=::')"
- attendant="$(egrep -x 'attendant=.+' "$each" |sed 's:attendant=::')"
+ info="$(basename "$each" |sed 's:.meta$::')"
+ headline="$(sed -rn '/^headline=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
+ taskstatus="$(sed -rn '/^status=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
+ section="$(sed -rn '/^section=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
+ attendant="$(sed -rn '/^attendant=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
cat <<TasksEND
<div class="Task">
- <b>$headline</b><br>
- <span><b>Status:</b> $status</span>
- <span><b>Section:</b> $Section</span>
+ <a href="${SCRIPTNAME}?p=Tasks&i=${info}"><b>$headline</b></a><br>
+ <span><b>Status:</b> $taskstatus</span>
+ <span><b>Section:</b> $section</span>
<span><b>Attendant:</b> $attendant</span>
</div>
TasksEND