From b4086325005e1d8ac18a5f510092bce0a43ba68c Mon Sep 17 00:00:00 2001 From: rmnull Date: Wed, 4 Apr 2018 05:28:47 +0530 Subject: [PATCH 1/5] [draft]testing open on different OS --- notes | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/notes b/notes index 65cdf14..0dfaf61 100755 --- a/notes +++ b/notes @@ -23,6 +23,13 @@ if [ -z "$EDITOR" ] && type editor &>/dev/null; then EDITOR=editor fi +# reference, https://en.wikipedia.org/wiki/Uname +OS=`uname -s` +[[ $OS = "Linux" ]] && open() { xdg-open "$@"; } +# Windows versions have NT in them +[[ $OS = *NT* ]] && open() { false; } # how do I invoke windows commands ? + + without_notes_dir() { cat | sed -e "s/^$escaped_notes_dir//g" | sed -E "s/^\/+//g" } From 2d24fa4b837367b307fca4f99c63c41e6e8ccb52 Mon Sep 17 00:00:00 2001 From: rmnull Date: Mon, 9 Apr 2018 22:23:11 +0530 Subject: [PATCH 2/5] file manager handling --- notes | 69 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/notes b/notes index 0dfaf61..91fcb0e 100755 --- a/notes +++ b/notes @@ -23,12 +23,6 @@ if [ -z "$EDITOR" ] && type editor &>/dev/null; then EDITOR=editor fi -# reference, https://en.wikipedia.org/wiki/Uname -OS=`uname -s` -[[ $OS = "Linux" ]] && open() { xdg-open "$@"; } -# Windows versions have NT in them -[[ $OS = *NT* ]] && open() { false; } # how do I invoke windows commands ? - without_notes_dir() { cat | sed -e "s/^$escaped_notes_dir//g" | sed -E "s/^\/+//g" @@ -58,22 +52,22 @@ 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" \;\ + 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 +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() { @@ -123,7 +117,7 @@ generate_name() { new_note() { local note_name="$*" if [[ $note_name == "" ]]; then - note_name="$(generate_name)" + note_name="$(generate_name)" fi mkdir -p "$(dirname "$notes_dir/$note_name")" @@ -182,11 +176,38 @@ get_full_note_path() { echo "$note_path" } +file_manager() { + if ! command -v uname > /dev/null; then + echo "failed to detect OS" >&2 + exit 1 + fi + + local OS=`uname -s` + # reference, https://en.wikipedia.org/wiki/Uname + if [[ $OS = Linux ]]; then + echo "xdg-open" + elif [[ $OS = Darwin ]]; then + echo "open" + else + echo "Opening directory is currently not supported in $OS, if you + know a work around. You can open an issue by going to the following + url, https://github.com/pimterry/notes/issues/new " >&2 + + exit 1 + fi + +} + open_note() { local note_path=$1 if [[ -z "$note_path" ]]; then - open "$notes_dir" + fm=$(file_manager) + if ! (command -v $fm > /dev/null); then + echo "No default file manager set." >&2 + exit 1 + fi + $fm "$notes_dir" return fi @@ -214,7 +235,7 @@ cat_note() { } usage() { - cat < Date: Fri, 13 Apr 2018 09:15:38 +0530 Subject: [PATCH 3/5] echo before opening dir --- notes | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notes b/notes index 91fcb0e..3541549 100755 --- a/notes +++ b/notes @@ -207,7 +207,9 @@ open_note() { echo "No default file manager set." >&2 exit 1 fi - $fm "$notes_dir" + + echo "Opening $notes_dir" + $fm "$notes_dir" >/dev/null return fi From b32fa922d6da777e1ae2cc70efc08ddfe3c08007 Mon Sep 17 00:00:00 2001 From: rmNULL Date: Fri, 13 Apr 2018 09:19:06 +0530 Subject: [PATCH 4/5] whitespace issues --- notes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes b/notes index 3541549..0b57a27 100755 --- a/notes +++ b/notes @@ -208,7 +208,7 @@ open_note() { exit 1 fi - echo "Opening $notes_dir" + echo "Opening $notes_dir" $fm "$notes_dir" >/dev/null return fi From a9be0fac5c02e09aaf398b251b680581017c3ef8 Mon Sep 17 00:00:00 2001 From: rmNULL Date: Fri, 13 Apr 2018 09:25:33 +0530 Subject: [PATCH 5/5] Update notes --- notes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes b/notes index 0b57a27..5ce3b71 100755 --- a/notes +++ b/notes @@ -209,7 +209,7 @@ open_note() { fi echo "Opening $notes_dir" - $fm "$notes_dir" >/dev/null + $fm "$notes_dir" &>/dev/null # FIX? discarding errors is bad! return fi