From f29f7e8751fa3af10f6fc55ed853214da592d493 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 17 May 2018 19:39:13 +0200 Subject: [PATCH] Add edit command, use pandoc to render show command --- .gitignore | 1 + README.md | 1 + doc/memo.1 | 11 ++++++++++- doc/memo.txt | 7 ++++++- memo | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/README.md b/README.md index 2d74adc..a97aabb 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Memo organizes is structured through topics which are folders in `~/memo`. ## Installation * Gentoo : use [my overlay](https://github.com/mrVanDalo/overlay) and install `app-misc/memo` +* NixOs : just do `nix-shell -p memo` ## Configuration diff --git a/doc/memo.1 b/doc/memo.1 index 683f564..054f273 100644 --- a/doc/memo.1 +++ b/doc/memo.1 @@ -1,5 +1,5 @@ .\" Text automatically generated by txt2man -.TH memo 1 "19 June 2017" "doc" "Linux Reference Manual" +.TH memo 1 "17 May 2018" "doc" "Linux Reference Manual" .SH NAME \fBmemo \fB @@ -43,11 +43,16 @@ shows memo.md in the topic folder. also showes a list of all files in the topic folder .TP .B +edit +opens your favorite editor to edit the \fBmemo\fP topic +.TP +.B list prints a list of all topics. .RE .PP + .SH CONFIGURATION .TP @@ -55,6 +60,10 @@ prints a list of all topics. $MEMO_DIR holds the folder where to store the \fBmemo\fP files. Default is $HOME/\fBmemo\fP +.TP +.B +$EDITOR +Your favorite editor. Must be set for the edit command .SH EXAMPLE diff --git a/doc/memo.txt b/doc/memo.txt index cebd358..942cac8 100644 --- a/doc/memo.txt +++ b/doc/memo.txt @@ -24,13 +24,18 @@ COMMANDS show shows memo.md in the topic folder. also showes a list of all files in the topic folder + edit opens your favorite editor to edit the memo topic + list prints a list of all topics. + CONFIGURATION $MEMO_DIR holds the folder where to store the memo files. - Default is $HOME/memo + Default is $HOME/memo + + $EDITOR Your favorite editor. Must be set for the edit command EXAMPLE diff --git a/memo b/memo index f6a5b3a..02308bd 100755 --- a/memo +++ b/memo @@ -20,17 +20,37 @@ function precondition::provide_memo_folder(){ function precondition::provide_topic(){ topic_name=$1 topic_path=${MEMO_FOLDER}/${topic_name} + topic_file=${topic_path}/memo.md if [[ ! -d ${topic_path} ]] then echo "create memo topic : ${topic_name}" mkdir -p ${topic_path} - echo "# ${topic_name}" > ${topic_path}/memo.md + echo "# Memo" > ${topic_file} fi } +# +# edit command +# + +function edit_memo() { + topic_name=$1 + precondition::provide_topic ${topic_name} + topic_path=${MEMO_FOLDER}/${topic_name} + + if [[ -z ${EDITOR} ]] + then + echo "you have to define the ${EDITOR} variable" + exit 1 + fi + + ${EDITOR} ${topic_file} + +} + # # add command # @@ -39,20 +59,21 @@ function add_memo(){ topic_name=$1 precondition::provide_topic ${topic_name} topic_path=${MEMO_FOLDER}/${topic_name} + topic_file=${topic_path}/memo.md shift if [[ $# -gt 0 ]] then memo=$@ echo "append memo to ${topic_name}" - cat >>${topic_path}/memo.md <>${topic_file} <>${topic_path}/memo.md - cat >>${topic_path}/memo.md - + echo "" >>${topic_file} + cat >>${topic_file} - fi } @@ -136,11 +157,22 @@ function show_topic(){ if [[ -f ${topic_file} ]] then echo - cat ${topic_file} + #cat ${topic_file} + cat <( + echo "% ${topic_name}" && \ + echo "% $( whoami )" && \ + echo "% $( date +%Y-%m-%d )" && \ + cat ${topic_file} && \ + echo && \ + echo "# Folders" && \ + echo && \ + find ${topic_path} -printf "* %p\n") | \ + pandoc - -s -t man | \ + man -l - echo fi - tree -a ${topic_path} + # tree -a ${topic_path} } @@ -194,6 +226,9 @@ Commands: show topic file and list all file in the ${MEMO_FOLDER}// + edit + edit topic ${MEMO_FOLDER}/.md + list prints a list of all topics @@ -223,6 +258,9 @@ case $command in show) show_topic $@ ;; + edit) + edit_memo $@ + ;; list) list_topics ;;