Code Monkey home page Code Monkey logo

Comments (7)

guybowden avatar guybowden commented on June 12, 2024

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.

emcrisostomo avatar emcrisostomo commented on June 12, 2024

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.

emcrisostomo avatar emcrisostomo commented on June 12, 2024

I just realised I already answered the same question here. Could you please check it as well?

from fswatch.

guybowden avatar guybowden commented on June 12, 2024

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.

emcrisostomo avatar emcrisostomo commented on June 12, 2024

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.

guybowden avatar guybowden commented on June 12, 2024

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.

emcrisostomo avatar emcrisostomo commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.