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