Skip to content

Commit

Permalink
add skip flag (#67)
Browse files Browse the repository at this point in the history
* add skip flag

* Update README.md

* updated help in README

Co-authored-by: Tomer Rosenfeld <[email protected]>
  • Loading branch information
notdodo and rosenpin authored Sep 20, 2021
1 parent ef5668a commit 92a4bd2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -107,7 +108,7 @@ interval = 60
```

Example i3block configuration:
```
```ini
[i3-agenda]
command=i3-agenda -c ~/.google_credentials.json -ttl 60
interval=60
Expand All @@ -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-} <output>

; 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
```
2 changes: 2 additions & 0 deletions i3_agenda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions i3_agenda/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

0 comments on commit 92a4bd2

Please sign in to comment.