mirror of https://git.sr.ht/~skiqqy/bin
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
73 lines
1.6 KiB
#!/usr/bin/env bash
|
|
# Author: Skiqqy
|
|
# Simple todo tracker
|
|
|
|
main()
|
|
{
|
|
if [ ! -f '/tmp/todo.directory' ]
|
|
then
|
|
printf 'todo.directory not found, generating cache'
|
|
wdir="$(find "$HOME" -regex '.*/todo' -type d 2> /dev/null | head -1)"
|
|
printf "wdir=%s\n" "$wdir" > /tmp/todo.directory
|
|
else
|
|
printf 'todo.directory found, skipping $ find ...\n'
|
|
. /tmp/todo.directory
|
|
fi
|
|
|
|
[ -z "$wdir" ] && printf 'Please create a "todo" directory...\n' && return 1
|
|
term= # Terminal to launch todo in, default is curr shell
|
|
|
|
while getopts hs opt
|
|
do
|
|
case "$opt" in
|
|
h)
|
|
echo 'TODO. usage()'
|
|
return
|
|
;;
|
|
s)
|
|
# Set the default term
|
|
term=
|
|
command -v st && term='st -e' # Run in new terminal
|
|
[ -z "$term" ] && command -v gnome-terminal && \
|
|
term='gnome-terminal --' # Run in new terminal
|
|
;;
|
|
*)
|
|
echo 'TODO. usage()'
|
|
return 1
|
|
;;
|
|
esac
|
|
done
|
|
shift "$((OPTIND-1))" # Get rid of parsed args
|
|
|
|
# Change work dir.
|
|
pushd "$wdir" || return 1
|
|
shopt -s nullglob
|
|
case "$1" in
|
|
compile|build)
|
|
for f in *.md
|
|
do
|
|
pdf "$f"
|
|
done
|
|
;;
|
|
''|pdf)
|
|
if [ "$1" = pdf ]
|
|
then
|
|
! command -v pdf && open='xdg-open' || open=pdf
|
|
fi
|
|
open=${open:-"$EDITOR"} # What to open the file with.
|
|
run="select open in *.${1:-md}; do $open \"\$open\"; done" # Funky eval string
|
|
if [ -n "$term" ]
|
|
then
|
|
$term env -C "$wdir" bash -c "$run" # Run in term
|
|
else
|
|
eval "$run" # eval is evil, but rn i need it :p
|
|
fi
|
|
;;
|
|
*)
|
|
$term $EDITOR "$(basename "$1" .md).md" # I want splitting
|
|
;;
|
|
esac
|
|
popd || return 1
|
|
}
|
|
|
|
main "$@"
|
|
|