various (failed) attempts at optimisation
This commit is contained in:
parent
35763c7b26
commit
0927f955e4
77
t.sh
77
t.sh
|
@ -51,6 +51,7 @@ function usage() {
|
|||
echo " -c Select calendar to use (use '$0 showcals' to list)"
|
||||
echo " -f Assume 'yes' to all questions."
|
||||
echo " -l xx Specify name of local vdirsyncer storage name (default: $DEFAULT_VDS_LOCAL)"
|
||||
echo " -p Enable profiling"
|
||||
echo " -r xx Specify name of remote vdirsyncer storage name (default: $DEFAULT_VDS_REMOTE)"
|
||||
echo " -s Auto-sync with server when complete."
|
||||
echo " -S Sort tasks and subtasks alphabetically"
|
||||
|
@ -89,20 +90,14 @@ function getuid_witherror() { # [noun]
|
|||
}
|
||||
|
||||
function getid() {
|
||||
local res id uid
|
||||
uid=$1
|
||||
res=""
|
||||
local res="" id
|
||||
for id in ${!idmap[@]}; do
|
||||
if [[ ${idmap[$id]} == $uid ]]; then
|
||||
res=${id}
|
||||
break
|
||||
if [[ ${idmap[$id]} == $1 ]]; then
|
||||
echo "$id"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
echo $res
|
||||
if [[ -z $res ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
function getuid() {
|
||||
|
@ -123,19 +118,24 @@ function loadids() {
|
|||
error "No ID file found (looking here: $idfile)"
|
||||
return 1
|
||||
fi
|
||||
profile "start"
|
||||
max=0
|
||||
while read LINE; do
|
||||
uid=${LINE%:*}
|
||||
id=${LINE#*:}
|
||||
#uid=$(echo "$LINE" | sed 's/:.*$//g')
|
||||
#id=$(echo "$LINE" | sed 's/^.*://g')
|
||||
idmap[$id]=$uid
|
||||
if [[ -z $uid || -z $id ]]; then
|
||||
error "invalid idmapping line: '$LINE'"
|
||||
profile "end"
|
||||
return 1
|
||||
fi
|
||||
[[ $id -gt $max ]] && max=$id
|
||||
count=$((count + 1))
|
||||
done < "$idfile"
|
||||
nextid=$((max + 1))
|
||||
profile "end"
|
||||
dblog "got $count IDs from $idfile"
|
||||
return 0
|
||||
}
|
||||
|
@ -173,6 +173,7 @@ function dumpids() {
|
|||
function loadtasks() {
|
||||
local f ess x thislev par parid show thissum thisdesc
|
||||
local verbose=0
|
||||
profile "start"
|
||||
maxid=-1
|
||||
maxindent=-1
|
||||
maxtaskwidth=-1
|
||||
|
@ -187,13 +188,14 @@ function loadtasks() {
|
|||
ntasks=$((ntasks + 1))
|
||||
done
|
||||
numwid=${#maxid}
|
||||
profile "finished loadtask calls"
|
||||
|
||||
dblog "Calculating max indent level"
|
||||
# figure out max indent level
|
||||
for x in ${!taskuid[@]}; do
|
||||
show=1
|
||||
par=${taskparent[$x]}
|
||||
if [[ ! -z $par ]]; then
|
||||
if [[ -n $par ]]; then
|
||||
parid=$(getid $par)
|
||||
if [[ ${taskfolded[$parid]} -eq 1 ]]; then
|
||||
show=0
|
||||
|
@ -212,10 +214,12 @@ function loadtasks() {
|
|||
dblog " ->sum: $thissum"
|
||||
fi
|
||||
done
|
||||
profile "got max indent"
|
||||
|
||||
[[ $ntasks -eq 1 ]] && ess="" || ess="s"
|
||||
[[ $verbose -eq 1 ]] && inform "Finished loading $ntasks task$ess."
|
||||
dblog "Finished loading $ntasks task$ess."
|
||||
profile "end"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -259,34 +263,25 @@ function confirm() {
|
|||
function loadtask() {
|
||||
local uid sum checked folded desc file id parent res i cats
|
||||
local blockreason
|
||||
#local re
|
||||
|
||||
#if iscached "$1"; then
|
||||
#fi
|
||||
|
||||
dblog "open $1"
|
||||
file="$1"
|
||||
res=$(cat "$file" | awk -F: 'BEGIN { checked=0; folded=0; } /^UID:/ { printf("uid©%s©",$2); } /^SUMMARY:/ { sub("SUMMARY:",""); printf("sum©%s©",$0); } /^CATEGORIES:/ { sub("^CATEGORIES:",""); printf("cats©%s©",$0); } /^DESCRIPTION:/ { sub("DESCRIPTION:",""); printf("desc©%s©",$0); } /^REQUEST-STATUS:4.1;/ { sub("REQUEST-STATUS:4.1;",""); printf("breason©%s©",$0);} /^RELATED-TO/ { sub("^RELATED-TO.*:",""); printf("parent©%s©",$0); } /^X-OC-HIDESUBTASKS:1/ { folded=1; } /^STATUS:/ { stat=substr($0,8); if (stat == "COMPLETED") { checked=2; } else if (stat == "NEEDS-inform") { checked=3; } else if (stat == "IN-PROCESS") { checked = 1 } } END { printf("checked©%d©folded©%d\n",checked,folded); }')
|
||||
|
||||
|
||||
|
||||
toadd2="REQUEST-STATUS:4.1;$reason"
|
||||
#re="^(CATEGORIES:|DESCRIPTION:|REQUEST-STATUS:4.1;|RELATED-TO|X-OC-HIDESUBTASKS:1|STATUS:)"
|
||||
res=$(cat "$file" | mawk -F: 'BEGIN { checked=0; folded=0; } /^UID:/ { printf("uid©%s©",$2); } /^SUMMARY:/ { sub("SUMMARY:",""); printf("sum©%s©",$0); } /^CATEGORIES:/ { sub("^CATEGORIES:",""); printf("cats©%s©",$0); } /^DESCRIPTION:/ { sub("DESCRIPTION:",""); printf("desc©%s©",$0); } /^REQUEST-STATUS:4.1;/ { sub("REQUEST-STATUS:4.1;",""); printf("breason©%s©",$0);} /^RELATED-TO/ { sub("^RELATED-TO.*:",""); printf("parent©%s©",$0); } /^X-OC-HIDESUBTASKS:1/ { folded=1; } /^STATUS:/ { stat=substr($0,8); if (stat == "COMPLETED") { checked=2; } else if (stat == "NEEDS-inform") { checked=3; } else if (stat == "IN-PROCESS") { checked = 1 } } END { printf("checked©%d©folded©%d\n",checked,folded); }' )
|
||||
|
||||
toadd2="REQUEST-STATUS:4.1;$reason"
|
||||
IFS='©'
|
||||
read -ra tok <<< "$res"
|
||||
parent=""
|
||||
i=0
|
||||
#dblog "res: '$res'"
|
||||
#for x in ${!tok[@]}; do
|
||||
#dblog "forloop tok $x is '${tok[$x]}'"
|
||||
#done
|
||||
# while [[ ! -z ${tok[$i]} ]]; do
|
||||
#dblog "tok $i is '${tok[$i]}'"
|
||||
# i=$((i + 1))
|
||||
# done
|
||||
while [[ ! -z ${tok[$i]} ]]; do
|
||||
dblog "process token '${tok[$i]}'"
|
||||
if [[ ${tok[$i]} == "uid" ]]; then
|
||||
uid=${tok[$((i + 1))]}
|
||||
#nexti=$((i + 1))
|
||||
#dblog "i=$i tok[i]=${tok[$i]} i+1=$((i + 1)) tok[i+1]=${tok[$((i + 1))]} uid $uid id $id"
|
||||
#dblog "i=$i tok[i]=${tok[$i]} i+1=$((i + 1)) tok[nexti]=${tok[$nexti]} uid $uid id $id"
|
||||
id=$(getid $uid)
|
||||
if [[ -z $id ]]; then
|
||||
id=$nextid
|
||||
|
@ -294,7 +289,6 @@ dblog "process token '${tok[$i]}'"
|
|||
nextid=$((nextid + 1))
|
||||
needsave=1
|
||||
fi
|
||||
#dblog "i=$i tok[i]=${tok[$i]} uid $uid id $id"
|
||||
elif [[ ${tok[$i]} == "sum" ]]; then
|
||||
sum="${tok[$((i + 1))]}"
|
||||
elif [[ ${tok[$i]} == "cats" ]]; then
|
||||
|
@ -344,9 +338,25 @@ dblog "process token '${tok[$i]}'"
|
|||
echo "$res"
|
||||
return 1
|
||||
fi
|
||||
# cache it
|
||||
#cachetask "$file"
|
||||
return 0
|
||||
}
|
||||
|
||||
function cachetask() { #1=cardfile
|
||||
stat -f "%Uc" "$1" >${cachedir}/$(basename "$1")
|
||||
}
|
||||
|
||||
function iscached() { #1=cardfile
|
||||
local changetime cachetime
|
||||
changetime=$(stat -f "%Uc" "$1")
|
||||
cachetime=$(cat ${cachedir}/$(basename "$1"))
|
||||
if [[ $changetime -eq $cachetime ]]; then
|
||||
return 1;
|
||||
fi
|
||||
return 0;
|
||||
}
|
||||
|
||||
function marknotdone() {
|
||||
local id uid rv file sedrv
|
||||
local children childuid ischild noun
|
||||
|
@ -717,6 +727,7 @@ function sedmod() { # sedmod uid 'sed command'
|
|||
if [[ $sedscript =~ ^s\/.*\/.*\/.*$ ]]; then
|
||||
one=$(echo "$sedscript" | awk -F/ '{ print $2 }')
|
||||
two=$(echo "$sedscript" | awk -F/ '{ print $3 }')
|
||||
# ooo
|
||||
cur=${cur/$one/$BOLD$STRIKE$RED$one^p^b}
|
||||
new=${new/$two/$BOLD$GREEN$two^b}
|
||||
fi
|
||||
|
@ -1617,6 +1628,7 @@ DEFAULT_VDS_LOCAL=cal_local
|
|||
DEFAULT_VDS_REMOTE=cal_remote
|
||||
basedir=/Users/rpearce/code/task_cli
|
||||
confdir="${HOME}/.task_cli"
|
||||
cachedir="${confdir}/cache"
|
||||
allcalsdir="$confdir/allcals" # symlink to vdirsyncer/calendar/
|
||||
defaultcalfile="$confdir/defaultcal"
|
||||
idfile="$confdir/idmappings"
|
||||
|
@ -1661,6 +1673,8 @@ addcmd "view" "view <id>" "Show detailed info for given task" "v|view|info|vcal"
|
|||
addcmd "showcals" "showcals" "List available calendars" "cals|showcals|cls" PASSIVE
|
||||
addcmd "setcal" "setcal" "Set the default calendar." "setcal|sc"
|
||||
|
||||
[[ ! -e $cachedir ]] && mkdir -p "$cachedir"
|
||||
|
||||
DEBUG=0
|
||||
TESTMODE=0
|
||||
AUTOSYNC=0
|
||||
|
@ -1668,7 +1682,7 @@ CALID=$(cat "$confdir/defaultcal")
|
|||
WANTSORT=0
|
||||
USEPAGER=1
|
||||
|
||||
ARGS="fhic:dnsStyl:r:"
|
||||
ARGS="fhic:dnsStyl:r:p"
|
||||
while getopts "$ARGS" i; do
|
||||
case "$i" in
|
||||
h)
|
||||
|
@ -1688,6 +1702,9 @@ while getopts "$ARGS" i; do
|
|||
n)
|
||||
USEPAGER=0
|
||||
;;
|
||||
p)
|
||||
__PROFILE=1
|
||||
;;
|
||||
r)
|
||||
VDS_REMOTE="$OPTARG"
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue