about summary refs log tree commit diff
path: root/Functions/Calendar/calendar_edit
blob: 430c3b2e9839ed29d0e6d33fa0b3e000ba56c3a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local line calendar
local -a lockfiles editor

integer cal_running

if (( $# )); then
  editor=("$@")
else
  editor=(${VISUAL:-${EDITOR:-vi}})
fi

sched | while read line; do
  [[ $line = *" calendar -s "<->" "<-> ]] && (( cal_running = 1 ))
done

zstyle -s ':datetime:calendar:' calendar-file calendar || calendar=~/calendar

# start of subshell for OS file locking
(
# start of block for following always to clear up lockfiles.
# Not needed but harmless if OS file locking is used.
{
  if zmodload -F zsh/system b:zsystem && zsystem supports flock; then
    zsystem flock $calendar
  else
    calendar_lockfiles $calendar || exit 1
  fi

  eval $editor \$calendar
} always {
  (( ${#lockfiles} )) && rm -f $lockfiles
}
)

(( cal_running )) && calendar -s