Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch a specific directory. #37

Closed
jaypeedevlin opened this issue May 7, 2020 · 2 comments
Closed

Watch a specific directory. #37

jaypeedevlin opened this issue May 7, 2020 · 2 comments

Comments

@jaypeedevlin
Copy link

I'm wanting to monitor for a file change two directories deep, where the filename is known but the middle directory is not. This is what I have so far:

while true;
    do ls foo/*/bar.txt | entr -dp echo /_;
done

If when I start the while loop the file foo/1/bar.txt exists, it seems like the directory foo/1 is detected to be watched, not foo (which makes total sense, it's just not what I'm trying to do).

I can see in the documentation there is a reference to -d being able to used with an explicitly supplied directory, but try as I might I can't get the syntax to work. I'm not sure if what I'm trying to achieve is not currently supported, or if it is and I'm just missing something from a syntax perspective.

Could you offer some clarification?

@eradman
Copy link
Owner

eradman commented May 7, 2020

Let me see if I can answer this using a slightly different example:

mkdir -p src/{1,2,3}
touch src/1/a.txt
touch src/2/b.txt

Now we have three directories and two files

src
├── 1
│   └── a.txt
├── 2
│   └── b.txt
└── 3

The trick here is to find the files and an empty directories. You can do this using a combination of ls -d and shell globbing. Try

ls -d src/* src/*/* | sort

Now if you add/remove/modify files the following loop should track properly

while sleep 1; do
    ls -d src/* src/*/* | entr -dp echo /_
done

@jaypeedevlin
Copy link
Author

Thanks Eric, I'll take this and see if I can mold it to my specific needs!

@eradman eradman closed this as completed Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants