Просмотр исходного кода

~/.bin/run: Run and observe commands in the background

This uses `nq` and `notify-send` to run commands in the background,
collect their output, and notify the user when they're done.

This allows running long-running jobs in the background, without loosing
their output, and with notifications when they're done.  This can be
used to download videos in the background, for example.

This is the first try, but it's already useful.
Lucas Stadler лет назад: 8
Родитель
Сommit
bd2ec8ecf6
2 измененных файлов с 32 добавлено и 0 удалено
  1. 19 0
      .bin/run
  2. 13 0
      .bin/run-and-notify

+ 19 - 0
.bin/run

@ -0,0 +1,19 @@
1
#!/bin/bash
2
3
export NQDIR="${NQDIR:-$HOME/.cache/run}"
4
5
case "$1" in
6
	-nq)
7
		shift
8
		nq $*
9
		;;
10
	-fq)
11
		shift
12
		fq $*
13
		;;
14
	*)
15
		logfile="$(nq run-and-notify $*)"
16
		echo -e "$(date +%s)\t$logfile\t$*" >> "$NQDIR/jobs"
17
		echo "$NQDIR/$logfile"
18
		;;
19
esac

+ 13 - 0
.bin/run-and-notify

@ -0,0 +1,13 @@
1
#!/bin/bash
2
3
sh -c "$*"
4
5
result="$?"
6
state="success"
7
notify_opts=""
8
if ! [ "$result" = "0" ]; then
9
	state="error"
10
	# set notify-send option to indicate an error
11
fi
12
13
notify-send $notify_opts "$1 finished running ($state)" "'$*' ran until `date` and exited with status $result."