2021-02-08 15:29:47 +01:00
|
|
|
:<<'info'
|
|
|
|
shellnotes - delnote.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 delnote() {
|
2021-07-05 14:49:58 +02:00
|
|
|
DIR="$(pwd)"
|
2021-02-08 15:29:47 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo -n "Enter the name of the note you want to delete: " && read delete
|
|
|
|
else
|
|
|
|
delete=$1
|
|
|
|
fi
|
2021-04-25 12:23:38 +02:00
|
|
|
|
|
|
|
if [ -z $delete ]; then
|
|
|
|
echo "Invalid input."
|
|
|
|
return 0
|
|
|
|
|
|
|
|
else
|
2021-02-08 15:29:47 +01:00
|
|
|
if [[ $1 == "-all" ]]; then
|
2021-04-25 12:23:38 +02:00
|
|
|
cd $DEFAULT_PATH
|
|
|
|
rm -f *
|
|
|
|
clear
|
|
|
|
cd $DIR
|
|
|
|
str="All files deleted from $DEFAULT_PATH"
|
|
|
|
underlines=$(echo "$str" | tr -c '\010' '-')
|
|
|
|
echo "$str\n$underlines"
|
|
|
|
|
2021-02-08 15:29:47 +01:00
|
|
|
else
|
|
|
|
cd $DEFAULT_PATH
|
2021-04-25 12:23:38 +02:00
|
|
|
|
2021-02-08 15:29:47 +01:00
|
|
|
if [ -e $delete ]; then
|
|
|
|
rm $delete
|
|
|
|
clear
|
2021-04-19 21:20:01 +02:00
|
|
|
cd $DIR
|
|
|
|
str="Note deleted from $DEFAULT_PATH"
|
2021-02-08 15:29:47 +01:00
|
|
|
underlines=$(echo "$str" | tr -c '\010' '-')
|
|
|
|
echo "$str\n$underlines"
|
|
|
|
else
|
2021-04-25 12:23:38 +02:00
|
|
|
echo "Invalid argument or parameter given."
|
2021-04-19 21:20:01 +02:00
|
|
|
cd $DIR
|
2021-02-08 15:29:47 +01:00
|
|
|
fi
|
|
|
|
fi
|
2021-04-25 12:23:38 +02:00
|
|
|
fi
|
2021-07-05 14:49:58 +02:00
|
|
|
cd $DIR
|
2023-08-21 16:48:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_delnote_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
|
|
|
|
delnote)
|
|
|
|
COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") )
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
complete -F _delnote_completion delnote
|