Quick access added, -l switch and number to display specific note to stdout.
This commit is contained in:
28
notestorm
28
notestorm
@@ -151,6 +151,16 @@ delete_note() {
|
||||
}
|
||||
|
||||
display_note() {
|
||||
if [[ "$1" =~ [0-9]+ ]]; then
|
||||
mapfile -t notes < <(find "$xdgPath/notestorm/notes" -type f -iname '*.md')
|
||||
if [[ $1 -ge "${#notes[@]}" ]]; then
|
||||
gettext "The requested note could not be found. Try using -l to get a list."
|
||||
echo "($1)"
|
||||
exit 1
|
||||
fi
|
||||
cat "${notes[1]}"
|
||||
exit 0
|
||||
fi
|
||||
if [[ "${1##*.}" == "gpg" ]]; then
|
||||
gpg -d "$1" | markdown | eval "$pager"
|
||||
else
|
||||
@@ -189,6 +199,14 @@ encrypt_note() {
|
||||
infobox "$(gettext "Encryption failed.")"
|
||||
}
|
||||
|
||||
list_notes() {
|
||||
# Return a numbered list of unencrypted notes.
|
||||
mapfile -t notes < <(find "$xdgPath/notestorm/notes" -type f -iname '*.md')
|
||||
for i in "${!notes[@]}" ; do
|
||||
echo "$i: ${notes[i]##*/}"
|
||||
done
|
||||
}
|
||||
|
||||
original_note() {
|
||||
# If no notes are present this will try to copy the README.md file into the notes directory so the menu won't fail.
|
||||
mapfile -t notes < <(find "$xdgPath/notestorm/notes" -type f -iname '*.md' -o -iname '*.gpg')
|
||||
@@ -207,6 +225,7 @@ original_note() {
|
||||
# Configuration section
|
||||
# Available arguments in both long and short versions stored in associative array.
|
||||
declare -A argList=(
|
||||
[l]="list"
|
||||
[n]="new")
|
||||
# Make the args a continuous string.
|
||||
short="${!argList[*]}"
|
||||
@@ -247,12 +266,20 @@ fi
|
||||
|
||||
# Code section
|
||||
|
||||
# If the only arg is a number, display that note, then exit.
|
||||
if [[ "$*" =~ [0-9]+ ]]; then
|
||||
display_note $*
|
||||
fi
|
||||
|
||||
# Parse non-numeric command line args.
|
||||
if ! options=$(getopt -o "$short" -l "$long" -n "notestorm" -- "$@"); then
|
||||
gettext -e "Usage: notestorm launch interactive session.\n"
|
||||
gettext -e -- "-n or --new add a new note without opening an interactive session.\n"
|
||||
echo
|
||||
gettext -e "You can use markdown syntax in notes.\n"
|
||||
gettext -e "Notes are named numerically. they can be renamed and will still show up so long as they end with a .md extension.\n"
|
||||
gettext -e "To get a numbered list, instead of the interactive menu, use the -l option.\n"
|
||||
gettext -e "To show a note without using the interactive interface and pager, give the notes number as the only argument.\n"
|
||||
gettext "Notes are saved in "
|
||||
echo "${xdgPath}/notestorm/notes"
|
||||
exit 1
|
||||
@@ -263,6 +290,7 @@ eval set -- "$options"
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
"-n"|"--new") add_note;;
|
||||
"-l"|"--list") list_notes;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user