Compare commits
No commits in common. "master" and "master" have entirely different histories.
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Simple pass like notes manager on bash.
|
Simple pass like notes manager on bash.
|
||||||
To-Do:
|
To-Do:
|
||||||
* [x] Update help
|
* [ ] Update help
|
||||||
* [x] rm/del notes feature
|
* [ ] rm/del notes feature
|
||||||
* [x] Autocomplite feature
|
* [ ] Autocomplite feature
|
||||||
* [ ] Sync with git
|
* [ ] Sync with git
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
PN="$HOME/.note-store/"
|
|
||||||
touch $PN/readme.md
|
|
||||||
echo "# NotesMenu" > $PN/readme.md
|
|
||||||
TR="kitty sh -c"
|
|
||||||
ED="vim"
|
|
||||||
|
|
||||||
find $PN* -maxdepth 0 -type f ! -name *.md -delete
|
|
||||||
QT=$(ls $PN | wc -l)
|
|
||||||
|
|
||||||
CHOISE=$(find "$PN" -iname '*.md' -type f | awk -F 'store/' '{print $NF;}' | wofi -d) || exit 1
|
|
||||||
|
|
||||||
if [[ "$CHOISE" != *.md ]]; then
|
|
||||||
CHOISE="$CHOISE.md"
|
|
||||||
fi
|
|
||||||
CHOISE="$ED '$PN$CHOISE'"
|
|
||||||
env TEMP=xterm-256color $TR "$CHOISE"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
#compdef note
|
|
||||||
#
|
|
||||||
# Completion script for note
|
|
||||||
#
|
|
||||||
|
|
||||||
_note () {
|
|
||||||
local cmd
|
|
||||||
if (( CURRENT > 2)); then
|
|
||||||
cmd=${words[2]}
|
|
||||||
curcontext="${curcontext%:*:*}:note-$cmd"
|
|
||||||
(( CURRENT-- ))
|
|
||||||
shift words
|
|
||||||
case "${cmd}" in
|
|
||||||
init)
|
|
||||||
;;
|
|
||||||
find)
|
|
||||||
_note_complete_entries_with_subdirs
|
|
||||||
;;
|
|
||||||
show|ls|list|edit)
|
|
||||||
_note_complete_entries_with_subdirs
|
|
||||||
;;
|
|
||||||
cp|copy|mv|rename|rm)
|
|
||||||
_note_complete_entries_with_subdirs
|
|
||||||
;;
|
|
||||||
rm|delete|remove)
|
|
||||||
_note_complete_entries_with_subdirs
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
local -a subcommands
|
|
||||||
subcommands=(
|
|
||||||
"init:Initialize new note storage"
|
|
||||||
"ls:List note"
|
|
||||||
"find:Find note files or directories based on pattern"
|
|
||||||
"grep:Search note files for matching pattern"
|
|
||||||
"show:Print a note"
|
|
||||||
"edit:Edit a note with \$EDITOR"
|
|
||||||
"mv:Rename the note"
|
|
||||||
"cp:Copy the note"
|
|
||||||
"rm:Remove the note"
|
|
||||||
"version:Output version information"
|
|
||||||
"help:Output help message"
|
|
||||||
)
|
|
||||||
_describe -t commands 'note' subcommands
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_note_complete_entries_helper () {
|
|
||||||
local IFS=$'\n'
|
|
||||||
local notepath
|
|
||||||
zstyle -s ":completion:${curcontext}:" notepath notepath || notepath="${NOTE_STORE_DIR:-$HOME/.note-store}"
|
|
||||||
_values -C 'notes' ${$(find -L "$notepath" \( -name .git \) -prune -o $@ -print 2>/dev/null | sed -e "s#${notepath}/\{0,1\}##" -e 's#\.md##' -e 's#\\#\\\\#g' -e 's#:#\\:#g' | sort):-""}
|
|
||||||
}
|
|
||||||
|
|
||||||
_note_complete_entries_with_subdirs () {
|
|
||||||
_note_complete_entries_helper
|
|
||||||
}
|
|
||||||
|
|
||||||
_note_complete_entries () {
|
|
||||||
_note_complete_entries_helper -type f
|
|
||||||
}
|
|
||||||
|
|
||||||
_note
|
|
||||||
96
note
96
note
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
VER=0.0.1
|
VER=0.0.1
|
||||||
NOTESPATH="$HOME/.note-store"
|
NOTESPATH="$HOME/.note-store"
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ CMD_INSERT(){
|
|||||||
path=$1
|
path=$1
|
||||||
mkdir -p -v "$NOTESPATH/$(dirname -- "$path")" &> /dev/null
|
mkdir -p -v "$NOTESPATH/$(dirname -- "$path")" &> /dev/null
|
||||||
path="$NOTESPATH/$path.md"
|
path="$NOTESPATH/$path.md"
|
||||||
$EDITOR "$path"
|
$EDITOR $path
|
||||||
}
|
}
|
||||||
|
|
||||||
CMD_HELP(){
|
CMD_HELP(){
|
||||||
@ -18,12 +18,10 @@ CMD_HELP(){
|
|||||||
Usage:
|
Usage:
|
||||||
$PROGRAM init
|
$PROGRAM init
|
||||||
Initialize new note storage.
|
Initialize new note storage.
|
||||||
$PROGRAM [ls] [subfolder]
|
$PROGRAM [ls]
|
||||||
List notes.
|
List notes.
|
||||||
$PROGRAM edit note-name
|
$PROGRAM [edit] note-name
|
||||||
Insert a new note or edit an existing note using editor.
|
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
|
$PROGRAM help
|
||||||
Show this text.
|
Show this text.
|
||||||
$PROGRAM version
|
$PROGRAM version
|
||||||
@ -34,31 +32,19 @@ _EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
CMD_INIT(){
|
CMD_INIT(){
|
||||||
local path="${1%/}"
|
test -d $NOTESPATH && echo "Note Store already exist" && exit 0 ||
|
||||||
local notefile="$NOTESPATH/$path.md"
|
mkdir $NOTESPATH &> /dev/null
|
||||||
check_sneaky_paths "$path"
|
echo "New note storage creted to: $NOTESPATH"
|
||||||
|
|
||||||
[[ $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
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
CMD_SHOWTREE(){
|
CMD_SHOWTREE(){
|
||||||
local path="$1"
|
if [ ! -z $1 ]; then
|
||||||
local notefile="$NOTESPATH/$path.md"
|
glow -p $NOTESPATH/$1.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
|
else
|
||||||
glow -p $NOTESPATH/$path.md
|
echo "Note Store"
|
||||||
|
tree -N -C -l --noreport $NOTESPATH | tail -n +2 |\
|
||||||
|
sed -E 's/\.md(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
@ -75,32 +61,6 @@ CMD_GREP(){
|
|||||||
echo "add to-do grep"
|
echo "add to-do grep"
|
||||||
}
|
}
|
||||||
|
|
||||||
CMD_DELETE(){
|
|
||||||
local opts recursive="" force=0
|
|
||||||
te
|
|
||||||
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
|
||||||
@ -119,36 +79,15 @@ CMD_SHOWVERSION(){
|
|||||||
echo $PROGRAM version: $VER
|
echo $PROGRAM version: $VER
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ ! "$1" = init ]]; then
|
if [[ ! $1 = init ]]; then
|
||||||
test -d "$NOTESPATH" || CMD_HELP
|
test -d $NOTESPATH || CMD_HELP
|
||||||
fi
|
fi
|
||||||
if [ -z "$1" ]; then
|
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 note a sneaky path to note. 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"
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
init) shift; CMD_INIT "$@" ;;
|
init) shift; CMD_INIT "$@" ;;
|
||||||
@ -156,14 +95,13 @@ 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|add) shift; CMD_INSERT "$@" ;;
|
edit) shift; CMD_INSERT "$@" ;;
|
||||||
version|-v) CMD_SHOWVERSION ;;
|
version|-v) CMD_SHOWVERSION ;;
|
||||||
*) CMD_HELP "$@" ;;
|
*) CMD_HELP "$@" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
find "$NOTESPATH"* -maxdepth 0 -type f ! -name *.md -delete &> /dev/null
|
find $NOTESPATH* -maxdepth 0 -type f ! -name *.md -delete &> /dev/null
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user