add remove notes
This commit is contained in:
parent
77989adc72
commit
ef77abb71a
50
note
50
note
@ -61,6 +61,31 @@ CMD_GREP(){
|
|||||||
echo "add to-do grep"
|
echo "add to-do grep"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMD_DELETE(){
|
||||||
|
local opts recursive="" force=0
|
||||||
|
opts="$($GETOPT -o rf -l recursive,force -n "$PROGRAM" -- "$@")"
|
||||||
|
local err=$?
|
||||||
|
eval set -- "$opts"
|
||||||
|
while true; do case $1 in
|
||||||
|
-r|--recursive) recursive="-r"; shift ;;
|
||||||
|
-f|--force) force=1; shift ;;
|
||||||
|
--) shift; break ;;
|
||||||
|
esac done
|
||||||
|
[[ $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--recursive,-r] [--force,-f] note-name"
|
||||||
|
local path="$1"
|
||||||
|
check_sneaky_paths "$path"
|
||||||
|
|
||||||
|
local notedir="$NOTESPATH/${path%/}"
|
||||||
|
local notefile="$NOTESPATH/$path.md"
|
||||||
|
[[ -f $notefile && -d $notedir && $path == */ || ! -f $notefile ]] && notefile="${notedir%/}/"
|
||||||
|
[[ -e $notefile ]] || die "Error: $path is not in the note store."
|
||||||
|
|
||||||
|
[[ $force -eq 1 ]] || yesno "Are you sure you would like to delete $path?"
|
||||||
|
|
||||||
|
rm $recursive -f -v "$notefile"
|
||||||
|
rmdir -p "${notefile%/*}" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
CMD_COPY_MOVE() {
|
CMD_COPY_MOVE() {
|
||||||
move=1
|
move=1
|
||||||
[[ $1 == "copy" ]] && move=0
|
[[ $1 == "copy" ]] && move=0
|
||||||
@ -86,8 +111,30 @@ if [ -z "$1" ]; then
|
|||||||
CMD_SHOWTREE
|
CMD_SHOWTREE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
check_sneaky_paths() {
|
||||||
|
local path
|
||||||
|
for path in "$@"; do
|
||||||
|
[[ $path =~ /\.\.$ || $path =~ ^\.\./ || $path =~ /\.\./ || $path =~ ^\.\.$ ]] && die "Error: You've attempted to pass a sneaky path to pass. Go home."
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
yesno() {
|
||||||
|
[[ -t 0 ]] || return 0
|
||||||
|
local response
|
||||||
|
read -r -p "$1 [y/N] " response
|
||||||
|
[[ $response == [yY] ]] || exit 1
|
||||||
|
}
|
||||||
|
|
||||||
PROGRAM="${0##*/}"
|
PROGRAM="${0##*/}"
|
||||||
COMMAND="$1"
|
COMMAND="$1"
|
||||||
|
GETOPT="getopt"
|
||||||
|
SHRED="shred -f -z"
|
||||||
|
BASE64="base64"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
init) shift; CMD_INIT "$@" ;;
|
init) shift; CMD_INIT "$@" ;;
|
||||||
@ -95,9 +142,10 @@ case "$1" in
|
|||||||
show|ls|list) shift; CMD_SHOWTREE "$@" ;;
|
show|ls|list) shift; CMD_SHOWTREE "$@" ;;
|
||||||
find|search) shift; CMD_FIND "$@" ;;
|
find|search) shift; CMD_FIND "$@" ;;
|
||||||
grep) shift; CMD_GREP "$@" ;;
|
grep) shift; CMD_GREP "$@" ;;
|
||||||
|
delete|rm|remove) shift; CMD_DELETE "$@" ;;
|
||||||
copy|cp) shift; CMD_COPY_MOVE "copy" "$@" ;;
|
copy|cp) shift; CMD_COPY_MOVE "copy" "$@" ;;
|
||||||
rename|mv) shift; CMD_COPY_MOVE "move" "$@" ;;
|
rename|mv) shift; CMD_COPY_MOVE "move" "$@" ;;
|
||||||
edit) shift; CMD_INSERT "$@" ;;
|
edit|add) shift; CMD_INSERT "$@" ;;
|
||||||
version|-v) CMD_SHOWVERSION ;;
|
version|-v) CMD_SHOWVERSION ;;
|
||||||
*) CMD_HELP "$@" ;;
|
*) CMD_HELP "$@" ;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user