cespare / reflex

Run a command when files change
MIT License
3.35k stars 135 forks source link

How to run a command with && in reflex #99

Closed nikitavoloboev closed 1 year ago

nikitavoloboev commented 1 year ago

watchexec --restart --exts ts "tput reset && tsx run.ts"

How can I do above command in reflex? Above command is for https://watchexec.github.io

I want to move to Reflex. It basically runs tput reset && tsx run.ts when any .ts file changes. And restarts the process in case its a running server too.

nikitavoloboev commented 1 year ago
image

tried above that failed

cespare commented 1 year ago

You need a shell. See https://github.com/cespare/reflex#notes-and-tips.

nikitavoloboev commented 1 year ago

Thanks, I think I am close

I tried this reflex -r '\.ts$' -- sh -c 'tsup && tsx run.ts'

And different variations of it and none work.

From --help

Usage: reflex [OPTIONS] [COMMAND]

COMMAND is any command you'd like to run. Any instance of {} will be replaced with the filename of the changed file. (The symbol may be changed with the --substitute flag.)

but i don't get, where options stop and where command begins with shell.

Thanks.

nikitavoloboev commented 1 year ago

Like in theory command should be close to this

reflex -- sh -c 'tsup && run.ts'

But need to add .ts watcher somehow.

So I added the -r '\.ts$' thing. But I guess I did it in wrong place. Readme does not mention this case I think.

p.s. running reflex -r '\.ts$' tsx run.ts for now as I can't get shell working to add tsup.

cespare commented 1 year ago

And different variations of it and none work.

In what way doesn't it work? Please provide the exact command you are running with the full output.

Side note: if the thing you are running is some kind of server or long-running process, you probably want -s/--start-service.

nikitavoloboev commented 1 year ago

Actually my bad I was messing up the command.

reflex -r '\.ts$' -- sh -c 'tput reset && tsx run.ts' works how I want it to