Skip to content

Commit

Permalink
Update dev to latest src
Browse files Browse the repository at this point in the history
  • Loading branch information
RODNOTGOD committed Dec 30, 2016
1 parent b6e1f74 commit e50ec96
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions _notes
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ __notes_cmd ()
ls:'<pattern> List notes by path'
find:'[pattern] Search notes by filename and path'
grep:'<pattern> Search notes by content'
search:'[pattern] Search notes by filename or content'
open:'<name> Open a notes for editing by full name'
rm:'[-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]'
--help:'Show usage'
Expand Down
26 changes: 26 additions & 0 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ ls_notes() {
fi
}

search_filenames_and_contents() {
if [ "$#" -gt 0 ]; then
find_output=$(find "$notes_dir" -type f -exec bash -c \
"shopt -s nocasematch
grep -il \"$*\" \"{}\" || if [[ \"{}\" =~ \"$*\" ]]; then
echo \"{}\";
fi" \;\
)
else
find_output=$(find "$notes_dir" -type f)
fi
find_result=$?
formatted_output=$(printf "$find_output" | without_notes_dir)

if [[ $find_result == 0 && "$formatted_output" ]]; then
printf "$formatted_output\n"
return 0
else
return 2
fi
}

find_notes() {
local find_output=$(find "$notes_dir" -ipath "$notes_dir/*$**" -type f 2>&1)
local find_result=$?
Expand Down Expand Up @@ -181,6 +203,7 @@ Usage:
notes ls <pattern> # List notes by path
notes find|f [pattern] # Search notes by filename and path
notes grep|g <pattern> # Search notes by content
notes search|s [pattern] # Search notes by filename or content
notes open|o # Open your notes directory
notes open|o <name> # Open a note for editing by full name
notes rm [-r | --recursive] <name> # Remove note, or folder if -r or --recursive is given
Expand Down Expand Up @@ -211,6 +234,9 @@ main() {
"ls" )
cmd="ls_notes"
;;
"search"|"s")
cmd="search_filenames_and_contents"
;;
"find"|"f" )
cmd="find_notes"
;;
Expand Down

0 comments on commit e50ec96

Please sign in to comment.