126 lines
3.1 KiB
Bash
Executable file
126 lines
3.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
C_RESET="\x1b[0m"
|
|
C_GREEN="\x1b[32m"
|
|
C_RED="\x1b[31m"
|
|
C_BOLD="\x1b[1m"
|
|
C_MAGENTA="\x1b[35m"
|
|
C_CYAN="\x1b[36m"
|
|
|
|
C_HEADLINE="\x1b[30;44;1m"
|
|
C_SUBHEADING="\x1b[33;1m"
|
|
C_DEADLINE="\x1b[31;1m"
|
|
|
|
year="$(date +%Y)"
|
|
|
|
# Just start helix if no arguments are given
|
|
if [ -z "${1+x}" ]; then
|
|
# Switch directory
|
|
pushd "$XDG_DATA_HOME/life.md" || exit 1
|
|
# Open Helix with the current year
|
|
hx "$year.md" +99999
|
|
# Commit changes if any exist
|
|
if ! git diff --quiet "$year.md"; then
|
|
git add "$year.md"
|
|
git commit -m "Auto Commit $(date +"%F %R")"
|
|
fi
|
|
# Exit
|
|
popd || exit 2
|
|
exit
|
|
fi
|
|
|
|
DASH=$(printf '%0*s' "$(tput cols)" "" | tr ' ' '-')
|
|
|
|
function print_help_and_exit() {
|
|
printf "Usage: note [ACTION]\n"
|
|
printf "\n"
|
|
printf "Without arguments, will open helix with the note file\n"
|
|
printf "\n"
|
|
printf "Arguments:\n"
|
|
printf " todo | todos [TAG]\n"
|
|
printf " Show only todos, optionally filtered by #TAG\n"
|
|
printf " done | did\n"
|
|
printf " Show only todos that I did today\n"
|
|
printf " day | today\n"
|
|
printf " Show only todays entry\n"
|
|
printf " -1 | -2 | -3\n"
|
|
printf " Show only yesterday/the day before/etc\n"
|
|
exit 1
|
|
}
|
|
|
|
ONLY_TODOS=
|
|
ONLY_DONE=
|
|
ONLY_DAY=
|
|
FILTER_TAG=
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
todo | todos)
|
|
ONLY_TODOS=1
|
|
shift # past argument
|
|
if [ -n "${1+x}" ]; then
|
|
FILTER_TAG="$1"
|
|
shift
|
|
fi
|
|
;;
|
|
done | did)
|
|
ONLY_TODOS=1
|
|
ONLY_DONE=1
|
|
shift # past argument
|
|
;;
|
|
day | today)
|
|
ONLY_DAY=today
|
|
shift # past argument
|
|
;;
|
|
-1 | -2 | -3)
|
|
ONLY_DAY="$1days"
|
|
shift
|
|
;;
|
|
-h | --help)
|
|
print_help_and_exit
|
|
;;
|
|
*)
|
|
echo "Unknown option $1"
|
|
print_help_and_exit
|
|
;;
|
|
esac
|
|
done
|
|
|
|
bat "$XDG_DATA_HOME/life.md/$year.md" |
|
|
{
|
|
if [ -n "$ONLY_TODOS" ]; then
|
|
rg "^- \[.\] " |
|
|
sed 's/- \(\[.\]\) \(.*\) due:\([[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}\)\(.*\)/- \1 \3 \2\4/' |
|
|
sort -r |
|
|
{
|
|
if [ -n "$FILTER_TAG" ]; then
|
|
rg "#$FILTER_TAG\b"
|
|
else
|
|
cat
|
|
fi
|
|
} |
|
|
{
|
|
if [ -n "$ONLY_DONE" ]; then
|
|
rg "^- \[[xX]\] " | rg "done:$(date +%Y-%m-%d)"
|
|
else
|
|
cat
|
|
fi
|
|
}
|
|
elif [ -n "$ONLY_DAY" ]; then
|
|
rg --multiline --multiline-dotall "# $(date -d "$ONLY_DAY" +%Y-%m-%d)(.*?\n#[^#]|.*)"
|
|
else
|
|
cat
|
|
fi
|
|
} |
|
|
sed "s/^# \([[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}\)/ $C_HEADLINE \1 $C_RESET\n/" |
|
|
sed "s/^## \(.*\)\$/ $C_SUBHEADING\1$C_RESET\n/" |
|
|
sed "s/- \[ \] \([[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}\) /- [ ] $C_DEADLINE \1$C_RESET/" |
|
|
sed "s/- \[ \]/ $C_RED$C_RESET/g" |
|
|
sed "s/- \[[xX]\]/ $C_GREEN$C_RESET/g" |
|
|
sed "s/^\(\s*\)- /\1 $C_CYAN$C_RESET /g" |
|
|
sed "s/^\(\s*\)+ /\1 $C_CYAN$C_RESET /g" |
|
|
sed "s/^\([[:digit:]]\{2\}:[[:digit:]]\{2\}\)/$C_BOLD\1$C_RESET/g" |
|
|
sed "s/\(#\S\+\)/$C_CYAN\1$C_RESET/g" |
|
|
sed "s/\(\(due\|done\|prio\):\S\+\)/$C_MAGENTA\1$C_RESET/g" |
|
|
sed "s/^---\$/$C_MAGENTA$DASH$C_RESET/"
|