Comments (7)
Some more research got me this:
fswatch . | (while read; do python manage.py test; done)
which, I would suggest, would make more sense for the fswatch-run command as it more closely resembles the 0.0.2 way of working. Using xargs passes extra arguments to the command to be run which might not be expecting them.
I have created a super simple bash script fswatch-do
that simplifies things for me:
#!/bin/bash
(while read; do $@; done)
usage:
fswatch -r -o -e 'pyc' somepath | fswatch-do python manage.py test someapp.SomeAppTestCase
am sure there's a better way, but this works for me now.
from fswatch.
Hi @guybowden,
I just answered on StackOverflow. If I understand correctly, you want this one:
$ fswatch -o -0 [opts] paths ... | xargs -0 -n 1 -I {} your command
Beware the pitfalls: the PDF manual and the wiki has a quite comprehensive description of the use cases.
Cheers,
-- Enrico
P.S.: Since you also started a StackOverflow question on the same topic, don't forget to answer it and keep that thread updated as well, in the best interest of whoever finds it on the Internet.
from fswatch.
I just realised I already answered the same question here. Could you please check it as well?
from fswatch.
I didn't find the other question + answer. Thanks for your answer.
I would think that an update to the fswatch-run script would be useful to better emulate the old fswatch syntax.
from fswatch.
Hi,
AFAIK the fswatch-run script should work correctly. If there's a bug, please send an easy way to reproduce it on a stock unix system (that is: your command should only use commonly installed unix utilities). After I can replicate it, I'll have a look at it and fix it.
Currently, I find the problem description too vague.
Also, keep in mind that fswatch-run is a hack to support a syntax which is obsolete and deprecated (because the author thinks it does more harm than good). Users should definitely go with the current fswatch syntax.
Cheers,--
Enrico M. Crisostomo
On Monday, 8 September 2014 at 12:50, guybowden wrote:
I didn't find the other question + answer. Thanks for your answer.
I would think that an update to the fswatch-run script would be useful to better emulate the old fswatch syntax.—
Reply to this email directly or view it on GitHub (#55 (comment)).
from fswatch.
OK.. so more looking reveals that the bash fswatch-run script does work, but should, IMO, include the -r
flag to be recursive.
However on my system (OSX 10.9.4) the zsh script was installed (via homebrew) - which doesn't work the same. I get xargs: python manage.py test: No such file or directory
- not sure why zsh was chosen on install.
I guess it comes down to the new fswatch doing a lot more than the original one did - the original one just executed 'something' when a file within a directory was changed. The syntax was a lot simpler because the way it worked was a lot simpler.
I have now modified my fswatch-run script to look like this (I'm not suggesting that the packaged script should be like this, but am posting here in case anyone else has the same use case as me - namely running a python script when any file within a directory has changed and not caring which file changed, and ignoring .pyc
files)
#!/bin/bash
[ $# -ge 2 ] || {
echo "Illegal number of arguments."
exit 1
}
command -v xargs >/dev/null 2>&1 || {
echo >&2 "xargs is required. Aborting."
exit 2
}
args=("$@")
arg_length=${#args[@]}
last_index=$(($arg_length - 1))
paths_to_watch=${args[@]:0:$last_index}
cmd=${args[$last_index]}
fswatch -o -r -e 'pyc' $paths_to_watch | xargs -n1 -I{} $cmd
from fswatch.
Hi @guybowden,
This kind of "customization-needs" is a compelling reason not to use fswatch-run
, since the old syntax is not flexible and leaves no space to proper customization.
Just use plain fswatch
and pipe its output to a process that fits your needs.
However, there's a but in the ZSH script: the last argument is passed as a single argument to xargs
, which "correcly" complains no such file or directory
.
I'm pushing the fix which is really simple: the last line should read
fswatch -o ${=*[1,-2]} | xargs -n1 -I{} ${=*[-1,-1]}
That missing =
in the variable expansion tells ZSH to split the words in the last argument. Which is yet another bad thing: quoting arguments in an already quoted argument is bad. That's why xargs
, find
in --exec
, etc, all expect multiple words.
I reiterate: if you can, drop fswatch-run
and the old syntax:
- It's just a pipe away.
- It's simple and clear.
- You get rid of such pitfalls.
Cheers,
-- Enrico
from fswatch.
Related Issues (20)
- broken exclude on macos? HOT 1
- Configuration header leaked into public interface in v. 1.17.0 HOT 8
- How to get the PDF documentation HOT 3
- Universal (Arm + x86) library build for MacOS on M1 HOT 1
- Ask for help HOT 1
- import error in silicon mac
- Additional waiting period after --one-event
- Make fails on Solaris 11.4 cbe with gcc-10 or gcc-11
- Trailing slash for directories HOT 1
- CMake package config file is not installed
- fswatch fails to build on windows 11 using cygwin
- Installation for windows missing
- libfswatch README copyright looks stale
- Help configuring fswatch to act only on full file being written by SFTP clients HOT 1
- fswatch command fires multiple events for a single move operation HOT 4
- Which event type should I look for if I am watching a Google Drive directory for new files?
- NetBSD support
- Is there any way to get previous filename for Rename event?
- Symlink question: Is fswatch suppose to notify of linked file changes HOT 1
- execute cmd for single filetype
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fswatch.