diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2007-08-16 12:03:57 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2007-08-16 12:03:57 +0000 |
commit | 0a607f5eefec38cc7ef625f1692bd1d12e969f90 (patch) | |
tree | 588130ff573e5d07ac2fa8f43b355dacbaaf4e79 /Functions/Calendar/calendar_add | |
parent | c05f1046d874fa51eb11c395ed1e2f2b184cddb5 (diff) | |
download | zsh-0a607f5eefec38cc7ef625f1692bd1d12e969f90.tar.gz zsh-0a607f5eefec38cc7ef625f1692bd1d12e969f90.tar.xz zsh-0a607f5eefec38cc7ef625f1692bd1d12e969f90.zip |
23764: allow hidden continuations in calendar entries
allow UIDs to help with updates
Diffstat (limited to 'Functions/Calendar/calendar_add')
-rw-r--r-- | Functions/Calendar/calendar_add | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/Functions/Calendar/calendar_add b/Functions/Calendar/calendar_add index 8e6eca8b6..dc9f50c2b 100644 --- a/Functions/Calendar/calendar_add +++ b/Functions/Calendar/calendar_add @@ -12,7 +12,7 @@ setopt extendedglob local calendar newfile REPLY lastline opt local -a calendar_entries lockfiles -integer newdate done rstat nolock nobackup +integer my_date done rstat nolock nobackup autoload -U calendar_{read,lockfiles,scandate} @@ -42,10 +42,20 @@ if ! calendar_scandate -a "$*"; then print "$0: failed to parse date/time" >&2 return 1 fi -(( newdate = $REPLY )) +(( my_date = $REPLY )) # $calendar doesn't necessarily exist yet. +local -a match mbegin mend +local my_uid their_uid + +# Match a UID, a unique identifier for the entry inherited from +# text/calendar format. +local uidpat='(|*[[:space:]])UID[[:space:]]##(#b)([[:xdigit:]]##)(|[[:space:]]*)' +if [[ "$*" = ${~uidpat} ]]; then + my_uid=$match[1] +fi + # start of block for following always to clear up lockfiles. { (( nolock )) || calendar_lockfiles $calendar || return 1 @@ -55,15 +65,22 @@ fi { for line in $calendar_entries; do - if (( ! done )) && calendar_scandate -a $line && (( REPLY > newdate )); then + if (( ! done )) && calendar_scandate -a $line && (( REPLY > my_date )); then print -r -- "$*" (( done = 1 )) - elif [[ $REPLY -eq $newdate && $line = "$*" ]]; then + fi + # Don't save this entry if it has the same UID as the new one. + if [[ -n $my_uid && $line = ${~uidpat} ]]; then + their_uid=$match[1] + [[ ${(U)my_uid} = ${(U)their_uid} ]] && continue + fi + if [[ $REPLY -eq $my_date && $line = "$*" ]]; then + (( done )) && continue # paranoia: shouldn't happen (( done = 1 )) fi print -r -- $line - done - (( done )) || print -r -- "$*" + done + (( done )) || print -r -- "$*" } >$newfile if (( ! nobackup )); then if ! mv $calendar $calendar.old; then |