From e4f2d6ceec4cb491a374f720ebf55aba3b20bcaa Mon Sep 17 00:00:00 2001 From: Dimitris Marakomihelakis Date: Sun, 20 Aug 2023 20:39:53 +0300 Subject: [PATCH] rmdups --- util/rmdups.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 util/rmdups.sh diff --git a/util/rmdups.sh b/util/rmdups.sh new file mode 100644 index 0000000..c88345f --- /dev/null +++ b/util/rmdups.sh @@ -0,0 +1,66 @@ +:<<'info' +shellnotes - rmdups.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 rmdups() { + + _rmdups() { + result="$(awk '!seen[$0]++' $1)" + echo "$result" + echo -n "Replace $notename with the above text?[Y\N]: " && read proceed + case "$proceed" in + Y|y|yes|YES|Yes ) + echo "$result" > $notename + esac + return 0 + } + + + DIR="$(pwd)" + if [ $# -eq 0 ]; then + echo -n "Enter the name of the note whose duplicates you wish to delete: " && read notename + else + notename=$1 + fi + + if [ -z $notename ]; then + echo "Invalid input." + return 0 + + else + cd $DEFAULT_PATH + + if [ -e $notename ]; then + _rmdups "$notename" + else + echo "Invalid argument or parameter given." + cd $DIR + fi + fi + + cd $DIR + +} + +_rmdups_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 + rmdups) + COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") ) + ;; + *) + ;; + esac +} +complete -F _rmdups_completion rmdups \ No newline at end of file