impr: custom filter and conjuction of filters
This commit is contained in:
147
src/main.sh
147
src/main.sh
@@ -110,28 +110,33 @@ __lines() {
|
|||||||
|
|
||||||
# Program starts here
|
# Program starts here
|
||||||
if [ "${1:-}" = "--help" ]; then
|
if [ "${1:-}" = "--help" ]; then
|
||||||
echo "Usage: $0 [OPTION]"
|
shift
|
||||||
echo ""
|
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
|
||||||
echo "You may specify at most one option."
|
--help Show this help and exit
|
||||||
echo " --help Show this help and exit"
|
--new Create new entry and do not exit
|
||||||
echo " --tasks Show tasks only"
|
|
||||||
echo " --no-tasks Ignore tasks"
|
[FILTER]
|
||||||
echo " --notes Show notes only"
|
You may specify any of these filters. Filters can be negated using the
|
||||||
echo " --no-notes Ignore notes"
|
--no-... versions, e.g., --no-tasks. Multiple filters are applied in
|
||||||
echo " --journal Show journal only"
|
conjuction. By default, the filter --no-completed is used. Note that
|
||||||
echo " --no-journal Ignore journal"
|
--no-completed is not the same as --open, and similarly, --no-open is not the
|
||||||
echo " --completed Show completed tasks only"
|
same as --completed.
|
||||||
echo " --no-completed Ignore completed tasks"
|
|
||||||
echo " --open Show open tasks only"
|
--tasks Show tasks only
|
||||||
echo " --no-open Ignore open tasks"
|
--notes Show notes only
|
||||||
echo " --new Create new entry"
|
--journal Show jounral only
|
||||||
|
--completed Show completed tasks only
|
||||||
|
--open Show open tasks only
|
||||||
|
--filter <query> Specify custom query"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Command line arguments to be self-contained
|
# Command line arguments to be self-contained
|
||||||
# Generate preview of file from selection
|
# Generate preview of file from selection
|
||||||
if [ "${1:-}" = "--preview" ]; then
|
if [ "${1:-}" = "--preview" ]; then
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
shift
|
||||||
|
name=$(echo "$1" | cut -d ' ' -f 3)
|
||||||
|
shift
|
||||||
file="$ROOT/$name"
|
file="$ROOT/$name"
|
||||||
awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
|
awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
|
||||||
$CAT
|
$CAT
|
||||||
@@ -139,7 +144,9 @@ if [ "${1:-}" = "--preview" ]; then
|
|||||||
fi
|
fi
|
||||||
# Delete file from selection
|
# Delete file from selection
|
||||||
if [ "${1:-}" = "--delete" ]; then
|
if [ "${1:-}" = "--delete" ]; then
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
shift
|
||||||
|
name=$(echo "$1" | cut -d ' ' -f 3)
|
||||||
|
shift
|
||||||
file="$ROOT/$name"
|
file="$ROOT/$name"
|
||||||
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file")
|
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file")
|
||||||
while true; do
|
while true; do
|
||||||
@@ -161,6 +168,7 @@ if [ "${1:-}" = "--delete" ]; then
|
|||||||
fi
|
fi
|
||||||
# Generate new entry
|
# Generate new entry
|
||||||
if [ "${1:-}" = "--new" ]; then
|
if [ "${1:-}" = "--new" ]; then
|
||||||
|
shift
|
||||||
collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
||||||
file=""
|
file=""
|
||||||
while [ -f "$file" ] || [ -z "$file" ]; do
|
while [ -f "$file" ] || [ -z "$file" ]; do
|
||||||
@@ -190,7 +198,9 @@ if [ "${1:-}" = "--new" ]; then
|
|||||||
fi
|
fi
|
||||||
# Toggle completed flag
|
# Toggle completed flag
|
||||||
if [ "${1:-}" = "--toggle-completed" ]; then
|
if [ "${1:-}" = "--toggle-completed" ]; then
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
shift
|
||||||
|
name=$(echo "$1" | cut -d ' ' -f 3)
|
||||||
|
shift
|
||||||
file="$ROOT/$name"
|
file="$ROOT/$name"
|
||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
@@ -198,7 +208,9 @@ if [ "${1:-}" = "--toggle-completed" ]; then
|
|||||||
fi
|
fi
|
||||||
# Increase priority
|
# Increase priority
|
||||||
if [ "${1:-}" = "--increase-priority" ]; then
|
if [ "${1:-}" = "--increase-priority" ]; then
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
shift
|
||||||
|
name=$(echo "$1" | cut -d ' ' -f 3)
|
||||||
|
shift
|
||||||
file="$ROOT/$name"
|
file="$ROOT/$name"
|
||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
@@ -206,49 +218,80 @@ if [ "${1:-}" = "--increase-priority" ]; then
|
|||||||
fi
|
fi
|
||||||
# Decrease priority
|
# Decrease priority
|
||||||
if [ "${1:-}" = "--decrease-priority" ]; then
|
if [ "${1:-}" = "--decrease-priority" ]; then
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
shift
|
||||||
|
name=$(echo "$1" | cut -d ' ' -f 3)
|
||||||
|
shift
|
||||||
file="$ROOT/$name"
|
file="$ROOT/$name"
|
||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
mv "$tmpfile" "$file"
|
mv "$tmpfile" "$file"
|
||||||
fi
|
fi
|
||||||
|
# Reload view
|
||||||
if [ "${1:-}" = "--reload" ]; then
|
if [ "${1:-}" = "--reload" ]; then
|
||||||
|
shift
|
||||||
__lines
|
__lines
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
query="${FZF_QUERY:-}"
|
while [ -n "${1:-}" ]; do
|
||||||
if [ "${1:-}" = "--no-completed" ]; then
|
case "${1:-}" in
|
||||||
query="!✅"
|
"--completed")
|
||||||
fi
|
shift
|
||||||
if [ "${1:-}" = "--completed" ]; then
|
cliquery="${cliquery:-} ✅"
|
||||||
query="✅"
|
;;
|
||||||
fi
|
"--no-completed")
|
||||||
if [ "${1:-}" = "--open" ]; then
|
shift
|
||||||
query="🔲"
|
cliquery="${cliquery:-} !✅"
|
||||||
fi
|
;;
|
||||||
if [ "${1:-}" = "--no-open" ]; then
|
"--open")
|
||||||
query="!🔲"
|
shift
|
||||||
fi
|
cliquery="${cliquery:-} 🔲"
|
||||||
if [ "${1:-}" = "--tasks" ]; then
|
;;
|
||||||
query="✅ | 🔲"
|
"--no-open")
|
||||||
fi
|
shift
|
||||||
if [ "${1:-}" = "--no-tasks" ]; then
|
cliquery="${cliquery:-} !🔲"
|
||||||
query="!✅ !🔲"
|
;;
|
||||||
fi
|
"--tasks")
|
||||||
if [ "${1:-}" = "--notes" ]; then
|
shift
|
||||||
query="🗒️"
|
cliquery="${cliquery:-} ✅ | 🔲"
|
||||||
fi
|
;;
|
||||||
if [ "${1:-}" = "--no-notes" ]; then
|
"--no-tasks")
|
||||||
query="!🗒️"
|
shift
|
||||||
fi
|
cliquery="${cliquery:-} !✅ !🔲"
|
||||||
if [ "${1:-}" = "--journal" ]; then
|
;;
|
||||||
query="📘"
|
"--notes")
|
||||||
fi
|
shift
|
||||||
if [ "${1:-}" = "--no-journal" ]; then
|
cliquery="${cliquery:-} 🗒️"
|
||||||
query="!📘"
|
;;
|
||||||
fi
|
"--no-notes")
|
||||||
query=${query:-!✅}
|
shift
|
||||||
|
cliquery="${cliquery:-} !🗒️"
|
||||||
|
;;
|
||||||
|
"--journal")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} 📘"
|
||||||
|
;;
|
||||||
|
"--no-journal")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !📘"
|
||||||
|
;;
|
||||||
|
"--filter")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} $1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--no-filter")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "Unknown option \"$1\""
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
query=${cliquery:-${FZF_QUERY:-!✅}}
|
||||||
query=$(echo "$query" | sed "s/^ *//" | sed "s/ *$//")
|
query=$(echo "$query" | sed "s/^ *//" | sed "s/ *$//")
|
||||||
|
|
||||||
selection=$(
|
selection=$(
|
||||||
|
|||||||
Reference in New Issue
Block a user