Merge branch 'release/0.6'

master 0.6
Ingolf Wagner 2018-08-10 00:46:25 +02:00
commit 64518e980a
6 changed files with 136 additions and 6 deletions

View File

@ -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

View File

@ -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]}"

View File

@ -7,18 +7,23 @@ 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'
edit\:'edit a topic'
list\:'print a list of all topics'
git\:'run git command'
))" \
"*::arg:->args"
case $line[1] in
add|copy|show|edit)
add|rm|copy|show|edit)
_memo_topics
;;
git)
_git
;;
*)
;;
esac
@ -31,3 +36,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
}

View File

@ -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 <topic>
remove $MEMO_DIR/topic folder with all it's content.
.TP
.B
copy <topic> <file-to-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 <command>
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

View File

@ -17,6 +17,8 @@ COMMANDS
add <topic> [text] adds text to the memo.md in the topic folder.
if text is not given it will read from stdin.
rm <topic> remove $MEMO_DIR/topic folder with all it's content.
copy <topic> <file-to-copy> copy a file to the topic folder.
search <term-to-search> search for a term in $MEMO_DIR using ack.
@ -28,6 +30,9 @@ COMMANDS
list prints a list of all topics.
git <command> 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

86
memo
View File

@ -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,13 +39,72 @@ 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_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}
@ -56,6 +117,8 @@ function edit_memo() {
${EDITOR} ${topic_file}
git:add_all_topics
git:commit "edit : ${topic_name}"
}
#
@ -83,6 +146,9 @@ EOF
cat >>${topic_file} -
fi
git:add_all_topics
git:commit "add : ${topic_name}"
}
@ -118,6 +184,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}"
}
@ -224,6 +293,9 @@ Commands:
so piping is possible.
Example: cat file.txt | memo add topic
rm <topic>
remove ${MEMO_FOLDER}/<topic> (with all its content)
copy <topic> <file to copy>
copy a file to ${MEMO_FOLDER}/<topic>/
@ -241,6 +313,9 @@ Commands:
list
prints a list of all topics
git <command>
run git <command> in ${MEMO_FOLDER}
EOF
}
@ -254,6 +329,7 @@ command=$1
shift
precondition::provide_memo_folder
git:status
case $command in
add) add_memo $@
@ -268,11 +344,17 @@ case $command in
show_topic $@
;;
edit)
edit_memo $@
edit_topic $@
;;
list)
list_topics
;;
git)
git:run_command $@
;;
rm)
remove_topic $@
;;
*) show_help
;;
esac