From aea3d9152e4de375ca4519164bd6109f121f106b Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Wed, 8 Aug 2018 20:03:48 +0200 Subject: [PATCH 1/5] add git commands --- memo | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) 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 From 7321e3d197c0d40cd054fc7f12fef14ae78c2f46 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 9 Aug 2018 04:35:55 +0200 Subject: [PATCH 2/5] update _memo --- completion/zsh/_memo | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/completion/zsh/_memo b/completion/zsh/_memo index adc3d06..00e5b65 100755 --- a/completion/zsh/_memo +++ b/completion/zsh/_memo @@ -12,6 +12,7 @@ function _memo { show\:'show a topic' edit\:'edit a topic' list\:'print a list of all topics' + git\:'run git command' ))" \ "*::arg:->args" @@ -19,6 +20,9 @@ function _memo { add|copy|show|edit) _memo_topics ;; + git) + _git + ;; *) ;; esac @@ -31,3 +35,17 @@ function _memo_topics { compadd -X "A vailable Topics" $topics } +function _git { + local -a subcommands + subcommands=( + "init:Initialize git repository" + "status:Status of git repository" + "push:Push to remote repository" + "pull:Pull from remote repository" + "config:Show git config" + "log:Show git log" + "reflog:Show git reflog" + ) + _describe -t commands 'git' subcommands +} + From 7dfbb88b07d3afbd26dc356e0496b24cf25116b5 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 9 Aug 2018 23:30:46 +0200 Subject: [PATCH 3/5] add rm command and cleanup of other commands --- memo | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/memo b/memo index f17765b..c344591 100755 --- a/memo +++ b/memo @@ -77,16 +77,34 @@ function git:commit(){ fi } -function git:run_commands(){ +function git:run_command(){ cd ${MEMO_FOLDER} ${git_cmd} $@ } +# +# remove command +# + +function remove_topic (){ + topic_name=$1 + #precondition::provide_topic ${topic_name} + topic_path=${MEMO_FOLDER}/${topic_name} + + if [[ -d ${topic_path} ]] + then + rm -rf ${topic_path} + fi + + git:add_all_topics + git:commit "edit : ${topic_name}" +} + # # edit command # -function edit_memo() { +function edit_topic () { topic_name=$1 precondition::provide_topic ${topic_name} topic_path=${MEMO_FOLDER}/${topic_name} @@ -275,6 +293,9 @@ Commands: so piping is possible. Example: cat file.txt | memo add topic + rm + remove ${MEMO_FOLDER}/ (with all its content) + copy copy a file to ${MEMO_FOLDER}// @@ -292,6 +313,9 @@ Commands: list prints a list of all topics + git + run git in ${MEMO_FOLDER} + EOF } @@ -320,13 +344,16 @@ case $command in show_topic $@ ;; edit) - edit_memo $@ + edit_topic $@ ;; list) list_topics ;; git) - git:run_commands $@ + git:run_command $@ + ;; + rm) + remove_topic $@ ;; *) show_help ;; From 058ab5d062f63a9c4a8d71c30eea6bda56952c4b Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 9 Aug 2018 23:32:34 +0200 Subject: [PATCH 4/5] add rm to completion --- completion/bash/memo.sh | 2 +- completion/zsh/_memo | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/completion/bash/memo.sh b/completion/bash/memo.sh index 7702050..360f375 100644 --- a/completion/bash/memo.sh +++ b/completion/bash/memo.sh @@ -4,7 +4,7 @@ _memo(){ local cur opt prev MEMO_FOLDER="${MEMO_DIR:-$HOME/memo}" - opts="add copy search show list" + opts="add rm copy search show list" COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" diff --git a/completion/zsh/_memo b/completion/zsh/_memo index 00e5b65..5cc918e 100755 --- a/completion/zsh/_memo +++ b/completion/zsh/_memo @@ -7,6 +7,7 @@ function _memo { _arguments \ "1:action:(( add\:'add a text to a topic' + rm\:'delete a topic folder with all its content' copy\:'copy a file to a topic' search\:'search for text in all topics' show\:'show a topic' @@ -17,7 +18,7 @@ function _memo { "*::arg:->args" case $line[1] in - add|copy|show|edit) + add|rm|copy|show|edit) _memo_topics ;; git) From b6fcf45aa23fe81471748e39d34723c27f9b6df7 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Fri, 10 Aug 2018 00:32:56 +0200 Subject: [PATCH 5/5] update documentation --- README.md | 5 ++++- doc/memo.1 | 19 ++++++++++++++++++- doc/memo.txt | 9 +++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a1957a..ed0d945 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ Memo organizes is structured through topics which are folders in `~/memo`. ## Features * add text to a topic to memorize it +* remote topics * search for strings in your memo-database * copy/import files to topic folder. +* git support ## Run @@ -19,7 +21,8 @@ Memo organizes is structured through topics which are folders in `~/memo`. * tree * ack * man -* pandoc +* git +* pandoc (optional) ## Installation diff --git a/doc/memo.1 b/doc/memo.1 index 054f273..e4c029f 100644 --- a/doc/memo.1 +++ b/doc/memo.1 @@ -1,5 +1,5 @@ .\" Text automatically generated by txt2man -.TH memo 1 "17 May 2018" "doc" "Linux Reference Manual" +.TH memo 1 "10 August 2018" "doc" "Linux Reference Manual" .SH NAME \fBmemo \fB @@ -30,6 +30,10 @@ adds text to the memo.md in the topic folder. if text is not given it will read from stdin. .TP .B +rm +remove $MEMO_DIR/topic folder with all it's content. +.TP +.B copy copy a file to the topic folder. .TP @@ -49,6 +53,11 @@ opens your favorite editor to edit the \fBmemo\fP topic .B list prints a list of all topics. +.TP +.B +git +run git command in $MEMO_DIR. +Once $MEMO_DIR is a git repository all \fBmemo\fP commands create commits. .RE .PP @@ -91,5 +100,13 @@ Copy the "Invoice.pdf" file to the "lawsuit" topic. .fam C $> memo copy lawsuit ~/Downloads/Invoice.pdf +.fam T +.fi +Make $MEMO_DIR a git repository. +.PP +.nf +.fam C + $> memo git init + diff --git a/doc/memo.txt b/doc/memo.txt index 942cac8..0a141a0 100644 --- a/doc/memo.txt +++ b/doc/memo.txt @@ -17,6 +17,8 @@ COMMANDS add [text] adds text to the memo.md in the topic folder. if text is not given it will read from stdin. + rm remove $MEMO_DIR/topic folder with all it's content. + copy copy a file to the topic folder. search search for a term in $MEMO_DIR using ack. @@ -28,6 +30,9 @@ COMMANDS list prints a list of all topics. + git run git command in $MEMO_DIR. + Once $MEMO_DIR is a git repository all memo commands create commits. + CONFIGURATION @@ -54,5 +59,9 @@ EXAMPLE $> memo copy lawsuit ~/Downloads/Invoice.pdf + Make $MEMO_DIR a git repository. + + $> memo git init +