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