Add edit command, use pandoc to render show command

master
Ingolf Wagner 2018-05-17 19:39:13 +02:00
parent c7273b709b
commit f29f7e8751
5 changed files with 62 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.swp

View File

@ -22,6 +22,7 @@ Memo organizes is structured through topics which are folders in `~/memo`.
## Installation ## Installation
* Gentoo : use [my overlay](https://github.com/mrVanDalo/overlay) and install `app-misc/memo` * Gentoo : use [my overlay](https://github.com/mrVanDalo/overlay) and install `app-misc/memo`
* NixOs : just do `nix-shell -p memo`
## Configuration ## Configuration

View File

@ -1,5 +1,5 @@
.\" Text automatically generated by txt2man .\" 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 .SH NAME
\fBmemo \fBmemo
\fB \fB
@ -43,11 +43,16 @@ shows memo.md in the topic folder.
also showes a list of all files in the topic folder also showes a list of all files in the topic folder
.TP .TP
.B .B
edit <topic>
opens your favorite editor to edit the \fBmemo\fP topic
.TP
.B
list list
prints a list of all topics. prints a list of all topics.
.RE .RE
.PP .PP
.SH CONFIGURATION .SH CONFIGURATION
.TP .TP
@ -55,6 +60,10 @@ prints a list of all topics.
$MEMO_DIR $MEMO_DIR
holds the folder where to store the \fBmemo\fP files. holds the folder where to store the \fBmemo\fP files.
Default is $HOME/\fBmemo\fP Default is $HOME/\fBmemo\fP
.TP
.B
$EDITOR
Your favorite editor. Must be set for the edit command
.SH EXAMPLE .SH EXAMPLE

View File

@ -24,13 +24,18 @@ COMMANDS
show <topic> shows memo.md in the topic folder. show <topic> shows memo.md in the topic folder.
also showes a list of all files in the topic folder also showes a list of all files in the topic folder
edit <topic> opens your favorite editor to edit the memo topic
list prints a list of all topics. list prints a list of all topics.
CONFIGURATION CONFIGURATION
$MEMO_DIR holds the folder where to store the memo files. $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 EXAMPLE

50
memo
View File

@ -20,17 +20,37 @@ function precondition::provide_memo_folder(){
function precondition::provide_topic(){ function precondition::provide_topic(){
topic_name=$1 topic_name=$1
topic_path=${MEMO_FOLDER}/${topic_name} topic_path=${MEMO_FOLDER}/${topic_name}
topic_file=${topic_path}/memo.md
if [[ ! -d ${topic_path} ]] if [[ ! -d ${topic_path} ]]
then then
echo "create memo topic : ${topic_name}" echo "create memo topic : ${topic_name}"
mkdir -p ${topic_path} mkdir -p ${topic_path}
echo "# ${topic_name}" > ${topic_path}/memo.md echo "# Memo" > ${topic_file}
fi 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 # add command
# #
@ -39,20 +59,21 @@ function add_memo(){
topic_name=$1 topic_name=$1
precondition::provide_topic ${topic_name} precondition::provide_topic ${topic_name}
topic_path=${MEMO_FOLDER}/${topic_name} topic_path=${MEMO_FOLDER}/${topic_name}
topic_file=${topic_path}/memo.md
shift shift
if [[ $# -gt 0 ]] if [[ $# -gt 0 ]]
then then
memo=$@ memo=$@
echo "append memo to ${topic_name}" echo "append memo to ${topic_name}"
cat >>${topic_path}/memo.md <<EOF cat >>${topic_file} <<EOF
${memo} ${memo}
EOF EOF
else else
echo "append input to ${topic_name}" echo "append input to ${topic_name}"
echo "" >>${topic_path}/memo.md echo "" >>${topic_file}
cat >>${topic_path}/memo.md - cat >>${topic_file} -
fi fi
} }
@ -136,11 +157,22 @@ function show_topic(){
if [[ -f ${topic_file} ]] if [[ -f ${topic_file} ]]
then then
echo 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 echo
fi fi
tree -a ${topic_path} # tree -a ${topic_path}
} }
@ -194,6 +226,9 @@ Commands:
show topic file and list all file in the show topic file and list all file in the
${MEMO_FOLDER}/<topic>/ ${MEMO_FOLDER}/<topic>/
edit <topic>
edit topic ${MEMO_FOLDER}/<topic>.md
list list
prints a list of all topics prints a list of all topics
@ -223,6 +258,9 @@ case $command in
show) show)
show_topic $@ show_topic $@
;; ;;
edit)
edit_memo $@
;;
list) list)
list_topics list_topics
;; ;;