inital work on handling files with spaces
This commit is contained in:
parent
fb4413249b
commit
404839bd7a
71
t.sh
71
t.sh
|
@ -154,10 +154,10 @@ function saveids() {
|
||||||
[[ $1 == "-v" ]] && verbose=1
|
[[ $1 == "-v" ]] && verbose=1
|
||||||
|
|
||||||
if [[ ${#idmap[@]} -gt 0 ]]; then
|
if [[ ${#idmap[@]} -gt 0 ]]; then
|
||||||
cp /dev/null $idfile
|
cp /dev/null "$idfile"
|
||||||
for id in ${!idmap[@]}; do
|
for id in ${!idmap[@]}; do
|
||||||
#dblog "save to $idfile: uid ${idmap[$id]} id $id sum ${tasksum[$id]}" >> $idfile
|
#dblog "save to $idfile: uid ${idmap[$id]} id $id sum ${tasksum[$id]}" >> $idfile
|
||||||
echo "${idmap[$id]}:$id" >> $idfile
|
echo "${idmap[$id]}:$id" >> "$idfile"
|
||||||
nids=$((nids + 1))
|
nids=$((nids + 1))
|
||||||
done
|
done
|
||||||
[[ $nids -eq 1 ]] && ess="" || ess="s"
|
[[ $nids -eq 1 ]] && ess="" || ess="s"
|
||||||
|
@ -188,9 +188,9 @@ function loadtasks() {
|
||||||
[[ $1 == "-v" ]] && verbose=1 && shift 1
|
[[ $1 == "-v" ]] && verbose=1 && shift 1
|
||||||
done
|
done
|
||||||
dblog "Loading tasks..."
|
dblog "Loading tasks..."
|
||||||
for f in $dir/*.vcf; do
|
for f in "$dir"/*.vcf; do
|
||||||
dblog "--> loading from $f"
|
dblog "--> loading from $f"
|
||||||
loadtask $f || return 1
|
loadtask "$f" || return 1
|
||||||
ntasks=$((ntasks + 1))
|
ntasks=$((ntasks + 1))
|
||||||
done
|
done
|
||||||
numwid=${#maxid}
|
numwid=${#maxid}
|
||||||
|
@ -285,7 +285,7 @@ function loadtask() {
|
||||||
|
|
||||||
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); } /^RELATED-TO/ { sub("^RELATED-TO.*:",""); printf("parent©%s©",$0); } /^X-OC-HIDESUBTASKS:1/ { folded=1; } /^STATUS:COMPLETED/ { checked=1; } END { printf("checked©%d©folded©%d\n",checked,folded); }')
|
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); } /^RELATED-TO/ { sub("^RELATED-TO.*:",""); printf("parent©%s©",$0); } /^X-OC-HIDESUBTASKS:1/ { folded=1; } /^STATUS:COMPLETED/ { checked=1; } END { printf("checked©%d©folded©%d\n",checked,folded); }')
|
||||||
|
|
||||||
IFS='©'
|
IFS='©'
|
||||||
read -ra tok <<< "$res"
|
read -ra tok <<< "$res"
|
||||||
|
@ -1233,9 +1233,10 @@ EOF
|
||||||
if [[ -z $selcal ]]; then
|
if [[ -z $selcal ]]; then
|
||||||
warn "No calendar selected "
|
warn "No calendar selected "
|
||||||
echo "${YELLOW}Please put default calendar name in ${defaultcalfile}"
|
echo "${YELLOW}Please put default calendar name in ${defaultcalfile}"
|
||||||
echo "${YELLOW}then: touch ${idfile}_\$(cat $defaultcalfile)"
|
echo "${YELLOW}then: touch \"${idfile}_\$(cat $defaultcalfile)\""
|
||||||
selcal=""
|
selcal=""
|
||||||
else
|
else
|
||||||
|
selcal=${selcal// /_}
|
||||||
if [[ -e "${idfile}_${selcal}" ]]; then
|
if [[ -e "${idfile}_${selcal}" ]]; then
|
||||||
warn "ID mapping file for $selcal already exists. Not overwriting it."
|
warn "ID mapping file for $selcal already exists. Not overwriting it."
|
||||||
else
|
else
|
||||||
|
@ -1298,6 +1299,27 @@ function getcals() { # countvar arrayvar
|
||||||
done <<< "$loc_cals"
|
done <<< "$loc_cals"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getcalname() { # cal_name_or_number
|
||||||
|
local lc larr d found=""
|
||||||
|
getcals lc larr
|
||||||
|
for d in ${!larr[@]}; do
|
||||||
|
if [[ ${larr[$d]} == $1 ]]; then
|
||||||
|
found="${larr[$d]}"
|
||||||
|
break
|
||||||
|
elif [[ $1 =~ ^[0-9]+$ && $d -eq $(($1 - 1)) ]]; then
|
||||||
|
# make this the default
|
||||||
|
found="${larr[$d]}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "$found"
|
||||||
|
if [[ -z $found ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Should be in config file:
|
# Should be in config file:
|
||||||
#basedir=/Users/rpearce/scripts/t
|
#basedir=/Users/rpearce/scripts/t
|
||||||
#dir=$basedir/docs
|
#dir=$basedir/docs
|
||||||
|
@ -1440,8 +1462,17 @@ while getopts "$ARGS" i; do
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
# validate CALID
|
||||||
|
foundcal=$(getcalname "$CALID")
|
||||||
|
if [[ -n $foundcal ]]; then
|
||||||
|
CALID="$foundcal"
|
||||||
|
else
|
||||||
|
error "Calendar '$CALID' does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
dir=$allcalsdir/$CALID
|
dir=$allcalsdir/$CALID
|
||||||
idfile=$confdir/idmappings_$CALID
|
idfile="$confdir/idmappings_${CALID// /_}"
|
||||||
|
|
||||||
if [[ ! -e $idfile ]]; then
|
if [[ ! -e $idfile ]]; then
|
||||||
warn "No ID mapping file found for calendar '$CALID' ($idfile)"
|
warn "No ID mapping file found for calendar '$CALID' ($idfile)"
|
||||||
|
@ -1520,28 +1551,12 @@ elif [[ $mode == "setcal" ]]; then
|
||||||
error "No calendar name provided."
|
error "No calendar name provided."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
getcals count cals_arr
|
foundcal=$(getcalname $1)
|
||||||
if [[ $count -gt 0 ]]; then
|
if [[ -n $foundcal ]]; then
|
||||||
found=0
|
action "Default calendar set to '${foundcal}'"
|
||||||
for d in ${!cals_arr[@]}; do
|
echo "${foundcal}" > "$defaultcalfile"
|
||||||
if [[ ${cals_arr[$d]} == $1 ]]; then
|
|
||||||
# make this the default
|
|
||||||
found=1
|
|
||||||
break
|
|
||||||
elif [[ $1 =~ ^[0-9]+$ && $d -eq $(($1 - 1)) ]]; then
|
|
||||||
# make this the default
|
|
||||||
found=1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [[ $found -eq 1 ]]; then
|
|
||||||
action "Default calendar set to '${cals_arr[$d]}'"
|
|
||||||
echo "${cals_arr[$d]}" > "$defaultcalfile"
|
|
||||||
else
|
|
||||||
error "Calendar '$1' not found"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
error "No calendars found."
|
error "Calendar '$1' not found"
|
||||||
fi
|
fi
|
||||||
elif [[ $mode == "rename" ]]; then
|
elif [[ $mode == "rename" ]]; then
|
||||||
uid=$(getuid_witherror $1)
|
uid=$(getuid_witherror $1)
|
||||||
|
|
Loading…
Reference in New Issue