kdheepak / taskwarrior-tui

`taskwarrior-tui`: A terminal user interface for taskwarrior
https://kdheepak.com/taskwarrior-tui
MIT License
1.5k stars 68 forks source link

Framework for shortcut functions allowing customization #146

Open jdorel opened 3 years ago

jdorel commented 3 years ago

Description

Currently :

One could have the following in his taskrc file :

uda.taskwarrior-tui.functions.default-user-location=~/.config/taskwarrior-tui/functions/
# Format explained : uda.taskwarrior-tui.functions.default-user-location=<user-defined-functions-default-location>

uda.taskwarrior-tui.functions.set-next-tag.keyconfig=n
# Format explained : uda.taskwarrior-tui.functions.<function_name>.keyconfig=<shortcut_key>

uda.taskwarrior-tui.functions.set-next-tag.location=set-next-tag.sh
# Format explained : uda.taskwarrior-tui.functions.<function_name>.location=<function_location>

And the file ~/.config/taskwarrior-tui/functions/set-next-tag.sh would contain :

task $1 mod +next

Task UUID would be given as an argument to this function call. Maybe some additional informations could be useful ? Or they should be obtained from the UUID ?

We could even do without the uda.taskwarrior-tui.functions.set-next-tag.location if by default we are looking for .sh files (or others like .py). We would use the <function_name> (set-next-tag in the example) as a filename.

Default functions location could be :

/usr/lib/taskwarrior-tui/functions  - For functions installed globally by package manager
/usr/local/lib/taskwarrior-tui/functions  - For functions installed manually for the whole system (maybe it is not necessary ?)
~/.config/taskwarrior-tui/functions  - For functions specific to a user, that could override functions defined in /usr/lib

Advanced implementation could include how to configure combination shortcuts (ex: Ctrl+n) or modal shortcuts (ex: t then n for tag-->next).

Additional context : #140

nickwynja commented 3 years ago

Wanted to share a workaround to the limited number of custom shortcut options until a more substantial framework can be built.

It's a pretty simple shell script that I've bound to one of the numbered shortcuts, then using fzf I can select from a list of scripts. This includes passing along the task IDs as arguments.

#!/bin/bash

TASK=$@

echo "
$HOME/.dotfiles/taskwarrior/create-zettle.sh
$HOME/.dotfiles/taskwarrior/copy-tasks-as-list.sh
$HOME/.dotfiles/tmux/tmux-nav-agenda.sh
$HOME/.dotfiles/taskwarrior/add-phone.sh
$HOME/.dotfiles/taskwarrior/work-plan.sh day
" | fzf --reverse | xargs -I {} sh -c "{} $TASK"

Then in .taskrc, I just call the script with one of the shortcuts.

uda.taskwarrior-tui.shortcuts.6=~/.dotfiles/taskwarrior/tui-script-list.sh

Now I can add as many scripts as I need to the list and access them quickly in the TUI. Ideally, I'd like the level of shortcut customization as found in vim or mutt but I know that's a lot of work.

kdheepak commented 3 years ago

Super neat hack! Thanks for sharing!