dot

packages and services management
Log | Files | Refs | README

commit 3f806fd9f7540fc8f1d5e99a8335b1b6b6d2c683
parent 3a263e01d24755d3a31feae06113c39674174b1a
Author: josuah <mail@josuah.net>
Date:   Thu, 22 Dec 2016 23:15:01 +0000

Added a calendar parsing awk script

Diffstat:
D.local/bin/agenda | 286-------------------------------------------------------------------------------
A.local/bin/ical | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D.local/bin/peax | 112-------------------------------------------------------------------------------
M.local/bin/tty-theme | 4++--
M.local/share/build/iomenu | 2+-
M.profile | 11++++++++---
MREADME | 2+-
7 files changed, 86 insertions(+), 405 deletions(-)

diff --git a/.local/bin/agenda b/.local/bin/agenda @@ -1,286 +0,0 @@ -# Agenda from the command line 2016-12-21 - - -AGENDA="${AGENDA-$HOME/.cache/agenda/agenda}" -COLUMNS="$(stty size | cut -d ' ' -f 2)" - -HELP="NAME - agenda - Agenda from the command line. - -SYNTAX - agenda COMMAND [-d DATE] [-i ICAL] - -DESCRIPTION - -d Set date to use - -i Import an ICAL to $AGENDA - a, agenda - for next event starting from DATE or today. - c, calendar - for current week and next events highlihted. - - -FILES - \$AGENDA: $AGENDA - File storing the agenda, with each entry on a line, and each - field separated by a tab, in this order: - - 1. Start date (yyyy-mm-dd HH:MM:SS) - 2. End date (yyyy-mm-dd HH:MM:SS) - 3. Name - 4. Location - 5. Description -" - - -# AWK SCRIPTS -# ------------------------------------------------------------------------------ - -awk_ical=' -BEGIN { - RS = ""; - FS = ":"; -} - -/BEGIN:VEVENT/,/END:VEVENT/ { - if (substr($0, 1, 1) != " ") { - type = $1; - vevent[type] = $2; - } else - vevent[type] = vevent[type] substr($0, 2, length($0) - 1); - - if ($0 == "BEGIN:VEVENT") { - date = vevent["DTSTART"] - printf("%s-%s-%s %s:%s:%s\t", - substr(date, 1, 4), # Year - substr(date, 5, 2), # Month - substr(date, 7, 2), # Day - substr(date, 10, 2), # Hour - substr(date, 12, 2), # Minute - substr(date, 14, 2)); # Second - - date = vevent["DTEND"] - printf("%s-%s-%s %s:%s:%s\t", - substr(date, 1, 4), # Year - substr(date, 5, 2), # Month - substr(date, 7, 2), # Day - substr(date, 10, 2), # Hour - substr(date, 12, 2), # Minute - substr(date, 14, 2)); # Second - - printf("%s\t", vevent["SUMMARY"]); - printf("%s\t", vevent["LOCATION"]); - printf("%s\n", vevent["DESCRIPTION"]); - } -}' - -awk_agenda=' -BEGIN { - FS = "\t"; -} - -{ - "date +%s -d '\''"$1"'\''" | getline event_date; -} - -(now <= event_date) { - beg = $1; end = $2; sum = $3; loc = $4; des = $5; - - beg_Y = substr(beg, 1, 4); sub(/^0/, " ", beg_Y); - beg_m = substr(beg, 6, 2); sub(/^0/, " ", beg_m); - beg_d = substr(beg, 9, 2); sub(/^0/, " ", beg_d); - beg_R = substr(beg, 12, 5); sub(/^0/, " ", beg_R); - end_Y = substr(end, 1, 4); sub(/^0/, " ", end_Y); - end_m = substr(end, 6, 2); sub(/^0/, " ", end_m); - end_d = substr(end, 9, 2); sub(/^0/, " ", end_d); - end_R = substr(end, 12, 5); sub(/^0/, " ", end_R); - - sub(/^\\n/, "", des); - gsub(/\\n/, " - ", des); - gsub(/\\/, "", sum); gsub(/\\/, "", loc); gsub(/\\/, "", des); - - # Header line - if (last_beg_Y != beg_Y) { - printf("_%4s_________Summary__________________________________"\ - "Location____________________________________________" \ - "____________________________________________________" \ - "\n |\n", - beg_Y); - } - - # First line - if (last_beg_m != beg_m) {printf("%2s ", beg_m);} else {printf(" ");} - if (last_beg_d != beg_d) {printf("%2s ", beg_d);} else {printf(" ");} - - printf("%5s | %-40s %s\n", beg_R, sum, loc); - - # Second line - if (beg_m != end_m) {printf("%2s ", end_m);} else {printf(" ");} - if (beg_d != end_d) {printf("%2s ", end_d);} else {printf(" ");} - if (beg_R != end_R) {printf("%5s ", end_R);} else {printf(" ");} - - printf("|\033[30;1m %s", des); - - printf("\n\033[0m |\n"); - - last_beg_Y = beg_Y; - last_beg_m = beg_m; - last_beg_d = beg_d; -}' - - -awk_calendar=' -BEGIN { - FS = "\t"; - - header = " "; - row[0] = " Mon "; - row[1] = " Tue "; - row[2] = " Wed "; - row[3] = " Thu "; - row[4] = " Fri "; - row[5] = " Sat "; - row[6] = " Sun "; - - # fill the empty days with spaces - for (i = 0; i < w; i++) - row[i] = row[i] " "; - - # month name offset - if (w == 0) offset = 0; - else offset = 1; - - # increase date for every day - for (j = 0; j <= range; j++) { - - # day of week - if ((j + w) % 7 == 0) { - offset++; - } - - if (d < 28 \ - || (d == 28 && m == 2 && Y % 4 == 0) \ - || (d < 30 && ((m <= 7 && m % 2 == 0) \ - || (m >= 8 && m % 2 == 1)) && m != 2) \ - || (d < 31 && ((m <= 7 && m % 2 == 1) \ - || (m >= 8 && m % 2 == 0)) && m != 2)) { - d++; - } else { - d = 1; - - if (m < 12) { - m++; - } else { - m = 1; Y++; - } - - if (m == 1) month = "Jan"; - else if (m == 2) month = "Feb"; - else if (m == 3) month = "Mar"; - else if (m == 4) month = "Apr"; - else if (m == 5) month = "May"; - else if (m == 6) month = "Jun"; - else if (m == 7) month = "Jul"; - else if (m == 8) month = "Aug"; - else if (m == 9) month = "Sep"; - else if (m == 10) month = "Oct"; - else if (m == 11) month = "Nov"; - else if (m == 12) month = "Dec"; - - header = sprintf("%s%" offset * 3 - 3 "s%s", \ - header, "", month); - offset = 0; - } - - date = sprintf("%04d-%02d-%02d", Y, m, d); - - # while event end is in the past, get next event if any - while (substr($2, 0, 10) < date) - if (! getline) break; - - # add a leading space - row[(j + w) % 7] = row[(j + w) % 7] " "; - - # if it begins in the past and ends in the future - if (substr($1, 0, 10) <= date && date <= substr($2, 0, 10)) - row[(j + w) % 7] = row[(j + w) % 7] "\033[7m"; - - # current day - if (date == today) - row[(j + w) % 7] = row[(j + w) % 7] "\033[31;1m"; - - # day number - row[(j + w) % 7] = row[(j + w) % 7] sprintf("%2s\033[0m", d); - } - - print header; - for (i = 0; i <= 6; i++) { - print row[i]; - } -}' - - -import_ical() -( - ical="$1" - - sed -i 's/\r//; s/\t/ /g' "$ical" - awk "$awk_ical" "$ical" | cat - "$AGENDA" | sort | uniq > "$AGENDA" -) - - -agenda() -{ - awk -v now="$SEC" "$awk_agenda" "$AGENDA" | cut -c 1-"$COLUMNS" -} - - -calendar() -{ - awk \ - -v Y="$(date +'%Y' -d "@$SEC")" \ - -v m="$(date +'%m' -d "@$SEC")" \ - -v d="$(date +'%d' -d "@$SEC")" \ - -v w="$(date +'%w' -d "@$SEC")" \ - -v now="$(date +'%Y-%m-%d' -d "@$SEC")" \ - -v range="$(($COLUMNS * 7 / 3 - 26))" \ - "$awk_calendar" "$AGENDA" -} - - -main() -( - [ $# = 0 ] && set -- help - while [ $# -gt 0 ] - do - case $1 in - a | agenda) - action="agenda" - shift - ;; - c | calendar) - action="calendar" - shift - ;; - -i ) - action="import_ical $2" - shift 2 - ;; - -d ) - DATE="$2" - - shift 2 - ;; - * ) - printf '%s\n' "$help" - exit 0 - ;; - esac - - [ "$DATE" ] && SEC="$(date +%s -d "$DATE")" || SEC="$(date +%s)" - done - - $action -) - - -main "$@" diff --git a/.local/bin/ical b/.local/bin/ical @@ -0,0 +1,74 @@ +function is_bissextile(year) +{ + return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); +} + +function days_in_month(month, year) +{ + if (month == 2) { + return 28 + is_bissextile(year); + } else if (month < 8) { + return 30 + (month % 2 == 1); + } else { + return 30 + (month % 2 == 0); + } +} + + +function date_to_second(year, month, day, hour, minute, second) +{ + for (month--; month > 0; month--) + day += days_in_month(month, year); + + for (year--; year >= 1970; year--) + day += 365 + is_bissextile(year); + + return (second + 60 * (minute + 60 * (hour + (24 * (day - 1))))); +} + + +BEGIN { + FS = ":"; +} + + +{ + gsub("\015", ""); +} + + +/BEGIN:VEVENT/,/END:VEVENT/ { + if (substr($0, 1, 1) != " ") { + type = $1; + vevent[type] = substr($0, + index($0, ":") + 1, length($0) - length($1)); + } else { + vevent[type] = vevent[type] substr($0, 2, length($0) - 1); + } +} + + +/END:VEVENT/ { + + date = vevent["DTSTART"] + printf "%s ", strftime("%Y%m%dT%H%M%SZ", date_to_second( \ + substr(date, 1, 4), # Year + substr(date, 5, 2), # Month + substr(date, 7, 2), # Day + substr(date, 10, 2), # Hour + substr(date, 12, 2), # Minute + substr(date, 14, 2))); # Second + + date = vevent["DTEND"] + printf "%s ", strftime("%Y%m%dT%H%M%SZ", date_to_second( \ + substr(date, 1, 4), # Year + substr(date, 5, 2), # Month + substr(date, 7, 2), # Day + substr(date, 10, 2), # Hour + substr(date, 12, 2), # Minute + substr(date, 14, 2))); # Second + + printf("%s\t", vevent["SUMMARY"]); + printf("%s\t", vevent["LOCATION"]); + printf("%s\n", vevent["DESCRIPTION"]); +} diff --git a/.local/bin/peax b/.local/bin/peax @@ -1,112 +0,0 @@ -#!/usr/bin/awk -f -# -# ---. ,--. ,--. . , -# | | |--' ,--| >< -# |--' `--' `--` ' ` 2016-10-07 -#-|----------------------------------------------------------------------------- -# Pick a line from stdin - -# Read the file from stdin -BEGIN { - h = 0; # Header - if (ARGV[1] != "") { - h = ARGV[1]; ARGV[1] = 0; - } -} - -NR <= h { - header[NR] = $0 -} - -NR > h { - stdin[NR - h] = $0; -} - -END { - s = 1; # Selection - o = 0; # Offset - - # Update screen dimensions - "stty size < /dev/tty" | getline LINES - COLUMNS = LINES; - sub(/ [0-9]*$/, "", LINES); - sub(/^[0-9]* /, "", COLUMNS); - - while (1) { - # Filter stdin through input and store into candidates - j = 1; - - # Fix the regex and expand ' ' to '.*' - regex = input; - gsub(" ", ".*", regex) - - for (i in stdin) { - if (match(stdin[i], regex)) { - candidates[j++] = stdin[i]; - } - } - - # Display the candidate list to stderr - system("clear 1>&2"); - - for (i = 1; i <= h; i++) { - printf("\n\033[1m%s\033[0m", \ - substr(header[i], 0, COLUMNS)) \ - > "/dev/stderr"; - } - for (i = 1; i < j; i++) { - if (o < i && i < o + LINES - h) { - printf((i == s) ? "\n\033[7m%s\033[0m" : "\n%s", - substr(candidates[i], 0, COLUMNS)) \ - > "/dev/stderr"; - } - } - - # Display the user input - printf("\033[0;0f\033[K%7s> %s", j - 1, input) > "/dev/stderr" - - # Get the next key from user input - cmd = "dd if=/dev/tty bs=1 count=1 2> /dev/null" - system("stty raw -echo < /dev/tty"); - cmd | getline key - system("stty -raw echo < /dev/tty"); - close(cmd); - - # Parse the key and determine action - if (key == "") { - s = s + 1; - } else if (key == "") { - s = s - 1; - } else if (key == "") { - s = s + int(LINES / 2); - } else if (key == "") { - s = s - int(LINES / 2); - } else if (key == "" || key == "") { - sub(/.$/, "", input); - } else if (key == "") { - sub(/[^ ]* *$/, "", input); - } else if (key == "") { - input = ""; - } else if (key == "") { - system("clear 1>&2"); - exit; - } else if (key == " ") { - system("clear 1>&2"); - print candidates[s]; - exit; - } else { - sub(/[^\40-\176]/, "", key); - input = input key; - } - - # Prevent the selection to overflow - if (s < 1) { - s = 1; - } else if (s >= j) { - s = j - 1; - } - - # Shift the list as the selection goes down - o = (s > LINES - 13) ? s - LINES + 13 : 0; - } -} diff --git a/.local/bin/tty-theme b/.local/bin/tty-theme @@ -182,8 +182,8 @@ matrix 4 339977 5 668877 6 119977 -7 99dd99 -8 338833 +7 99ffaa +8 338844 9 aa7733 A 00ff88 B 88ee66 diff --git a/.local/share/build/iomenu b/.local/share/build/iomenu @@ -1,3 +1,3 @@ # Input/Output interactive menu and completion engine. -tar=http://repo.or.cz/iomenu.git/snapshot/cb518c1501b1f112242668896d7932dbeb4ed52d.tar.gz +tar=http://repo.or.cz/iomenu.git/snapshot/c493398d788a42554885677e9fafcfc1bc45475e.tar.gz diff --git a/.profile b/.profile @@ -191,8 +191,13 @@ screencast() # Startup #_______________________________________________________________________________ -[ "$TERM" = linux ] && setfont ~/.local/share/consolefonts/lode-16.psf +case "$TERM" in +linux ) + setfont ~/.local/share/consolefonts/tamsyn-16n.psf + ;; +dvtm ) + export TERM='screen' + ;; +esac [ "$ABDUCO" ] || TERM='screen' ABDUCO='dvtm' abduco -A dvtm dvtm-status - -export TERM='screen' diff --git a/README b/README @@ -10,7 +10,7 @@ ________________________________________________________________________________ not detecting all source types accurately for C headers and shell script without shebangs. - This file is the installer script. You can run it.' + This file is the installer script. You can run it. Scripts (/bin)