Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: git support and git init #66

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,32 @@ 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
if [[ $git_cmd = "add" ]]; then
git -C $notes_dir add $2
else
git -C $notes_dir "$git_cmd"
fi
}

usage() {
cat <<EOF
notes is a command line note taking tool.
Expand All @@ -225,6 +251,8 @@ Usage:
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
notes cat <name> # Display note
notes git <command> # Git command (status, pull, push etc)
notes init|i <command> # Initialize git repository or clone from existing
echo <name> | notes open|o # Open all note filenames piped in
echo <name> | notes cat # Display all note filenames piped in
notes --help # Print this usage information
Expand Down Expand Up @@ -271,6 +299,12 @@ main() {
"cat" )
cmd="handle_multiple_notes cat"
;;
"git"|"g" )
cmd="git_cmd_note"
;;
"init"|"i" )
cmd="init_note"
;;
--help | -help | -h )
cmd="usage"
;;
Expand All @@ -286,5 +320,4 @@ main() {
ret=$[$ret+$?]
exit $ret
}
main "$@"

main "$@"
7 changes: 7 additions & 0 deletions notes.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down