Skip to content

Instantly share code, notes, and snippets.

@lenalebt
Last active March 14, 2020 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenalebt/5dfb68270e9076e5a8b8537e12a0c019 to your computer and use it in GitHub Desktop.
Save lenalebt/5dfb68270e9076e5a8b8537e12a0c019 to your computer and use it in GitHub Desktop.
How to build a temporary context for taskwarrior
#I added a temporary context for taskwarrior using some bash commands and aliases.
#Here I show how it works.
#
#I wanted my bash prompt to show my temporary context, and I wanted that temporary context to be easily set and reset.
#you may find this at /usr/share/bash-completion/completions instead of in your home directory
source ~/.bash_completion.d/task.sh
alias task='task $DEFAULT_TASK_OPTIONS'
#short for task add, automatically marking it as something new ("inbox") and for something not work-related
alias ta='task add +home +inbox $DEFAULT_TASK_OPTIONS'
#same for work-related
alias taw='task add +work +inbox $DEFAULT_TASK_OPTIONS'
#short for task-set-context, call it e.g. "tsc project:camper_trailer" to set a context or without params to reset it
function tsc {
export DEFAULT_TASK_OPTIONS=$(echo "$@" | xargs)
}
export -f tsc
function _my_prompt_command {
#LP_PS1_PREFIX is from liquidprompt. You could manipulate your PS1 variable directly here instead
if [ -n "$DEFAULT_TASK_OPTIONS" ]; then
LP_PS1_PREFIX="[\e[33m$DEFAULT_TASK_OPTIONS\e[39m] "
else
LP_PS1_PREFIX=""
fi
_lp_set_prompt
}
export -f _my_prompt_command
export PROMPT_COMMAND=_my_prompt_command
#make sure we have the nice auto-completion for e.g. projects and tags also for our aliases
complete -o nospace -F _task ta
complete -o nospace -F _task taw
complete -o nospace -F _task tsc
lena@lena-XPS-13-9360:~ $ tsc project:demo
[project:demo] lena@lena-XPS-13-9360:~ $ task add demotask
Created task 216.
The project 'demo' has changed. Project 'demo' is 0% complete (1 task remaining).
[project:demo] lena@lena-XPS-13-9360:~ $ task
[task next ( project:demo )]
ID Age Project Description Urg
216 4s demo demotask 1
1 task
There are local changes. Sync required.
[project:demo] lena@lena-XPS-13-9360:~ $ task add demotask 2
Created task 217.
The project 'demo' has changed. Project 'demo' is 0% complete (2 of 2 tasks remaining).
[project:demo] lena@lena-XPS-13-9360:~ $ task
[task next ( project:demo )]
ID Age Project Description Urg
216 18s demo demotask 1
217 2s demo demotask 2 1
2 tasks
There are local changes. Sync required.
[project:demo] lena@lena-XPS-13-9360:~ $ tsc demo2
[demo2] lena@lena-XPS-13-9360:~ $ task
[task next ( demo2 )]
No matches.
There are local changes. Sync required.
[demo2] lena@lena-XPS-13-9360:~ $ tsc
lena@lena-XPS-13-9360:~ $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment