command autocompletion & file suggestion
This commit is contained in:
parent
332c70a72d
commit
78be120770
8 changed files with 171 additions and 22 deletions
|
@ -44,4 +44,24 @@ function delnote() {
|
|||
fi
|
||||
fi
|
||||
cd $DIR
|
||||
}
|
||||
}
|
||||
|
||||
_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
|
|
@ -30,6 +30,9 @@ function listnotes() {
|
|||
-f|--folder )
|
||||
. ~/.shellnotes/util/listnotes/f/f.sh
|
||||
;;
|
||||
-v|--view )
|
||||
. ~/.shellnotes/util/listnotes/v/v.sh
|
||||
;;
|
||||
*)
|
||||
if [ -z $1 ]; then
|
||||
if [ -z "$(ls -A $DEFAULT_PATH)" ]; then
|
||||
|
@ -44,3 +47,19 @@ function listnotes() {
|
|||
return 0
|
||||
cd $DIR
|
||||
}
|
||||
|
||||
_listnotes_completion() {
|
||||
local cur prev
|
||||
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
case "$prev" in
|
||||
listnotes)
|
||||
COMPREPLY=( $(compgen -W "-d -n -f -v" -- "$cur") )
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
complete -F _listnotes_completion listnotes
|
|
@ -7,11 +7,12 @@ info
|
|||
|
||||
function newnote() {
|
||||
DIR="$(pwd)"
|
||||
cd $DEFAULT_PATH
|
||||
$NOTES_EDITOR
|
||||
clear
|
||||
str="Note created in $DEFAULT_PATH"
|
||||
underlines=$(echo "$str" | tr -c '\010' '-')
|
||||
echo "$str\n$underlines"
|
||||
cd $HOME
|
||||
# echo $1
|
||||
NOTES_EDITOR
|
||||
# clear
|
||||
# str="Note created in $DEFAULT_PATH"
|
||||
# underlines=$(echo "$str" | tr -c '\010' '-')
|
||||
# echo "$str\n$underlines"
|
||||
cd $DIR
|
||||
}
|
|
@ -213,3 +213,25 @@ function notegrep() {
|
|||
cd $DIR
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
_notegrep_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
|
||||
notegrep)
|
||||
COMPREPLY=( $(compgen -W "-cf -cl -m -sc -sf -sl -ws" -- "$cur") )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
complete -F _notegrep_completion notegrep
|
|
@ -28,4 +28,24 @@ function notewc() {
|
|||
|
||||
cd $DIR
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
_notewc_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
|
||||
notewc)
|
||||
COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") )
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
complete -F _notewc_completion notewc
|
|
@ -55,4 +55,26 @@ function quickread() {
|
|||
fi
|
||||
|
||||
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
|
|
@ -10,32 +10,56 @@ function readnote() {
|
|||
if [ $# -eq 0 ]; then
|
||||
echo -n "Enter note name: " && read notename
|
||||
else
|
||||
notename=$1
|
||||
notename="$1"
|
||||
fi
|
||||
|
||||
if [ -z $notename ]; then
|
||||
if [ -z "$notename" ]; then
|
||||
echo "Invalid input."
|
||||
return 0
|
||||
|
||||
else
|
||||
|
||||
cd $DEFAULT_PATH
|
||||
if [ -e $notename ]; then
|
||||
chmod 0444 $notename
|
||||
$NOTES_EDITOR $notename
|
||||
chmod +rw $notename
|
||||
if [ -e "$notename" ]; then
|
||||
cd "$HOME"
|
||||
# chmod 0444 $notename
|
||||
NOTES_EDITOR "$notename"
|
||||
# chmod +rw $notename
|
||||
|
||||
else
|
||||
clear
|
||||
echo "No such note."
|
||||
echo -n "Do you want to create one?[Y/N]: " && read create;
|
||||
|
||||
case $create in y|Y|YES|Yes|yes )
|
||||
newnote
|
||||
esac
|
||||
fi
|
||||
|
||||
case $create in y|Y|YES|Yes|yes )
|
||||
$NOTES_EDITOR
|
||||
esac
|
||||
|
||||
|
||||
clear
|
||||
cd $DIR
|
||||
# clear
|
||||
cd "$DIR"
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_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
|
|
@ -47,4 +47,25 @@ function renamenote() {
|
|||
cd $DIR
|
||||
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_renamenote_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
|
||||
renamenote)
|
||||
COMPREPLY=( $(compgen -W "${files_list}" -- "$cur") )
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
complete -F _renamenote_completion renamenote
|
Loading…
Reference in a new issue