diff --git a/README.md b/README.md index 7756bf4..8efc6a9 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,20 @@ Various runit service files for per-user services. May need to be modified to work on your system. Helper scripts: -- `log`: symlink as the `run` script in your service's log directory to enable logging to `~/.local/log/` -- `setup-supervise.zsh`: run to create symlinks for `supervise` directories, so they are created in $XDG_RUNTIME_DIR -- `new-service`: create a new service, executing the given command line. +- `log`: symlink as the `run` script in your service's log directory to enable + logging to `~/.local/log/` +- `utils/setup-supervise.zsh`: run to create symlinks for `supervise` + directories, so they are created in $XDG_RUNTIME_DIR +- `utils/new-service`: create a new service, executing the given command line. Accepted options before service name: - `-l`, `--log`: create a log directory and symlink `log` script - `-i PROC`, `--import-env PROC`: include import-env script and import environment from process `PROC` Example + ```sh + utils/new-service -l my-daemon --foreground -a -b -c ``` - ./new-service -l my-daemon --foreground -a -b -c - ``` +- `utils/svlogs`: like svlogtail for user services. Uses $SVLOGDIRS or + `~/.local/log/` as base dir. ZSH completion file available in + `utils/completions` diff --git a/utils/completion/_svlogs b/utils/completion/_svlogs new file mode 100644 index 0000000..8a97e36 --- /dev/null +++ b/utils/completion/_svlogs @@ -0,0 +1,11 @@ +#compdef svlogs + +local logs=( ${SVLOGDIR:-$HOME/.local/log}/* ) +logs=( ${logs:t} ) +local arguments=( + '-o[show old logs]' + '--old[show old logs]' + "::logs:(${logs})" +) + +_arguments $arguments diff --git a/utils/svlogs b/utils/svlogs new file mode 100755 index 0000000..87719bc --- /dev/null +++ b/utils/svlogs @@ -0,0 +1,42 @@ +#!/bin/zsh +# based on svlogtail from socklock-void package + +usage () { + cat <<-'EOF' + svlogs [-o] [LOG...] - show svlogd logs conveniently, for user services + + Without arguments, show current logs of all services, uniquely. + With arguments, show all logs of mentioned services + + Uses $SVLOGDIR as base for log directories if set, defaults to ~/.local/log + + Options: + -o, --old Show old logs, too + EOF +} + +BASE_LOGDIR=${SVLOGDIR:-$HOME/.local/log} + +zparseopts -D -E o=showold -old=showold + +if [[ -z $@ ]]; then + cat ${showold:+$BASE_LOGDIR/*/*.[us](N)} $BASE_LOGDIR/*/current | sort -u + tail -Fq -n0 $BASE_LOGDIR/*/current | uniq +else + old=() + cur=() + for log; do + case "$log" in + -*) usage; exit 1;; + esac + if [[ -d $BASE_LOGDIR/$log ]]; then + old+=( $BASE_LOGDIR/$log/*.[us](N) ) + cur+=( $BASE_LOGDIR/$log/current ) + else + echo "no logs for $log" 1>&2 + exit 1 + fi + done + cat ${showold:+$old} $cur | sort + tail -Fq -n0 $cur +fi