From ac811c693005a19e7223de01df5342cfe35f5568 Mon Sep 17 00:00:00 2001 From: Ben Armstrong Date: Wed, 21 Aug 2013 18:05:08 -0300 Subject: [PATCH] Initial support for context and focus (see Issue #218). --- AUTHORS | 1 + scripts/bash/context | 36 ++++++++++++++++++++++++++++++++++ scripts/bash/focus | 1 + scripts/bash/task_functions.sh | 26 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100755 scripts/bash/context create mode 120000 scripts/bash/focus create mode 100644 scripts/bash/task_functions.sh diff --git a/AUTHORS b/AUTHORS index 9fa393fd5..f0a874e6b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -85,6 +85,7 @@ The following submitted code, packages or analysis, and deserve special thanks: Jakub Wilk Russell Steicke YBSAR + Ben Armstrong Thanks to the following, who submitted detailed bug reports and excellent suggestions: diff --git a/scripts/bash/context b/scripts/bash/context new file mode 100755 index 000000000..f69dca58d --- /dev/null +++ b/scripts/bash/context @@ -0,0 +1,36 @@ +#!/bin/bash +# - These filters not modified, as their purpose is for special review +# not dependent on context or focus: +# - report.all.filter +# - report.completed.filter status:completed +# - What is this -FILTER about in my filters? +# - In each filter, we negate a non-existent virtual tag -FILTER that +# doesn't change what the filter matches but does add a recognizable +# marker. This is used later to substitute the filter with a new one when +# it changes. +# - CAUTION: do not add any additional (i.e. non-context, non-focus) material +# after -FILTER in the report filter variables or else it will be lost next +# time the context or focus is changed. +script_path=$(dirname ${0}) +. "${script_path}/task_functions.sh" + +filter_type=$(basename ${0}) +task_config "${filter_type}.current" "${@}" +context=$(task_get context.current) +focus=$(task_get focus.current) +colored_context="$(task_color 'white on red' ${context})" +colored_focus="$(task_color 'white on blue' ${focus})" +filter="${context} ${focus}" + +filter_vars=$(task_vars filter) +filter_vars=${filter_vars/report.all.filter/} +filter_vars=${filter_vars/report.completed.filter/} +for var in ${filter_vars}; do + old_value=$(task_get ${var}) + old_value=${old_value/%-FILTER*/} + task_config ${var} ${old_value} -FILTER ${filter} +done + +task_config "shell.prompt" "${colored_context}:${colored_focus}>" + +echo "Filter applied to reports and add: ${filter}" diff --git a/scripts/bash/focus b/scripts/bash/focus new file mode 120000 index 000000000..f2159129a --- /dev/null +++ b/scripts/bash/focus @@ -0,0 +1 @@ +context \ No newline at end of file diff --git a/scripts/bash/task_functions.sh b/scripts/bash/task_functions.sh new file mode 100644 index 000000000..f60050e79 --- /dev/null +++ b/scripts/bash/task_functions.sh @@ -0,0 +1,26 @@ +CONFIRM_PROMPT='are you sure' +task_config () +{ + var="${1}" + shift + value="${@}" + echo y | task config $var "$value" | grep -iv "$CONFIRM_PROMPT" +} +task_vars () +{ + task _show | grep "^.*${1}.*=" | cut -d'=' -f1 +} +task_get () +{ + task _show | grep "^${1}=" | cut -d'=' -f2 +} +task_color () +{ + color="${1}" + shift + text="${@}" + task rc.verbose=nothing rc._forcecolor=yes color ${color} | grep 'task color' | \ + tail -n 1 | sed -e 's/^ //' -e "s/task color ${color}/${text}/" +} + +