3 ms·
A bash script for a note-taker was given here: https://news.ycombinator.com/item?id=18902255 https://news.ycombinator.com/item?id=18902255 based on the one here
by yesenadam 8y ago
A bash script for a note-taker was given here: https://news.ycombinator.com/item?id=18902255 https://news.ycombinator.com/item?id=18902255 based on the one here https://news.ycombinator.com/item?id=16358837 https://news.ycombinator.com/item?id=16358837 Thanks for the motivation! I incorporated some improvements -
My version, n: 'n' displays notes with less, 'n [your text here]' to enter a line of text, 'n i' to enter input mode, where input continues until Ctrl-D. 'n date' adds date. 'n cat' prints notes. 'n -h' shows commands.
#! /bin/bash #n note-taker
fpath=$HOME/notes.txt
[[ -e "$fpath" ]] || touch "$fpath" #create file if doesn't exist
if [ "$1" == "cat" ]; then
cat "$fpath"
exit 0
elif [ "$1" == "rg" ]; then
rg "$2" "$fpath"
elif [ "$1" == "nano" ]; then
nano "$fpath"
elif [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
printf '\n n \t\t\t- display notes
n --help\t\t- display this help
n date\t\t- add date row to notes
n <text>\t\t- add new entry
n i \t\t- input mode, end input with ^D
n cat\t\t- print notes using cat
n rg <pattern>\t- ripgrep notes
Use #tags (for easier grepping).\n\n'
elif [ "$1" == "date" ]; then {
echo
echo '# '$(date +"%d-%m-%Y - %T")
} >> "$fpath"
elif [ "$1" == "" ]; then
less +G "$fpath"
elif [ "$*" == "i" ]; then {
echo
while read line
do
echo $line
done
} >> "$fpath"
else {
echo
echo "$@"
} >> "$fpath"
fi