initial check-in
This commit is contained in:
commit
f8690d5584
|
@ -0,0 +1,115 @@
|
|||
# zn repo
|
||||
|
||||
## Introduction
|
||||
|
||||
This repo contains zn, a simple note taking shell script. It is conceptually
|
||||
inspired by zetz, written by Guy Valariola (kutacoder). His github page is
|
||||
located at;
|
||||
|
||||
* https://gist.github.com/kutacoder/de2c0e624477efce920904125f0fb7b0
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This script requires the following programs;
|
||||
|
||||
* bat - https://github.com/sharkdp/bat
|
||||
* fzf - https://github.com/junegunn/fzf
|
||||
* rg - https://github.com/BurntSushi/ripgrep
|
||||
* tmux - https://github.com/tmux/tmux
|
||||
|
||||
All of these should also be available via the package management system in
|
||||
most distributions.
|
||||
|
||||
## Setup
|
||||
|
||||
### Note Directory
|
||||
|
||||
The first step to perform is creation of the note storage directory. This can
|
||||
be nested or not, depending on your requirements. In my case I nest a number
|
||||
of note storage directories under $HOME/.notes;
|
||||
|
||||
```
|
||||
$ tree -d .notes
|
||||
.notes
|
||||
├── journal
|
||||
└── notes
|
||||
```
|
||||
|
||||
There is a variable in the script named "NOTEPATH" where you can set up a
|
||||
default note storage directory.
|
||||
|
||||
### Git Setup
|
||||
|
||||
The next thing to do is set up git for revision control of your notes. You can
|
||||
either set up a git repo for each note directory (if running with more than one)
|
||||
or set up a git repo in the parent directory if using a nested directory setup.
|
||||
|
||||
Once you've identified where you'll place your git repo, simply cd into that
|
||||
directory and run `git init`.
|
||||
|
||||
Using git for revision control of your notes can be disabled by commenting out
|
||||
the line starting with `git add . && ...` in the script.
|
||||
|
||||
## Command Line Options
|
||||
|
||||
```
|
||||
Usage: zn [-p <path to note directory>] [-t]
|
||||
|
||||
-p Path to desired note directory. Can be relative or absolute.
|
||||
ie, "-p $HOME/.notes/notes"
|
||||
|
||||
-t Use tags search (default is to use filename search)
|
||||
```
|
||||
|
||||
## Bash Aliases
|
||||
|
||||
I use aliased commands to interact with my notebooks.
|
||||
|
||||
```
|
||||
$ cat bash_aliases_clip
|
||||
|
||||
# zn aliases
|
||||
alias zn="zn -p $HOME/.notes/notes"
|
||||
alias znt="zn -p $HOME/.notes/notes -t"
|
||||
alias zj="zn -p $HOME/.notes/journal"
|
||||
alias zjt="zn -p $HOME/.notes/journal -t"
|
||||
```
|
||||
|
||||
## Note File Format
|
||||
|
||||
This script is set up to work with Markdown formatted note files. There are
|
||||
only two requirements that must be observed for the note files.
|
||||
|
||||
The first line of the note file is the title of the note, and should be written
|
||||
as a level 1 header.
|
||||
|
||||
The other requirement is tags. You can have any number of tags in your note
|
||||
files. Tags should be placed starting on line three, with a blank line
|
||||
between the tags and the title, and another blank line between the tags and
|
||||
the body of the note. Each tag should start with a "#" character with no space
|
||||
between it and the tag itself.
|
||||
|
||||
In actuality, tags can be placed anywhere within the note file, and the script
|
||||
will find them just fine. The above recommendation is for readability.
|
||||
|
||||
* Example Note File
|
||||
|
||||
```
|
||||
$ cat 20220125141537.md
|
||||
|
||||
# LXD Documentation Links
|
||||
|
||||
#LXD
|
||||
#Links
|
||||
#Docs
|
||||
|
||||
* https://linuxcontainers.org/lxd/
|
||||
* https://github.com/lxc/lxd
|
||||
* https://ubuntu.com/server/docs/containers-lxd
|
||||
* https://snapcraft.io/lxd
|
||||
|
||||
```
|
||||
|
||||
Note files are created with a date-time formatted filename, in the format
|
||||
of 'YYYYMMDDHHMMSS.md'.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
# zn aliases
|
||||
alias zn="zn -p $HOME/.notes/notes"
|
||||
alias znt="zn -p $HOME/.notes/notes -t"
|
||||
alias zj="zn -p $HOME/.notes/journal"
|
||||
alias zjt="zn -p $HOME/.notes/journal -t"
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
#!/usr/bin/env bash
|
||||
##############################################################################
|
||||
#
|
||||
# Basic structure derived from the note taking application named zetz;
|
||||
# - https://gist.github.com/kutacoder/de2c0e624477efce920904125f0fb7b0
|
||||
#
|
||||
# Prerequisites:
|
||||
# - tmux, fzf, bat, rg
|
||||
#
|
||||
# - Notes should have a .md extention.
|
||||
# - Notes should have a title on the *first* line prefixed by one hash symbol, i.e. "# Cool Title".
|
||||
#
|
||||
# Key Bindings:
|
||||
# - ctrl-r: reload list
|
||||
# - ctrl-x: delete note
|
||||
# - ctrl-i: add new note
|
||||
#
|
||||
# NOTE: The new note's name is its creation date in the follwing format: %Y%m%d%H%M%S
|
||||
##############################################################################
|
||||
|
||||
#################################################
|
||||
# default note path if not specified
|
||||
NOTEPATH="$HOME/.notes/notes"
|
||||
|
||||
#################################################
|
||||
# DOTAGS is false by default
|
||||
DOTAGS="false"
|
||||
|
||||
#################################################
|
||||
# Usage Function
|
||||
|
||||
usage () {
|
||||
echo ""
|
||||
echo "Usage: $0 [-p <path to note directory>] [-t]"
|
||||
echo ""
|
||||
echo "-p Path to desired note directory. Can be relative or absolute."
|
||||
echo " ie, \"-p \$HOME/.notes/notes\""
|
||||
echo ""
|
||||
echo "-t Use tags search (default is to use filename search)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
#################################################
|
||||
# Parse the CLA
|
||||
|
||||
parse_args() {
|
||||
while getopts "p:t" opt; do
|
||||
case $opt in
|
||||
p)
|
||||
NOTEPATH=${OPTARG}
|
||||
;;
|
||||
|
||||
t)
|
||||
DOTAGS="true"
|
||||
;;
|
||||
|
||||
\?)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
#################################################
|
||||
main() {
|
||||
|
||||
parse_args "$@"
|
||||
|
||||
#############################################
|
||||
# check if the supplied note path exists
|
||||
|
||||
if [ ! -d "$NOTEPATH" ];
|
||||
then
|
||||
echo ""
|
||||
echo "Error: Directory \"${NOTEPATH}\" does not exist!"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$NOTEPATH"
|
||||
|
||||
if [ "$DOTAGS" == "false" ];
|
||||
then
|
||||
#########################################
|
||||
# Run against filenames
|
||||
|
||||
FZF_DEFAULT_COMMAND="find *.md -type f -exec sed -n 1p {} \; | sed 's_# __g' | sort -rn" \
|
||||
fzf --height=100% --preview-window=right:65%:wrap \
|
||||
--preview 'bat --language=md --style=plain --color=always $(rg -slF {})' \
|
||||
--bind 'enter:execute:$EDITOR $(rg -slF {})' \
|
||||
--bind 'ctrl-r:reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
||||
--bind 'ctrl-x:execute-silent(rm -f $(rg -slF {}))+reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
||||
--bind 'ctrl-i:execute:tmux split-window "FZF_DEFAULT_COMMAND=\"${FZF_DEFAULT_COMMAND}\" $EDITOR $(date +"%Y%m%d%H%M%S").md"'
|
||||
else
|
||||
#########################################
|
||||
# Run against tags
|
||||
|
||||
FZF_DEFAULT_COMMAND="rg '^\#[a-zA-Z]' *.md" \
|
||||
fzf --exact --height=100% --preview-window=right:65%:wrap \
|
||||
--preview 'bat --language=md --style=plain --color=always $(echo {} | cut -d':' -f1)' \
|
||||
--bind 'enter:execute:$EDITOR $(echo {} | cut -d':' -f1)' \
|
||||
--bind 'ctrl-r:reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
||||
--bind 'ctrl-x:execute-silent(rm -f $(echo {} | cut -d':' -f1))+reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
||||
--bind 'ctrl-i:execute:tmux split-window "FZF_DEFAULT_COMMAND=\"${FZF_DEFAULT_COMMAND}\" $EDITOR $(date +"%Y%m%d%H%M%S").md"'
|
||||
fi
|
||||
|
||||
#############################################
|
||||
# check changes made into git
|
||||
git add . && git commit -q -m "checking in changes made at $(date +%Y%m%d-%H%M%S)"
|
||||
|
||||
cd -
|
||||
}
|
||||
|
||||
#################################################
|
||||
# This is the way...
|
||||
main "$@"
|
||||
|
||||
# EOF
|
Loading…
Reference in New Issue