From 473e1e8f566baaf813195b4af32154ccfb41f55f Mon Sep 17 00:00:00 2001 From: David Thurstenson Date: Wed, 19 Oct 2022 11:55:11 -0500 Subject: [PATCH] Added newdev() which uses inotifywait to list new files in the specified path, or /dev/ if unspecified --- .bashrc.d/newdev.bash | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .bashrc.d/newdev.bash diff --git a/.bashrc.d/newdev.bash b/.bashrc.d/newdev.bash new file mode 100644 index 0000000..a36a59f --- /dev/null +++ b/.bashrc.d/newdev.bash @@ -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 +}