Added newdev() which uses inotifywait to list new files in the specified path, or /dev/ if unspecified

This commit is contained in:
David Thurstenson 2022-10-19 11:55:11 -05:00
parent d73734401e
commit 473e1e8f56
1 changed files with 27 additions and 0 deletions

27
.bashrc.d/newdev.bash Normal file
View File

@ -0,0 +1,27 @@
newfiles() {
# Path to watch. If the first parameter isn't set, just use /dev/
local path="${1:-/dev/}"
# Seconds without new events before exiting inotifywait
local timeout=10
printf "New files in %s:\n\n" "$path"
inotifywait \
--monitor \
--event create \
--timeout $timeout \
--format '%w%f' \
--quiet \
"$path"
local return=$?
if [[ $return == 2 ]]; then
printf "\nNo new events in %s seconds. Exiting.\n\n" $timeout
return 0
else
printf "\nE: inotifywait returned %s. Exiting.\n\n" $return
return $return
fi
}