From 92a4bd236ace0c5f57e0bea5f4a57ecd5a1ee844 Mon Sep 17 00:00:00 2001 From: Edoardo Rosa <6991986+notdodo@users.noreply.github.com> Date: Mon, 20 Sep 2021 09:34:18 +0200 Subject: [PATCH] add skip flag (#67) * add skip flag * Update README.md * updated help in README Co-authored-by: Tomer Rosenfeld --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++-- i3_agenda/__init__.py | 2 ++ i3_agenda/config.py | 7 ++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a81fd7e..6e67a18 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Run `sudo pip3 install python-bidi google-api-python-client google-auth-httplib2 --update, -u when using this flag it will not load previous results from cache, it will however save new results to cache. You can use this flag to refresh all the cache forcefully --ids IDS [IDS ...], -i IDS [IDS ...] - list of calendar ids to fetch, space separated. If none is specified all calendars will be fetched + list of calendar ids to fetch, space separated. If none is specified all calendars will be fetched --maxres MAXRES, -r MAXRES max number of events to query Google's API for each of your calendars. Increase this number if you have lot of events in your google calendar @@ -74,6 +74,7 @@ Run `sudo pip3 install python-bidi google-api-python-client google-auth-httplib2 the date format like %d/%m/%y. Default is %d/%m --limchar LIMCHAR, -l LIMCHAR the max characters that the displayed event can contain + --skip SKIP, -s SKIP the number of events to skip from the most recent ``` ### Filter displayed calendars @@ -107,7 +108,7 @@ interval = 60 ``` Example i3block configuration: -``` +```ini [i3-agenda] command=i3-agenda -c ~/.google_credentials.json -ttl 60 interval=60 @@ -116,3 +117,56 @@ interval=60 Example output of the script:\ ```10:55 Grocery shopping``` + +### How to use the `skip` flag to scroll events + +Edit the polybar configuration creating two modules: + +```ini +[module/agenda-ipc] +type = custom/ipc + +hook-0 = i3-agenda -c ~/.google_credentials.json --skip $(cat ~/.config/i3-agenda/i3-agenda-skip.tmp || echo 0) +hook-1 = ~/.config/polybar/scripts/i3agenda-onscroll.sh down && i3-agenda -c ~/.google_credentials.json --skip $(cat ~/.config/i3-agenda/i3-agenda-skip.tmp || echo 0) +hook-2 = ~/.config/polybar/scripts/i3agenda-onscroll.sh up && i3-agenda -c ~/.google_credentials.json --skip $(cat ~/.config/i3-agenda/i3-agenda-skip.tmp || echo 0) + +format = %{F#61afef}%{F-} + +; left click to launch Google Calendar +click-left = firefox https://calendar.google.com/calendar/u/0/r +; right click force update the cache, if for example you just added a new event +click-right = rm ~/.config/i3-agenda/i3-agenda-skip.tmp; i3-agenda -c ~/.config/i3-agenda/client_secret.json --update && notify-send "i3-agenda" "Sync completed" + +; show the previous event +scroll-down = polybar-msg hook agenda-ipc 2 +; show the next event +scroll-up = polybar-msg hook agenda-ipc 3 + +[module/agenda] +type = custom/script +interval = 900 +exec = polybar-msg hook agenda-ipc 1 +label = +``` + +Add both modules to the bar, for example: + +```ini +modules-center = agenda agenda-ipc +``` + +In the polybar scripts folder add the file `i3agenda-onscroll.sh`: + +```bash +#!/usr/bin/env bash +if [ -n "${1}" ]; then + file=~/.config/i3-agenda/i3-agenda-skip.tmp + typeset -i skip=$(cat $file || echo 0) + if [[ "${1}" == "up" ]]; then + skip+=1 + elif [[ "${1}" == "down" && $skip -gt 0 ]]; then + skip=$(( skip - 1)) + fi + echo $skip > $file +fi +``` diff --git a/i3_agenda/__init__.py b/i3_agenda/__init__.py index b552131..4b2437b 100755 --- a/i3_agenda/__init__.py +++ b/i3_agenda/__init__.py @@ -40,6 +40,8 @@ def main(): config.CONF_DIR = args.conf events = load_events(args) + if args.skip > 0: + events = events[args.skip :] closest = get_closest(events, args.hide_event_after) if closest is None: diff --git a/i3_agenda/config.py b/i3_agenda/config.py index ce0eee0..4147fe8 100644 --- a/i3_agenda/config.py +++ b/i3_agenda/config.py @@ -85,3 +85,10 @@ default=-1, help="the max characters that the displayed event can contain", ) +parser.add_argument( + "--skip", + "-s", + type=int, + default=0, + help="the number of events to skip from the most recent", +)