dot

packages and services management
Log | Files | Refs | README

commit 1924cf0f557ab90338210c3839933701117e9a09
parent c6006f1c2adbe2fc761432aa5b23c1c42762a7cf
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 23 Feb 2018 17:32:57 +0100

simplifying usage (and man page)

Diffstat:
Mbin/agenda | 78++++++++++++++++++++++++++++++++++++++----------------------------------------
Mman/agenda.1 | 95+++++++++++++++++++++++++------------------------------------------------------
2 files changed, 68 insertions(+), 105 deletions(-)

diff --git a/bin/agenda b/bin/agenda @@ -105,6 +105,7 @@ BEGIN { /^:$/ { line[nb++] = sprintf("%08d\t%s", NR, $0); prefix = ""; + for (i = length(SORT); i > 0; i--) prefix = line[substr(SORT, i, 1)] "\t" prefix; for (i = 1; i < nb; i++) @@ -153,75 +154,72 @@ BEGIN { last_day = b_day; }' -to_sec="$date"' -#DATE YYYY-MM-DD-HH-MM #OFF=[+-]HH +add="$date"' +#DT1 YYYY/MM/DD-HH:MM +#DT2 YYYY/MM/DD-HH:MM +#OFF [+-]HH -BEGIN { +function parse(date) +{ yrs = substr(DATE, 1, 4); mth = substr(DATE, 6, 2); day = substr(DATE, 9, 2); hrs = substr(DATE, 12, 2); min = substr(DATE, 15, 2); - print(to_sec(yrs, mth, day, hrs, min, 0) - OFF * 3600); + return to_sec(yrs, mth, day, hrs, min, 0) - OFF * 3600; +} + +BEGIN { + printf("B:%d\nE:%d\nS:\nC:\nL:\nD:\n:\n", parse(DATE1), parse(DATE2)); }' list="$date"' -sub("^B:", "") { minimum = ($0 < minimum || minimum == 0) ? $0 : minimum; } +sub("^B:", "") { + minimum = ($0 < minimum || minimum == 0) ? $0 : minimum; +} END { name = FILENAME; sub(".*/", "", name); - printf("%s - %s - %s\n", + printf("%s - %-10s %s\n", to_date("%d/%02d/%02d", minimum + 3600), name, FILENAME); }' mkdir -p "$AGENDA" case "$1" in -(import) - [ "$#" -ne 4 ] && exec "$0" +(-i) + [ "$#" = 4 ] || exec "$0" -h awk -v OFF="$4" "$import" "$2" > "$AGENDA/$3" ;; -(view) - [ "$#" -lt 2 ] || [ "$#" -gt 3 ] && exec "$0" - - shift 1 - [ "$1" = "all" ] && set -- "$AGENDA"/* || set -- "$AGENDA/$1" - - cat "$@" | - awk -v SORT="${3:-BECLS}" "$sort" | - awk -v OFF="$(date +%z | cut -c 1-3)" "$view" | - less - ;; -(add) - [ "$#" -ne 4 ] && exec "$0" +(-a) + [ "$#" = 5 ] && set -- "$1" "$2" "$3" "$4" "$3" "$5" + [ "$#" = 6 ] || exec "$0" -h off="$(date +%z | cut -c -3)" - - printf 'B:%s\nE:%s\nS:\nC:\nL:\nD:\n:\n' \ - "$(awk -v DATE="$3" -v OFF="$off" "$to_sec")" \ - "$(awk -v DATE="$4" -v OFF="$off" "$to_sec")" \ - >> "$AGENDA/$2" - - exec "$0" edit "$2" - ;; -(edit) - [ $# -ne 2 ] && exec "$0" - + awk -v OFF="$off" -v DT1="$3-$4" -v DT2="$5-$6" "$add" >> "$AGENDA/$2" exec $EDITOR "$AGENDA/$2" ;; -(list) +(all) + cd "$AGENDA" + awk -v SORT="${2:-BECLS}" "$sort" * | + awk -v OFF="$(date +%z | cut -c 1-3)" "$view" | + less + ;; +('') find "$AGENDA" ! -type d ! -name '*.txt' -exec awk "$list" {} \; | sort ;; (*) - echo "usage: $0 add <name> <YYYY-MM-DD-HH-MM> <YYYY-MM-DD-HH-MM>" - echo " $0 edit <name>" - echo " $0 import <file.ics> <name> [+-]<HH>" - echo " $0 view <name> [BESCL]" - echo " $0 list" - echo "" - "$0" list + [ "$#" = 1 ] || [ "$#" = 2 ] && [ -f "$AGENDA/$1" ] || + exec cut -f 2- << 'EOF' 1>&2 + usage: agenda -a <name> YYYY/MM/DD HH:MM [YYYY/MM/DD] HH:MM + agenda -i <file.ics> <name> [+-]HH + agenda [all | <name> [BESCL]] +EOF + awk -v SORT="${2:-BECLS}" "$sort" "$AGENDA/$1" | + awk -v OFF="$(date +%z | cut -c 1-3)" "$view" | + less ;; esac diff --git a/man/agenda.1 b/man/agenda.1 @@ -1,4 +1,4 @@ -.Dd $Mdocdate: December 23 2017$ +.Dd $Mdocdate: February 23 2018$ .Dt AGENDA 1 .Os . @@ -11,10 +11,9 @@ . .Sh SYNOPSIS . -.Nm Ic add Ar name Ar begin Ar end -.Nm Ic edit Ar name -.Nm Ic show Ar name Op Ar sort -.Nm Ic import Ar ics_file Ar name Op +- Ns Ar HH +.Nm Fl a Ar name Ar YYYY/MM/DD Ar HH:MM Oo Ar YYYY/MM/DD Oc Ar HH:MM +.Nm Fl i Ar ics_file Ar name Op +- Ns Ar HH +.Nm Op Ar name Op Ar sort . . .Sh DESCRIPTION @@ -29,29 +28,34 @@ by hand, or imported from an file. . . -.Ss Nm Ic add Ar name Ar begin Ar end +.Ss Nm Fl a Ar name Ar YYYY/MM/DD Ar HH:MM Oo Ar YYYY/MM/DD Oc Ar HH:MM . Create a new .Xr agenda 5 entry in the +agenda .Ar name -agenda in the -and open this file with an editor. -.Ar begin -and -.Ar end -are dates formatted as -.Ql YYYY-MM-DD-HH-MM . +with specified start and end date and open this file with an editor. +If the end date is ommited, the end date is set to the same day as the begin. . . -.Ss Nm Ic edit Ar name +.Ss Nm Ic -i Ar ics_file Ar name Op +- Ns Ar HH . -Open the +Convert +.Ar ics_file +to the +.Xr agenda 5 +format and store it in the .Ar name -agenda with an editor. +agenda, replacing its content. +.Ar HH +is the timezone offset of the agenda imported, optionnaly preceded by a +.Ql - +or +.Ql + . . . -.Ss Nm Ic show Ar name Op Ar sort +.Ss Nm Op Ar name Op Ar sort . Render the .Ar name @@ -84,34 +88,6 @@ is .Ql BECLS . . -.Ss Nm Ic import Ar ics_file Ar name Op +- Ns Ar HH -. -Convert -.Ar ics_file -to the -.Xr agenda 5 -format and store it in the -.Ar name -agenda, replacing its content. -.Ar HH -is the timezone offset of the agenda imported, optionnaly preceded by a -.Ql - -or -.Ql + . -. -. -.Ss Nm Ic gopher -. -Generate a gopher menu list in a format compatible with -.Xr geomyidae 1 . -The links are relative to current directory with the -.Dq Pa .txt -extension added. -The command should be launched in the root of the directory served and -.Ev AGENDA -must be set one of its subdirectories. -. -. .Sh ENVIRONMENT . .Bl -tag -width 6n @@ -121,11 +97,9 @@ Path th the agenda dir, defaults to .Pa ~/.config/agenda . . .It Ev EDITOR -Started to edit the agenda file with the -.Ic add -and -.Ic edit -commands. +Started to edit the agenda file as with the +.Op Fl a +flag. . .It Ev TZ Timezone to use for printing the dates. @@ -135,22 +109,19 @@ Timezone to use for printing the dates. . .Sh EXAMPLES . -Import an ical agenda from a gopher uri: -.Dl % curl gopher://url | agenda import - fosdem +01 -. -.Pp -Print the time offset corresponding to the Europe/Brussels timezone: -.Dl % TZ=Europe/Brussels date +%z | cut -c -3 +Import an ical agenda from an url: +.Dl % curl http://example.com | agenda -i - fosdem +01 . .Pp Print the travel agenda with times expressed in the Japan timezone: -.Dl % TZ=Japan agenda show travel +.Dl % TZ=Japan agenda travel . .Pp Print the fosdem agenda sorted by -.Dq location , then by +.Dq location , +then by .Dq begin date : -.Dl % agenda show fosdem LB +.Dl % agenda fosdem LB . . .Sh SEE ALSO @@ -168,9 +139,3 @@ Only a subset of ical format is supported. .Sh AUTHORS . .An Josuah Demangeon Aq Mt mail@josuah.net -. -. -.Sh CAVEATS -. -Events spanning across multiple month will be displayed poorly. -Other multiple-day events are displayed properly.