From 2d007ac4333489503d70a6b65f934e5f9959ca6a Mon Sep 17 00:00:00 2001 From: brokenpip3 Date: Wed, 23 Jan 2019 00:09:16 +0100 Subject: [PATCH 1/2] initial git support --- notes | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/notes b/notes index b71b205..5088689 100755 --- a/notes +++ b/notes @@ -211,6 +211,29 @@ cat_note() { cat "$note_path" } +init_note() { + local gitrepo=$1 + # Check if directory already exist + if [ -d "$notes_dir" ]; then + printf "Directory "$notes_dir" already exits.\n" + exit 1 + fi + # Create git empty repo or clone from existing one if git repo is given + if [ -z "$gitrepo" ]; then + mkdir -p $notes_dir + git -C $notes_dir init + else + git clone $gitrepo $notes_dir + fi +} + +git_cmd_note() { + + local git_cmd=$1 + git -C $notes_dir "$git_cmd" + +} + usage() { cat < # Open a note for editing by full name notes rm [-r | --recursive] # Remove note, or folder if -r or --recursive is given notes cat # Display note + notes git # Git command (status, pull, push etc) + notes init|i # Initialize git repository or clone from existing echo | notes open|o # Open all note filenames piped in echo | notes cat # Display all note filenames piped in notes --help # Print this usage information @@ -271,6 +296,12 @@ main() { "cat" ) cmd="handle_multiple_notes cat" ;; + "git" ) + cmd="git_note" + ;; + "init"|"i" ) + cmd="init_note" + ;; --help | -help | -h ) cmd="usage" ;; @@ -287,4 +318,3 @@ main() { exit $ret } main "$@" - From d71ab30bdbedb427e89211de8e9bf86a4e0ee403 Mon Sep 17 00:00:00 2001 From: Brokenpip3 Date: Tue, 5 Feb 2019 12:49:21 +0100 Subject: [PATCH 2/2] git support "add" command + man pages --- notes | 11 +++++++---- notes.1 | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/notes b/notes index 5088689..9b407ae 100755 --- a/notes +++ b/notes @@ -230,8 +230,11 @@ init_note() { git_cmd_note() { local git_cmd=$1 + if [[ $git_cmd = "add" ]]; then + git -C $notes_dir add $2 + else git -C $notes_dir "$git_cmd" - + fi } usage() { @@ -296,8 +299,8 @@ main() { "cat" ) cmd="handle_multiple_notes cat" ;; - "git" ) - cmd="git_note" + "git"|"g" ) + cmd="git_cmd_note" ;; "init"|"i" ) cmd="init_note" @@ -317,4 +320,4 @@ main() { ret=$[$ret+$?] exit $ret } -main "$@" +main "$@" \ No newline at end of file diff --git a/notes.1 b/notes.1 index 396fe18..cfa6f60 100644 --- a/notes.1 +++ b/notes.1 @@ -48,6 +48,13 @@ Removes \fINAME\fR. If \-r or \-\-recursive is given, folders will be removed. .BR cat " " \fINAME\fR Display note \fINAME\fR. \fINAME\fR can either be an absolute path or relative to $NOTES_DIRECTORY. +.TP +.BR git " " \fINAME\fR +Use git command on $NOTES_DIRECTORY +.TP +.BR init " " \fINAME\fR +Init $NOTES_DIRECTORY: create the path if don't exist and start a empty git repo + .SH AUTHORS Notes was created by Tim Perry, who is still the maintainer. Numerous contributions have been submitted via pull requests on github.