This is certainly hacky, but if you want to work locally without making any external request (to live.js
, for example), or run any local server, I think this might be useful. This is not specific to web development, you can adopt similar strategy to any other workflow.
You will need two tiny tools (which are present in almost all distribution repos): inotify-tools
and xdotool
.
First get the ID
of your Firefox and your editor window using xdotool
.
$ xdotool search --name "Mozilla Firefox"
60817411
60817836
$ xdotool search --name "Pluma" # Pluma is my editor
94371842
Depending on the number of processes running, you will get one or more window ID
. Use xdotool windowactivate <ID>
to know which one you want (the focus changes to the respective window).
Use inotifywait -e close_write
to monitor changes to your local file and when you save the file using your editor, change focus to your browser, reload xdotool key CTRL+R
and focus back to your editor. This is so instantaneous you will not notice nothing.
Also, inotifywait
exits on change, so you might have to do it in a loop. Here is a minimum working example (in Bash in your working directory).
while /usr/bin/true
do
inotifywait -e close_write index.html;
xdotool windowactivate 60917411; # Switch to Firefox
xdotool key CTRL+R; # Reload Firefox
xdotool windowactivate 94371842 # Switch back to Pluma
done
- You can use
inotifywait
to watch for the entire directory or some selected files in your directory.
- You can write a script that can automate is easily.
- This works on Linux (I've tested this on Void Linux.)