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 +}