From 19ef65bd645bf9264ebb43ebd8c617cd5e9d16d7 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Fri, 28 Oct 2022 00:08:53 +0800 Subject: First commit --- Makefile | 26 ++++++++++++++++++++++++++ wd | 29 +++++++++++++++++++++++++++++ wd-journal | 17 +++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 Makefile create mode 100755 wd create mode 100755 wd-journal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5a89949 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +PROG ?= wd +PREFIX ?= /usr +DESTDIR ?= +BINDIR ?= $(PREFIX)/bin + +all: + @echo "$(PROG) is a shell script and doesn't need compilation. It can be simply executed." + @echo + @echo "To install it. Try \"make install\" instead." + @echo + +install: + @install -vm0755 \ + "$(PROG)" \ + "$(PROG)-journal" \ + "$(DESTDIR)$(BINDIR)" + @echo + @echo "$(PROG) is installed succesfully" + @echo + +uninstall: + @rm -vrf \ + "$(DESTDIR)$(BINDIR)/$(PROG)" \ + "$(DESTDIR)$(BINDIR)/$(PROG)-journal" + +.PHONY: all install uninstall diff --git a/wd b/wd new file mode 100755 index 0000000..13cfde7 --- /dev/null +++ b/wd @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +VERSION="0.0.1" +PROGRAM="$(basename $0)" + +cmd_wd_usage () { + cat <<-_EOF +Usage: + + $PROGRAM journal + +_EOF + exit 0 +} + +cmd_wd_version () { + echo $VERSION + exit 0 +} + +case "$1" in + help|--help|-h) shift; cmd_wd_usage "$@";; + version|--version|-v) shift; cmd_wd_version "$@";; + journal|j) shift; wd-journal "$@";; + *) cmd_wd_usage "$@";; +esac + +exit 0 + diff --git a/wd-journal b/wd-journal new file mode 100755 index 0000000..e56d357 --- /dev/null +++ b/wd-journal @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +notes_dir=${NB_NOTE_DIR:-"$HOME/notes"} +journals_dir="$notes_dir/journals" + +year=$(date +%Y) +week_number=$(date +%W) + +title="## $(date '+%Y-%m-%d %A')" + +weekly_journal="$journals_dir/$year/week$week_number.md" + +if ! grep -q "$title" "$weekly_journal"; then + echo "$title" >> "$weekly_journal" +fi + +$EDITOR "$journals_dir/$year/week$week_number.md" -- cgit v1.2.3