From a1bae69d54bfebbdb99c4beb644ebc755a75da24 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 12 Mar 2024 19:44:04 +0100 Subject: add some example plugins --- core/help | 2 +- core/path | 2 +- core/state | 21 --------------------- core/status | 21 +++++++++++++++++++++ core/update | 3 --- dppt | 4 ++-- makefile | 1 + plugins/display | 17 +++++++++++++++++ plugins/notify | 45 +++++++++++++++++++++++++++++++++++++++++++++ plugins/polybar | 43 +++++++++++++++++++++++++++++++++++++++++++ readme.md | 7 +++++++ 11 files changed, 138 insertions(+), 28 deletions(-) delete mode 100755 core/state create mode 100755 core/status create mode 100755 plugins/display create mode 100755 plugins/notify create mode 100755 plugins/polybar diff --git a/core/help b/core/help index 4bc5496..56783d2 100755 --- a/core/help +++ b/core/help @@ -33,6 +33,6 @@ done | awk ' cat << EOF -if no action is provided, the \`state\` action is chosen by default +if no action is provided, the \`status\` action is chosen by default EOF diff --git a/core/path b/core/path index 23f7f5c..376059b 100644 --- a/core/path +++ b/core/path @@ -1,5 +1,5 @@ #!/bin/sh # initialize default search path for core + plugins -path="$core_path" +path="$core_path:$path" path="$XDG_DATA_HOME/$progname:$path" export path diff --git a/core/state b/core/state deleted file mode 100755 index 6aad04b..0000000 --- a/core/state +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -[ "$1" = "info" ] && echo "show timer" && exit 2 -. "$core_path/lib" - -usage() { - cat << EOF -$subcmd -- show timer - -usage: - $subcmd [options] - -options: - -h, --help show help - -actions: -EOF -} - -. "$core_path/update" -echo "lap $lap, $([ $running -eq 1 ] && echo "running" || echo "paused"), $(fmt_time $remaining)" - diff --git a/core/status b/core/status new file mode 100755 index 0000000..6aad04b --- /dev/null +++ b/core/status @@ -0,0 +1,21 @@ +#!/bin/sh +[ "$1" = "info" ] && echo "show timer" && exit 2 +. "$core_path/lib" + +usage() { + cat << EOF +$subcmd -- show timer + +usage: + $subcmd [options] + +options: + -h, --help show help + +actions: +EOF +} + +. "$core_path/update" +echo "lap $lap, $([ $running -eq 1 ] && echo "running" || echo "paused"), $(fmt_time $remaining)" + diff --git a/core/update b/core/update index 686def2..6844114 100644 --- a/core/update +++ b/core/update @@ -38,9 +38,6 @@ if [ $running -eq 1 ] && [ "${remaining#-}" != "${remaining}" ] ; then update_time=1 fi -# update remaining time if in reset -[ $lap -eq 0 ] && [ $time = '0' ] && update_time=1 - if [ $update_time -eq 1 ] ; then # skip_libraries is used to prevent endless loop (see top of this file) time=$(skip_libraries=y "$prog" lap $lap) diff --git a/dppt b/dppt index 3010bba..9e32b77 100755 --- a/dppt +++ b/dppt @@ -19,8 +19,8 @@ done # action is first argument after options action="$1" -# default action is to display state -[ -z "$action" ] && exec "$prog" state +# default action is to display status +[ -z "$action" ] && exec "$prog" status shift IFS=':' # make sure for loop splits $path on colon diff --git a/makefile b/makefile index d688487..8beeec4 100644 --- a/makefile +++ b/makefile @@ -13,6 +13,7 @@ install: FORCE mkdir -p $(DESTDIR)$(PREFIX)/bin cp $(NAME) $(DESTDIR)$(PREFIX)/bin/$(NAME) sed 's#\(\=\).*#\1"$(CORE_PATH)"#' -i $(DESTDIR)$(PREFIX)/bin/$(NAME) + sed 's#\(\=\).*#\1"$(NAME)"#' -i $(DESTDIR)$(PREFIX)/bin/$(NAME) mkdir -p $(CORE_PATH) cp -r core/. $(CORE_PATH)/ mkdir -p $(DESTDIR)$(MANPREFIX)/man1 diff --git a/plugins/display b/plugins/display new file mode 100755 index 0000000..7d8441c --- /dev/null +++ b/plugins/display @@ -0,0 +1,17 @@ +#!/bin/sh +[ "$1" = "info" ] && echo "plugin to display time nicely" && exit 2 + +. "$core_path/lib" +. "$core_path/update" + +# on reset, print empty line to clear module +if [ $lap -eq 0 ] && [ $running -eq 0 ] && [ $time = $("$prog" lap 0) ] ; then + echo "" + exit +fi + +# print time in square brackets if running, else between dashes +time="$(fmt_time $remaining)" +[ $running -eq 1 ] && echo "[$time]" \ + || echo "-$time-" + diff --git a/plugins/notify b/plugins/notify new file mode 100755 index 0000000..24565ec --- /dev/null +++ b/plugins/notify @@ -0,0 +1,45 @@ +#!/bin/sh +[ "$1" = "info" ] && echo "run the notification daemon" && exit 2 + +. "$core_path/lib" + +runtime_dir="$XDG_RUNTIME_DIR/$progname" + +mkdir -p "$runtime_dir" +notify_file="$runtime_dir/notify" + +pid_file="$runtime_dir/pid" +[ -e "$pid_file" ] && err "$pid_file exists! use \`kill $(cat "$pid_file")\` to stop the other daemon" +echo "$$" > "$pid_file" + +update() { + unset original_state remaining running + . "$core_path/update" + touch "$notify_file" +} +update + +watch_pid=0 + +cleanup() { + trap - TERM + rm -f "$pid_file" +} +trap cleanup INT TERM EXIT + +while inotifywait -qq -e modify "$POMODORO_STATE_PATH/primary" ; do + update + if [ $running -eq 1 ] ; then + if [ $watch_pid = 0 ] ; then + while :; do + update & + sleep 1 + done & + watch_pid=$! + fi + else + kill -- $watch_pid 2> /dev/null + watch_pid=0 + fi +done + diff --git a/plugins/polybar b/plugins/polybar new file mode 100755 index 0000000..430b814 --- /dev/null +++ b/plugins/polybar @@ -0,0 +1,43 @@ +#!/bin/sh +[ "$1" = "info" ] && echo "plugin for script module in polybar" && exit 2 + +. "$core_path/lib" + +usage() { + cat << EOF +usage: + $subcmd [options] + +options: + -h, --help display this help text + +this plugin is intended to be used in combination with polybar. add the +following to your config.ini file to use this plugin: + + [module/$progname] + type = custom/script + exec = $subcmd + tail = true + click-left = $progname toggle + click-middle = $progname reset +EOF +} + +while [ $# -gt 0 ] ; do + case "$1" in + -h|--help) usage && exit 0 ;; + --) shift ; break ;; + *) err "unknown parameter: $1" ;; + esac +done + +# launch notify daemon if it is not already active +("$prog" notify 1> /dev/null 2> /dev/null &) +sleep 0.1 # warm up a little + +"$prog" display +while inotifywait -qq -e attrib "$XDG_RUNTIME_DIR/$progname/notify" ; do + unset remaining lap time running + "$prog" display +done + diff --git a/readme.md b/readme.md index ec99416..b4adb7d 100644 --- a/readme.md +++ b/readme.md @@ -20,3 +20,10 @@ features: # make install ``` +## plugins + +this repository contains example plugins. some of these plugins rely on +external dependencies, and are therefore not installed by default. + +more information on plugins is available in man dppt(1). + -- cgit v1.2.3