base func

This commit is contained in:
Максим Тотмин 2024-02-16 23:34:57 +07:00
commit 89d372866a
2 changed files with 115 additions and 0 deletions

8
Readme.md Normal file
View File

@ -0,0 +1,8 @@
# Notes Store
Simple pass like notes manager on bash.
To-Do:
* [ ] Update help
* [ ] rm/del notes feature
* [ ] Autocomplite feature
* [ ] Sync with git

107
note Executable file
View File

@ -0,0 +1,107 @@
#!/bin/bash
VER=0.0.1
NOTESPATH="$HOME/.note-store"
CMD_INSERT(){
path=$1
mkdir -p -v "$NOTESPATH/$(dirname -- "$path")" &> /dev/null
path="$NOTESPATH/$path.md"
$EDITOR $path
}
CMD_HELP(){
if [ ! -z $1 ]; then
CMD_INSERT "$@"
else
echo
cat <<-_EOF
Usage:
$PROGRAM init
Initialize new note storage.
$PROGRAM [ls]
List notes.
$PROGRAM [edit] note-name
Insert a new note or edit an existing note using editor.
$PROGRAM help
Show this text.
$PROGRAM version
Show version information.
_EOF
fi
exit 0
}
CMD_INIT(){
test -d $NOTESPATH && echo "Note Store already exist" && exit 0 ||
mkdir $NOTESPATH &> /dev/null
echo "New note storage creted to: $NOTESPATH"
exit 0
}
CMD_SHOWTREE(){
if [ ! -z $1 ]; then
glow -p $NOTESPATH/$1.md
else
echo "Note Store"
tree -N -C -l --noreport $NOTESPATH | tail -n +2 |\
sed -E 's/\.md(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
fi
exit 0
}
CMD_FIND(){
[[ $# -eq 0 ]] && die "Usage: $PROGRAM $COMMAND note-names..."
IFS="," eval 'echo "Search Terms: $*"'
local terms="*$(printf '%s*|*' "$@")"
tree -N -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$NOTESPATH" |\
tail -n +2 | sed -E 's/\.md(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
}
CMD_GREP(){
echo "add to-do grep"
}
CMD_COPY_MOVE() {
move=1
[[ $1 == "copy" ]] && move=0
shift
old_path="$NOTESPATH/${1%/}"
old_dir="$old_path"
new_path="$NOTESPATH/$2"
if [[ $move -eq 1 ]]; then
mv -v "$old_path.md" "$new_path.md" || exit 1
else
cp -r -v "$old_path.md" "$new_path.md" || exit 1
fi
}
CMD_SHOWVERSION(){
echo $PROGRAM version: $VER
}
if [[ ! $1 = init ]]; then
test -d $NOTESPATH || CMD_HELP
fi
if [ -z $1 ]; then
CMD_SHOWTREE
fi
PROGRAM="${0##*/}"
COMMAND="$1"
case "$1" in
init) shift; CMD_INIT "$@" ;;
help|--help) shift; CMD_HELP "$@" ;;
show|ls|list) shift; CMD_SHOWTREE "$@" ;;
find|search) shift; CMD_FIND "$@" ;;
grep) shift; CMD_GREP "$@" ;;
copy|cp) shift; CMD_COPY_MOVE "copy" "$@" ;;
rename|mv) shift; CMD_COPY_MOVE "move" "$@" ;;
edit) shift; CMD_INSERT "$@" ;;
version|-v) CMD_SHOWVERSION ;;
*) CMD_HELP "$@" ;;
esac
find $NOTESPATH* -maxdepth 0 -type f ! -name *.md -delete &> /dev/null
exit 0