2021-02-10 17:10:49 +01:00
|
|
|
:<<'info'
|
|
|
|
shellnotes - readnote.sh
|
|
|
|
(C) Dimitris Marakomihelakis
|
|
|
|
Released under the "All rights reserved" category. See the RIGHTS.txt file
|
|
|
|
in /docs/github/ for its full text.
|
|
|
|
info
|
|
|
|
|
|
|
|
function readnote() {
|
2021-07-05 14:49:58 +02:00
|
|
|
DIR="$(pwd)"
|
2021-02-10 17:10:49 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo -n "Enter note name: " && read notename
|
|
|
|
else
|
2023-08-21 16:48:30 +02:00
|
|
|
notename="$1"
|
2021-02-10 17:10:49 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-21 16:48:30 +02:00
|
|
|
if [ -z "$notename" ]; then
|
2021-04-25 12:23:38 +02:00
|
|
|
echo "Invalid input."
|
|
|
|
return 0
|
|
|
|
|
2021-02-10 17:10:49 +01:00
|
|
|
else
|
2021-04-25 12:23:38 +02:00
|
|
|
|
|
|
|
cd $DEFAULT_PATH
|
2023-08-21 16:48:30 +02:00
|
|
|
if [ -e "$notename" ]; then
|
|
|
|
cd "$HOME"
|
|
|
|
# chmod 0444 $notename
|
|
|
|
NOTES_EDITOR "$notename"
|
|
|
|
# chmod +rw $notename
|
2021-04-25 12:23:38 +02:00
|
|
|
|
|
|
|
else
|
|
|
|
clear
|
|
|
|
echo "No such note."
|
|
|
|
echo -n "Do you want to create one?[Y/N]: " && read create;
|
2023-08-21 16:48:30 +02:00
|
|
|
|
|
|
|
case $create in y|Y|YES|Yes|yes )
|
|
|
|
newnote
|
|
|
|
esac
|
2021-04-25 12:23:38 +02:00
|
|
|
fi
|
|
|
|
|
2023-08-21 16:48:30 +02:00
|
|
|
|
2021-04-25 12:23:38 +02:00
|
|
|
|
2023-08-21 16:48:30 +02:00
|
|
|
# clear
|
|
|
|
cd "$DIR"
|
2021-02-10 17:10:49 +01:00
|
|
|
fi
|
2023-08-21 16:48:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_readnote_completion() {
|
|
|
|
local cur prev
|
|
|
|
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
|
|
|
|
# Generate the list of files in the directory
|
|
|
|
files=("$DEFAULT_PATH"/*)
|
|
|
|
files_list="${files[@]##*/}" # Extract file names
|
|
|
|
|
|
|
|
case "$prev" in
|
|
|
|
readnote)
|
|
|
|
COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") )
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
complete -F _readnote_completion readnote
|