Tmux key-binding to open task calender and list tasks
-----------------------------------------------------

Last edited: $Date: 2020/08/25 08:57:43 $

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 werkpad

This starts tmux with a session named "werkpad".

## Configurion of Taskwarrior

I added the following line to my .taskrc:

   calendar.details=full

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


## Configurion 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 =werkpad:=twcal' '' \
'new-window -n twcal' \; send-keys -t '=werkpad:=twcal' 'task calendar' C-m \; \
 select-window -t =werkpad:=twcal

The break-down of this is as folows.

bind T :
   bind the command to key <shift>-T

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

tmux has-session -t =werkpad:=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 '=werkpad:=twcal' :
  send following command to the window named 'twcal'

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

\; :
 start new command after opening task calendar

select-window -t =werkpad:=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 isblazingly fast
* Test if named window exsists is not very much
 documented

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