dot/outerheaven.init3.home/.local/bin/note-taker.sh

46 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2024-06-19 13:19:05 +00:00
#!/bin/bash
2024-06-20 12:36:27 +00:00
# scripted note organizer/taker
2024-06-19 13:19:05 +00:00
#
2024-06-20 12:39:05 +00:00
# with Sway/on login:
# a Kitty session is started which runs *this* script through a 'session file' in a pane
# ultimately, providing an editor with timely notes for this week (and last) in tabs
2024-06-20 12:36:27 +00:00
#
# Kitty session config:
2024-06-20 12:39:05 +00:00
# # ~/.config/kitty/sessions/triplesplit.conf
2024-06-19 13:19:05 +00:00
# layout tall
# launch --location=hsplit --cwd=current bash
# launch --location=hsplit --cwd=current bash
2024-06-20 12:02:07 +00:00
# launch --location=hsplit --cwd=current note-taker.sh
#
# the last command is *this script* in ~/.local/bin, presumably in $PATH already
2024-06-19 13:19:05 +00:00
#
SCRIPT_NAME=$(basename "$0")
# Check if the script is already running/controlling editors
if pgrep -f "$SHELL.*$SCRIPT_NAME" | grep -v $$ > /dev/null; then
echo "The notes are already being edited elsewhere."
exit 1
fi
# Where are notes held? Can be overridden outside of the script; defaults to ~/notes
NOTE_DIR="${NOTE_DIR:-${HOME}/notes}"
# Get the current year and week number, used for the name of the file. eg: 2023-week40
CURRENT_NOTE=$(date +%Y-week%V)
# Get the year and week number for the same day of the previous week
LAST_WEEK_NAME=$(date -d '7 days ago' +%Y-week%V)
# Construct the two note files to open in tabs as one array
NOTE_PATHS=("$NOTE_DIR/$CURRENT_NOTE" "$NOTE_DIR/$LAST_WEEK_NAME")
2024-06-20 12:36:27 +00:00
# Use EDITOR variable or fallback to vim as default. If contains "vim" (like {g,n,}vim and so on), add tab arguments.
2024-06-19 13:19:05 +00:00
EDITOR="${EDITOR:-vim}"
if [[ $EDITOR == *vim* ]]; then
# Run the vim-like editor with tabs
$EDITOR -c ':tab all' "${NOTE_PATHS[@]}"
else
# Run the editor without vim tab arg; assume array is fine
$EDITOR "${NOTE_PATHS[@]}"
fi