force adding a whenfilechanges function for all
This commit is contained in:
27
qcd_function
27
qcd_function
@@ -77,3 +77,30 @@ function qcd() {
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function whenfilechanges() {
|
||||
[ -z "$1" ] && { echo 'Usage: whenfilechanges "file" "some" "command"
|
||||
Follows the modification time of the "file" and runs the command
|
||||
at every change. '
|
||||
return
|
||||
}
|
||||
[ -e "$1" ] || { echo $1 not found
|
||||
return
|
||||
}
|
||||
|
||||
fname=$1
|
||||
shift 1
|
||||
otime=$( stat -c %Z "$fname" )
|
||||
while :
|
||||
do ntime=$( stat -c %Z "$fname" )
|
||||
[ "$ntime" -ne "$otime" ] && {
|
||||
eval "$@"
|
||||
otime="$ntime"
|
||||
}
|
||||
|
||||
sleep 2
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user