summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2022-10-28 18:43:37 +0800
committerGuangxiong Lin <[email protected]>2022-10-28 18:44:22 +0800
commit5152cb88e72134066ff0a4ee83edc539731529b5 (patch)
tree121c5a3a1981077bef37ad4cf6fb0146d006fcc2
parent7df8ee0b3b3159e3c704ad4bd2fe940c72ae4e21 (diff)
downloadwd-0.0.2.tar.gz
wd-0.0.2.tar.bz2
wd-0.0.2.zip
Add wd-editv0.0.2
-rw-r--r--Makefile4
-rwxr-xr-xwd25
-rwxr-xr-xwd-edit3
-rwxr-xr-xwd-journal7
4 files changed, 26 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 5a89949..7d61d55 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ install:
@install -vm0755 \
"$(PROG)" \
"$(PROG)-journal" \
+ "$(PROG)-edit" \
"$(DESTDIR)$(BINDIR)"
@echo
@echo "$(PROG) is installed succesfully"
@@ -21,6 +22,7 @@ install:
uninstall:
@rm -vrf \
"$(DESTDIR)$(BINDIR)/$(PROG)" \
- "$(DESTDIR)$(BINDIR)/$(PROG)-journal"
+ "$(DESTDIR)$(BINDIR)/$(PROG)-journal" \
+ "$(DESTDIR)$(BINDIR)/$(PROG)-edit"
.PHONY: all install uninstall
diff --git a/wd b/wd
index 28cbe1c..d6b7c6b 100755
--- a/wd
+++ b/wd
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="0.0.1"
+VERSION="0.0.2"
PROGRAM="$(basename $0)"
cmd_wd_usage () {
@@ -8,6 +8,7 @@ cmd_wd_usage () {
Usage:
$PROGRAM journal
+ $PROGRAM edit
_EOF
exit 0
@@ -18,16 +19,26 @@ cmd_wd_version () {
exit 0
}
-wdrc=${WDRC:-"$HOME/.wdrc"}
-if [ ! -f "$wdrc" ]; then
- touch $wdrc
-fi
-source $wdrc
+setup_env () {
+
+ local wdrc=${WDRC:-"$HOME/.wdrc"}
+ if [ ! -f "$wdrc" ]; then
+ touch $wdrc
+ fi
+ source $wdrc
+
+ export WD_NOTES_DIR=${WD_NOTES_DIR:-"$HOME/notes"}
+ export WD_JOURNALS_DIR=${WD_JOURNALS_DIR:-"$WD_NOTES_DIR/journals"}
+
+}
+
+setup_env
case "$1" in
help|--help|-h) shift; cmd_wd_usage "$@";;
version|--version|-v) shift; cmd_wd_version "$@";;
- journal|j) shift; wd-journal "$@";;
+ journal|j) shift; "$PROGRAM-journal" "$@";;
+ edit|e) shift; "$PROGRAM-edit" "$@";;
*) cmd_wd_usage "$@";;
esac
diff --git a/wd-edit b/wd-edit
new file mode 100755
index 0000000..185bb27
--- /dev/null
+++ b/wd-edit
@@ -0,0 +1,3 @@
+#!/usr/bin/bash
+
+$EDITOR "$WD_NOTES_DIR"
diff --git a/wd-journal b/wd-journal
index e56d357..8022125 100755
--- a/wd-journal
+++ b/wd-journal
@@ -1,17 +1,14 @@
#!/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"
+weekly_journal="$WD_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"
+$EDITOR "$WD_JOURNALS_DIR/$year/week$week_number.md"