box.matto.nl
Enjoying Open Source Software

Tmux key-binding to open task calender and list tasks

I have been searching for a way to show my Taskwarrior calendar and tasks with a single key-binding in Tmux.

Automatic start of Tmux

I start Tmux from my i3-config with:

exec --no-startup-id $term -e tmux new-session -s workpad

This starts tmux with a session named "workpad".

Configuration of Taskwarrior

I added the following line to my .taskrc:

calendar.details=full

With this, the command 'task calendar' shows the calendar for the current and upcoming months with some nice colors, as well as a list of the tasks, including the due dates.

Configuration of Tmux

After some trial-and-error I came to the following lines in my .tmux.conf:

bind T if-shell 'tmux has-session -t =workpad:=twcal' '' \
 'new-window -n twcal' \; send-keys -t '=workpad:=twcal' \
 'task calendar' C-m \; \
 select-window -t =workpad:=twcal

The break-down of this is as follows.

bind T :
bind the command to key -T

if-shell :
tmux command to do some if-then-else thing

tmux has-session -t =workpad:=twcal':
test if window named 'twcal' exists

'' :
if true, do nothing

'new-window -n twcal :
if false, create new window named 'twcal'

\; :
start new command after if-then-else thing

send-keys -t '=workpad:=twcal' :
send following command to the window named 'twcal'

'task calendar' C-m :
command to start task calendar followed by (C-m)

\; :
start new command after opening task calendar

select-window -t =workpad:=twcal :
set focus to the window named 'twcal'

This last part (select-window) is necessary when the window named 'twcal' already exists and does not has the focus.

Not rocket science

OK, this is very simple. there are two reasons why I publish this:

  • It is blazing fast
  • Test if named window exists is not very easy to find

Also, for me the Taskwarrior calendar followed by the list of tasks including due-dates is very, very useful. And it has nice colors :)

Tags:

⇽ Open external URL in Vim vsplit with w3m Using Vimwiki tags ⇾