diff --git a/memo b/memo index 203802a..f17765b 100755 --- a/memo +++ b/memo @@ -9,9 +9,11 @@ ack_cmd=ack man_cmd=man tree_cmd=tree +git_cmd=git # comment pandoc_cmd to fall back to cat pandoc_cmd=pandoc + # Script MEMO_FOLDER="${MEMO_DIR:-$HOME/memo}" @@ -37,7 +39,48 @@ function precondition::provide_topic(){ fi } +# +# git commands +# +IS_GIT_REPO=0 +# check if it is a gitrepository +# use the IS_GIT_REPO variable to +# verify later if it is a git repo +function git:status(){ + cd ${MEMO_FOLDER} + ${git_cmd} status &> /dev/null + if [[ $? -eq 0 ]] + then + IS_GIT_REPO=1 + else + IS_GIT_REPO=0 + fi +} + +# run before commit +function git:add_all_topics(){ + if [[ ${IS_GIT_REPO} -eq 1 ]] + then + cd ${MEMO_FOLDER} + ${git_cmd} add . + fi +} + +# make a commit +function git:commit(){ + local message="${1:-blind commit}" + if [[ ${IS_GIT_REPO} -eq 1 ]] + then + cd ${MEMO_FOLDER} + ${git_cmd} commit -m "${message}" + fi +} + +function git:run_commands(){ + cd ${MEMO_FOLDER} + ${git_cmd} $@ +} # # edit command @@ -56,6 +99,8 @@ function edit_memo() { ${EDITOR} ${topic_file} + git:add_all_topics + git:commit "edit : ${topic_name}" } # @@ -83,6 +128,9 @@ EOF cat >>${topic_file} - fi + git:add_all_topics + git:commit "add : ${topic_name}" + } @@ -118,6 +166,9 @@ function copy_file(){ echo "copy '${path}' to '${topic_name}'" cp -r "${path}" ${topic_path}/ + git:add_all_topics + git:commit "copy $( dirname ${path} ): ${topic_name}" + } @@ -254,6 +305,7 @@ command=$1 shift precondition::provide_memo_folder +git:status case $command in add) add_memo $@ @@ -273,6 +325,9 @@ case $command in list) list_topics ;; + git) + git:run_commands $@ + ;; *) show_help ;; esac