2##! Author: Pieter van der Star (info@pietervanderstar.nl)
3##! Modifications by: (unmodified)
5##! This program is free software: you can redistribute it and/or modify
6##! it under the terms of the GNU Affero General Public License as
7##! published by the Free Software Foundation, either version 3 of the
8##! License, or (at your option) any later version.
10##! This program is distributed in the hope that it will be useful,
11##! but WITHOUT ANY WARRANTY; without even the implied warranty of
12##! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13##! GNU Affero General Public License for more details.
15##! You should have received a copy of the GNU Affero General Public License
16##! along with this program. If not, see <https:
20#┏━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┓
21#┃ 11 jun 2022 │ First release │ Pieter van der Star ┃
22#┠───────────────┼──────────────────────────────────────────┼──────────────────────────┨
23#┃ 24 feb 2024 │ Changed documentation comments to be │ Pieter van der Star ┃
24#┃ │ compatible with my doxygen-bash-filter. │ ┃
25#┠───────────────┼──────────────────────────────────────────┼──────────────────────────┨
26#┃ 9 may 2024 │ Readded spaces between the arguments. │ Pieter van der Star ┃
27#┗━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┛
30##! @brief This script can be used to automatically run a command as soon as a file is updated/saved.
31echo
"When waiting press: q to quit";
33echo
" f to show the file to wait on";
34echo
" c to show the command to run";
37 echo
"Please enter a file to wait on as first argument.";
41 echo
"Please enter bash script to execute as second argument.";
44#get the arguments, first the file
45##! Name of the file to use as trigger.
49##! The command to execute on file modifications.
52#string together all other arguments to make and run, these are the arguments
53#to the program given in command
54##! Arguments to pass to the command.
60echo
"arguments: $arguments";
61##! Last modified date when we previously ran the command.
64while [ 1 -eq 1 ];
do #
using [ 1 -eq 1 ] instead of
true for wider compatibility
65 lastmod=$(date -r
"$file" +%s);
67 echo
"file not found";
69 if [
"$lastmod" -gt
"$prevlastmod" ]; then
70 eval
"$command $arguments";
72 echo
"---------------------------RUN_ON_SAVE---------------------------";
76 if [
"$key" ==
'q' ]; then
80 if [
"$key" ==
'r' ]; then
84 if [
"$key" ==
'f' ]; then
86 echo
"waiting on update of $file";
88 if [
"$key" ==
'c' ]; then
90 echo
"after update run: \"$command $arguments\"";
if(func_num_args() -le 0) if(func_num_args() -le 1) $file
Name of the file to use as trigger.
$arguments
Arguments to pass to the command.
$prevlastmod
Last modified date when we previously ran the command.
$command
The command to execute on file modifications.