Inotifywait To run a command based on a modified file type

I specifically try to simultaneously watch 2 different types of files in 2 subdirectories:

.coffee filetypes in the js subdirectory
.styl filetypes in the 'css' subdirectory

I know only so much bash, and I'm trying to make something like this function

while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do # regex pattern to match the file ending # and define it to $ending if[ $ending == coffee ] then coffee -c $file elif[ $ending == styl ] then stylus -c $file fi done 



// Edit // changed this line:

 while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do 

So now it checks both files, but if there are no files in the css folder. coffee or .styl files in js, it returns an error so that files are not found.

In addition, I noticed that when I run this script, it returns / runs the next 3 times

 Setting up watches. Watches established. ./css/styles.styl 
+4
source share
1 answer

Not the cleanest solution, but it works

 #!/bin/sh while file=$(inotifywait -r -e modify --format "%w%f" ./); do EXT=${file##*.} if [ $EXT = "styl" ] then stylus -c $file fi if [ $EXT = "coffee" ] then coffee -c $file fi done 

If you have a better solution that only tracks the files I want, then I'm all ears

+2
source

Source: https://habr.com/ru/post/1433612/


All Articles