From 145846d37aec5cede307456ddf534c8d10d3a7fb Mon Sep 17 00:00:00 2001 From: Maksim Totmin Date: Mon, 20 May 2024 15:58:09 +0700 Subject: [PATCH] micro change ) --- Readme.md | 4 ++-- {menu => addon}/wofi/menunote | 4 ++-- note | 36 ++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 15 deletions(-) rename {menu => addon}/wofi/menunote (93%) diff --git a/Readme.md b/Readme.md index 361b73d..512b2fc 100644 --- a/Readme.md +++ b/Readme.md @@ -2,7 +2,7 @@ Simple pass like notes manager on bash. To-Do: -* [ ] Update help -* [ ] rm/del notes feature +* [x] Update help +* [x] rm/del notes feature * [x] Autocomplite feature * [ ] Sync with git diff --git a/menu/wofi/menunote b/addon/wofi/menunote similarity index 93% rename from menu/wofi/menunote rename to addon/wofi/menunote index be932f1..928c8e1 100644 --- a/menu/wofi/menunote +++ b/addon/wofi/menunote @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash PN="$HOME/.note-store/" touch $PN/readme.md echo "# NotesMenu" > $PN/readme.md @@ -16,4 +16,4 @@ fi CHOISE="$ED '$PN$CHOISE'" env TEMP=xterm-256color $TR "$CHOISE" -exit 0 \ No newline at end of file +exit 0 diff --git a/note b/note index 41b4b1c..d3b1af7 100755 --- a/note +++ b/note @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash VER=0.0.1 NOTESPATH="$HOME/.note-store" @@ -18,10 +18,12 @@ CMD_HELP(){ Usage: $PROGRAM init Initialize new note storage. - $PROGRAM [ls] + $PROGRAM [ls] [subfolder] List notes. - $PROGRAM [edit] note-name + $PROGRAM edit note-name Insert a new note or edit an existing note using editor. + $PROGRAM rm [--recursive,-r] [--force,-f] note-name + Remove existing note or directory, optionally forcefully. $PROGRAM help Show this text. $PROGRAM version @@ -32,19 +34,31 @@ _EOF } CMD_INIT(){ - test -d "$NOTESPATH" && echo "Note Store already exist" && exit 0 || - mkdir "$NOTESPATH" &> /dev/null + local path="${1%/}" + local notefile="$NOTESPATH/$path.md" + check_sneaky_paths "$path" + + [[ $force -eq 0 && -e $passfile ]] && yesno "An entry already exists for $path. Overwrite it?" + + mkdir -p -v "$NOTESPATH/$(dirname -- "$path")" + 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 |\ + local path="$1" + local notefile="$NOTESPATH/$path.md" + if [ -d $NOTESPATH/$path ]; then + if [[ -z $path ]]; then + echo "Note Store" + else + echo "${path%\/}" + fi + tree -N -C -l --noreport "$NOTESPATH/$path" | tail -n +2 |\ sed -E 's/\.md(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' + else + glow -p $NOTESPATH/$path.md fi exit 0 } @@ -63,6 +77,7 @@ CMD_GREP(){ CMD_DELETE(){ local opts recursive="" force=0 + te opts="$($GETOPT -o rf -l recursive,force -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" @@ -134,7 +149,6 @@ PROGRAM="${0##*/}" COMMAND="$1" GETOPT="getopt" SHRED="shred -f -z" -BASE64="base64" case "$1" in init) shift; CMD_INIT "$@" ;;