How do I run a bash script from File Watcher

In Webstorm 8, how do I set up a file watcher to update a text file with the current date and time? I started to investigate using sed to update the text file.

I'd like to overwrite line 2 of a text file with the output of

date
, prefixed with #:
# Wed May 28 08:31:01 CDT 2014

I've got this far in OSX bash. I can't get it to work in Webstorm yet.

sed -e "2s|.*|# `date`|g" "cache.manifest" > "cache.manifest.tmp" && mv cache.manifest.tmp cache.manifest

This writes the output of

date
into line 2 of a temp file, then renames the temp file back to cache.manifest.

How in the world do I get this to run in Webstorm's file watcher? The cache.manifest file is in my project directory/app and won't move.

In the Edit Watcher dialog I have this so far but the darn thing just outputs the whole cache.manifest file to the Webstorm terminal (including the edited second line as #
date
). Then "process finished with exit code 1".
Very helpful. :)
File Type: Any
Scope: Open Files
Program: sed
Arguments: -e "2s|.*|# `date`|g" "cache.manifest" > "cache.manifest.tmp" && mv cache.manifest.tmp cache.manifest
Working Directory: $ProjectFileDir$/app


I also tried creating a .sh file and putting that in the program field and leaving the arguments field blank.  But that didn't work either.  What's the correct way to do this?

#!/bin/bash

sed -e "2s|.*|# `date`|g" "cache.manifest" > "cache.manifest.tmp" && mv cache.manifest.tmp cache.manifest

1 comment
Comment actions Permalink

The second solution (sh script) works fine for me. The first one doesn't, as sed executable was not found - watchers expect a full path to executable as a command

0

Please sign in to leave a comment.