feat: --list option to list entries and exit
This commit is contained in:
20
src/main.sh
20
src/main.sh
@@ -36,9 +36,10 @@ __lines() {
|
||||
# Program starts here
|
||||
if [ "${1:-}" = "--help" ]; then
|
||||
shift
|
||||
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
|
||||
echo "Usage: $(basename $0) [--help | --new [FILTER..] | --list [FILTER..] | [FILTER..] ]
|
||||
--help Show this help and exit
|
||||
--new Create new entry and do not exit
|
||||
--list List entries and exit
|
||||
--git-init Activate git usage and exit
|
||||
--git <cmd> Run git command and exit
|
||||
|
||||
@@ -51,7 +52,7 @@ if [ "${1:-}" = "--help" ]; then
|
||||
|
||||
--tasks Show tasks only
|
||||
--notes Show notes only
|
||||
--journal Show jounral only
|
||||
--journal Show journal only
|
||||
--completed Show completed tasks only
|
||||
--open Show open tasks only
|
||||
--filter <query> Specify custom query"
|
||||
@@ -64,7 +65,7 @@ fi
|
||||
# Command line arguments: Interal use
|
||||
. "sh/cliinternal.sh"
|
||||
|
||||
# Command line arguments: Interal use
|
||||
# Command line arguments
|
||||
. "sh/cli.sh"
|
||||
|
||||
# Attachment handling
|
||||
@@ -73,10 +74,21 @@ fi
|
||||
# Categories handling
|
||||
. "sh/categories.sh"
|
||||
|
||||
if [ -n "${list_option:-}" ]; then
|
||||
__lines |
|
||||
$FZF \
|
||||
--filter="$query" \
|
||||
--no-sort \
|
||||
--with-nth=5.. |
|
||||
tac
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while true; do
|
||||
query=$(stripws "$query")
|
||||
selection=$(
|
||||
__lines | $FZF --ansi \
|
||||
__lines | $FZF \
|
||||
--ansi \
|
||||
--query="$query " \
|
||||
--no-sort \
|
||||
--no-hscroll \
|
||||
|
||||
@@ -5,7 +5,9 @@ __add_attachment() {
|
||||
file="$1"
|
||||
shift
|
||||
sel=$(
|
||||
$FZF --prompt="Select attachment> " \
|
||||
$FZF \
|
||||
--ansi \
|
||||
--prompt="Select attachment> " \
|
||||
--walker="file,hidden" \
|
||||
--walker-root="$HOME" \
|
||||
--expect="ctrl-c,ctrl-g,ctrl-q,esc"
|
||||
@@ -137,6 +139,7 @@ __attachment_view() {
|
||||
att=$(
|
||||
awk "$AWK_ATTACHLS" "$file" |
|
||||
$FZF \
|
||||
--ansi \
|
||||
--delimiter="\t" \
|
||||
--accept-nth=1,2,3,4 \
|
||||
--with-nth="Attachment {1}: \"{2}\" {3} ({5})" \
|
||||
|
||||
@@ -7,7 +7,9 @@ __select_category() {
|
||||
sort |
|
||||
uniq |
|
||||
grep '.' |
|
||||
$FZF --prompt="Select category> " \
|
||||
$FZF \
|
||||
--ansi \
|
||||
--prompt="Select category> " \
|
||||
--no-sort \
|
||||
--tac \
|
||||
--margin="30%,30%" \
|
||||
|
||||
@@ -31,6 +31,12 @@ if [ "${1:-}" = "--new" ]; then
|
||||
__new
|
||||
fi
|
||||
|
||||
# Switch to list mode
|
||||
if [ "${1:-}" = "--list" ]; then
|
||||
shift
|
||||
export list_option=1
|
||||
fi
|
||||
|
||||
# Build query
|
||||
while [ -n "${1:-}" ]; do
|
||||
case "${1:-}" in
|
||||
|
||||
@@ -6,7 +6,11 @@ fi
|
||||
# shellcheck source=/dev/null
|
||||
. "$CONFIGFILE"
|
||||
if [ -z "${ROOT:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
|
||||
err "Configuration is incomplete."
|
||||
err "Configuration '$CONFIGFILE' is incomplete."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$ROOT" ]; then
|
||||
err "Directory '$ROOT' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
SYNC_CMD="${SYNC_CMD:-}"
|
||||
@@ -14,7 +18,12 @@ export ROOT
|
||||
export SYNC_CMD
|
||||
export COLLECTION_LABELS
|
||||
for i in $(seq 9); do
|
||||
collection=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 1)
|
||||
label=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 2)
|
||||
if [ -n "$label" ] && [ ! -d "$ROOT/$collection" ]; then
|
||||
err "Collection directory for '$label' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$label" ]; then
|
||||
export COLLECTION_COUNT=$((i - 1))
|
||||
break
|
||||
@@ -24,7 +33,7 @@ done
|
||||
|
||||
# Tools
|
||||
if command -v "fzf" >/dev/null; then
|
||||
FZF="fzf"
|
||||
FZF="fzf --black"
|
||||
else
|
||||
err "Did not find the command-line fuzzy finder fzf."
|
||||
exit 1
|
||||
|
||||
@@ -112,7 +112,9 @@ __new() {
|
||||
collection=$(printf "%s" "$COLLECTION_LABELS" |
|
||||
tr ';' '\n' |
|
||||
$FZF \
|
||||
--ansi \
|
||||
--prompt="Choose collection> " \
|
||||
--select-1 \
|
||||
--no-sort \
|
||||
--tac \
|
||||
--margin="30%,30%" \
|
||||
@@ -146,6 +148,9 @@ __new() {
|
||||
while [ "$checksum" != "$(cksum "$tmpmd")" ]; do
|
||||
tmpfile="$tmpmd.ics"
|
||||
if awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"; then
|
||||
if [ ! -d "$ROOT/$collection" ]; then
|
||||
mkdir -p "$ROOT/$collection"
|
||||
fi
|
||||
mv "$tmpfile" "$file"
|
||||
if [ -n "${GIT:-}" ]; then
|
||||
$GIT add "$file"
|
||||
|
||||
Reference in New Issue
Block a user