shellnotes/util/quickread.sh

80 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2021-02-13 10:00:50 +01:00
:<<'info'
shellnotes - quickread.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 quickread() {
DIR="$(pwd)"
check_params() {
2021-07-06 09:56:12 +02:00
case $option in
-l | --line )
. ~/.shellnotes/util/quickread/l/l.sh
;;
-r | --reverse )
. ~/.shellnotes/util/quickread/r/r.sh
;;
-s | --sort )
. ~/.shellnotes/util/quickread/s/s.sh
2021-07-06 10:13:45 +02:00
;;
*)
echo "Invalid parameter." #"\nUSAGE:\nquickread -r/-s -> FILE\nquickread -l -> LINE, FILE"
2021-07-06 09:56:12 +02:00
;;
esac
return 0
}
2021-02-13 10:00:50 +01:00
if [ $# -eq 0 ]; then
echo -n "Enter note name: " && read notename
elif [ $# -gt 1 ]; then
2021-07-06 09:56:12 +02:00
if [ $# -gt 2 ]; then
export option=$1
export line=$2
export notename=$3
else
2021-07-06 10:13:45 +02:00
export option=$1
export notename=$2
2021-07-06 09:56:12 +02:00
fi
check_params
2021-07-06 09:56:12 +02:00
return 0
2021-02-13 10:00:50 +01:00
else
notename=$1
fi
2021-02-13 10:00:50 +01:00
cd $DEFAULT_PATH
if [ -e $notename ]; then
2021-07-06 09:56:12 +02:00
# clear
if [ "$(cat $notename | wc -l)" -ge 25 ]; then
2021-07-05 10:58:11 +02:00
cat $notename | less
else
cat $notename
fi
2021-02-13 10:00:50 +01:00
else
echo "No such note."
2021-02-13 10:00:50 +01:00
fi
2021-04-19 21:20:01 +02:00
cd $DIR
}
_quickread_completion() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" # Get the previous argument
# Generate the list of files in the directory
files=("$DEFAULT_PATH"/*)
files_list="${files[@]##*/}" # Extract file names
case "$prev" in
quickread)
COMPREPLY=( $(compgen -W "-l -r -s" -- "$cur") )
;;
*)
COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") )
;;
esac
}
complete -F _quickread_completion quickread