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
* Gentoo : use [my overlay](https://github.com/mrVanDalo/overlay) and install `app-misc/memo`
* NixOs : just do `nix-shell -p memo`
## Configuration

View File

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

View File

@ -24,13 +24,18 @@ COMMANDS
show <topic> shows memo.md 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.
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

50
memo
View File

@ -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 <<EOF
cat >>${topic_file} <<EOF
${memo}
EOF
else
echo "append input to ${topic_name}"
echo "" >>${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}/<topic>/
edit <topic>
edit topic ${MEMO_FOLDER}/<topic>.md
list
prints a list of all topics
@ -223,6 +258,9 @@ case $command in
show)
show_topic $@
;;
edit)
edit_memo $@
;;
list)
list_topics
;;