fix spaces in file/dir/calendar names breaking several commands.

This commit is contained in:
Rob Pearce 2021-11-07 08:46:49 +11:00
parent 404839bd7a
commit 58bc83e53e
1 changed files with 53 additions and 53 deletions

106
t.sh
View File

@ -376,15 +376,15 @@ function marknotdone() {
error "$noun #${id} is already unfinished"
return 1
fi
file=$dir/$uid.vcf
sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:100/d' $file
file="$dir/$uid.vcf"
sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:100/d' "$file"
sedrv=$((sedrv + $?))
set_lastmodified $uid
sedrv=$((sedrv + $?))
if [[ $sedrv -eq 0 ]]; then
action "Marked $noun #${id} as unfinished."
processed="$processed ${uid} "
loadtask $file
loadtask "$file"
rv=0
children=$(getchildren $uid)
for childuid in ${children}; do
@ -445,8 +445,8 @@ function delq_process() {
if [[ $? -eq 0 ]]; then
count=0
for uid in $deluids; do
file=$dir/$uid.vcf
rm -f $file
file="$dir/$uid.vcf"
rm -f "$file"
id=$(getid $uid)
unset idmap[$id]
@ -467,9 +467,9 @@ function delq_process() {
function set_lastmodified() {
local uid file now
uid=$1
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
now=$(date -u +'%Y%m%dT%H%M%SZ')
sed -i "s/^LAST-MODIFIED:.*/LAST-MODIFIED:$now/" $file
sed -i "s/^LAST-MODIFIED:.*/LAST-MODIFIED:$now/" "$file"
return $?
}
@ -490,15 +490,15 @@ function move_left() { # move_left uid
parent2=${taskparent[$parentid]}
taskparent[$id]="$parent2"
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
sed -i "s/^RELATED-TO.*/RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}/" $file
sed -i "s/^RELATED-TO.*/RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}/" "$file"
sedrv=$?
set_lastmodified $uid
sedrv=$((sedrv + $?))
if [[ $sedrv -eq 0 ]]; then
action "Shifted task #${id} upwards/left."
loadtask $file
loadtask "$file"
showit ${taskparent[$id]} $uid
@ -528,18 +528,18 @@ function move_right() { # move_right uid new_parent
rv=0
taskparent[$id]="$newparent"
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
if [[ -z $newparent ]]; then
sed -i "/^RELATED-TO.*/d" $file
sed -i "/^RELATED-TO.*/d" "$file"
sedrv=$?
else
if grep -q ^RELATED-TO $file; then
sed -i "s/^RELATED-TO.*/RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}/" $file
if grep -q ^RELATED-TO "$fil"e; then
sed -i "s/^RELATED-TO.*/RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}/" "$file"
sedrv=$?
else
str="END:VTODO"
toadd="RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}"
sed -i "/$str/i $toadd\n" $file
sed -i "/$str/i $toadd\n" "$file"
sedrv=$?
fi
fi
@ -552,7 +552,7 @@ function move_right() { # move_right uid new_parent
str="underneath #${newparentid} ('${tasksum[$newparentid]}')."
fi
action "Shifted task #${id} $str"
loadtask $file
loadtask "$file"
showit ${taskparent[$id]} $uid
@ -580,15 +580,15 @@ function setnote() { # setnote uid new note goes here
shift
newnote="$*"
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
if grep -q ^DESCRIPTION: $file; then
sed -i "s/^DESCRIPTION:.*/DESCRIPTION:$newnote/" $file
if grep -q ^DESCRIPTION: "$file"; then
sed -i "s/^DESCRIPTION:.*/DESCRIPTION:$newnote/" "$file"
sedrv=$?
else
str="END:VTODO"
toadd="DESCRIPTION:$newnote"
sed -i "/$str/i $toadd\n" $file
sed -i "/$str/i $toadd\n" "$file"
sedrv=$?
fi
set_lastmodified $uid
@ -599,7 +599,7 @@ function setnote() { # setnote uid new note goes here
else
action "Set note of task #${id} to '$newnote'."
fi
loadtask $file
loadtask "$file"
rv=0
else
error "Failed to set note of task #${id}."
@ -622,11 +622,11 @@ function modtag() { # setnote uid add|del new tag goes here
shift
arg="$*"
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
if [[ -z $arg ]]; then
if [[ $action == "del" ]]; then
sed -i "/^CATEGORIES:/d" $file
sed -i "/^CATEGORIES:/d" "$file"
sedrv=$?
else
error "No tag specified to add."
@ -646,13 +646,13 @@ function modtag() { # setnote uid add|del new tag goes here
fi
if grep -q ^CATEGORIES: $file; then
sed -i "s/^CATEGORIES:.*/CATEGORIES:${newcat}/" $file
if grep -q ^CATEGORIES: "$file"; then
sed -i "s/^CATEGORIES:.*/CATEGORIES:${newcat}/" "$file"
sedrv=$?
else
str="END:VTODO"
toadd="CATEGORIES:${newcat}"
sed -i "/$str/i $toadd\n" $file
sed -i "/$str/i $toadd\n" "$file"
sedrv=$?
fi
fi
@ -668,7 +668,7 @@ function modtag() { # setnote uid add|del new tag goes here
else
action "Added tag '$arg' to task #${id}."
fi
loadtask $file
loadtask "$file"
rv=0
else
error "Failed to set/remove tag on task #${id}."
@ -688,15 +688,15 @@ function rename() { # rename uid new name goes here
shift
newname="$*"
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
sed -i "s/^SUMMARY:.*/SUMMARY:$newname/" $file
sed -i "s/^SUMMARY:.*/SUMMARY:$newname/" "$file"
sedrv=$?
set_lastmodified $uid
sedrv=$((sedrv + $?))
if [[ $sedrv -eq 0 ]]; then
action "Renamed task #${id} to '$newname'."
loadtask $file
loadtask "$file"
rv=0
else
error "failed to rename task #${id}."
@ -752,13 +752,13 @@ function fold() {
return 1
fi
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
str="END:VTODO"
if grep -q ^X-OC-HIDESUBTASKS: $file ; then
sed -i "s/X-OC-HIDESUBTASKS:.*/X-OC-HIDESUBTASKS:1/" $file
if grep -q ^X-OC-HIDESUBTASKS: "$file" ; then
sed -i "s/X-OC-HIDESUBTASKS:.*/X-OC-HIDESUBTASKS:1/" "$file"
sedrv=$?
else
sed -i "/$str/i X-OC-HIDESUBTASKS:1" $file
sed -i "/$str/i X-OC-HIDESUBTASKS:1" "$file"
sedrv=$?
fi
set_lastmodified $uid
@ -766,7 +766,7 @@ function fold() {
if [[ $sedrv -eq 0 ]]; then
action "Folded task #${id}."
processed="$processed ${uid} "
loadtask $file
loadtask "$file"
rv=0
else
failed="$failed ${uid} "
@ -796,13 +796,13 @@ function unfold() {
return 1
fi
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
str="END:VTODO"
if grep -q ^X-OC-HIDESUBTASKS: $file ; then
sed -i "s/X-OC-HIDESUBTASKS:.*/X-OC-HIDESUBTASKS:0/" $file
if grep -q ^X-OC-HIDESUBTASKS: "$file" ; then
sed -i "s/X-OC-HIDESUBTASKS:.*/X-OC-HIDESUBTASKS:0/" "$file"
sedrv=$?
else
sed -i "/$str/i X-OC-HIDESUBTASKS:0" $file
sed -i "/$str/i X-OC-HIDESUBTASKS:0" "$file"
sedrv=$?
fi
set_lastmodified $uid
@ -810,7 +810,7 @@ function unfold() {
if [[ $sedrv -eq 0 ]]; then
action "Unfolded task #${id}."
processed="$processed ${uid} "
loadtask $file
loadtask "$file"
rv=0
else
failed="$failed ${uid} "
@ -839,15 +839,15 @@ function markdone() {
toadd2="PERCENT-COMPLETE:100"
toadd3="COMPLETED:$now"
file=$dir/$uid.vcf
sed -i "/$str/i $toadd1\n$toadd2\n$toadd3" $file
file="$dir/$uid.vcf"
sed -i "/$str/i $toadd1\n$toadd2\n$toadd3" "$file"
sedrv=$?
set_lastmodified $uid
sedrv=$((sedrv + $?))
if [[ $sedrv -eq 0 ]]; then
action "Marked $noun #${id} as completed."
processed="$processed ${uid} "
loadtask $file
loadtask "$file"
rv=0
children=$(getchildren $uid)
for childuid in ${children}; do
@ -867,10 +867,10 @@ function viewtask() {
local uid id file
uid=$1
id=$(getid $uid)
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
action "Viewing task #$id ($file):"
cat $file | sed -e 's/^/ /'
cat "$file" | sed -e 's/^/ /'
return 0
}
@ -913,9 +913,9 @@ function addtask() {
taskchecked[$thisid]=0
taskfolded[$thisid]=0
taskparent[$thisid]=$parentuid
file=$dir/$uid.vcf
file="$dir/$uid.vcf"
now=$(date -u +'%Y%m%dT%H%M%SZ')
cat >$file <<EOF
cat >"$file" <<EOF
BEGIN:VCALENDAR
VERSION:2.0
PRODID:+//IDN tasks.org//android-111003//EN
@ -927,9 +927,9 @@ LAST-MODIFIED:$now
SUMMARY:${tasksum[$thisid]}
EOF
if [[ ! -z ${taskparent[$thisid]} ]]; then
echo "RELATED-TO;RELTYPE=PARENT:${taskparent[$thisid]}" >>$file
echo "RELATED-TO;RELTYPE=PARENT:${taskparent[$thisid]}" >>"$file"
fi
cat >>$file <<EOF2
cat >>"$file" <<EOF2
PRIORITY:9
X-APPLE-SORT-ORDER:611376630
X-OC-HIDESUBTASKS:0
@ -1374,10 +1374,10 @@ VDIRSYNCER=/usr/local/bin/vdirsyncer
DEFAULT_VDS_LOCAL=cal_local
DEFAULT_VDS_REMOTE=cal_remote
basedir=/Users/rpearce/code/task_cli
confdir=${HOME}/.task_cli
allcalsdir=$confdir/allcals # symlink to vdirsyncer/calendar/
defaultcalfile=$confdir/defaultcal
idfile=$confdir/idmappings
confdir="${HOME}/.task_cli"
allcalsdir="$confdir/allcals" # symlink to vdirsyncer/calendar/
defaultcalfile="$confdir/defaultcal"
idfile="$confdir/idmappings"
nextid=1
indent=0
indentamt=4