寻找一种简单的方法来查看文件、运行 脚本和刷新浏览器
Looking for a simple way to watch files, run a script, and refresh the browser
文件已编辑。文件已保存。 Bash 脚本在保存时是 运行。浏览器会自行刷新以自动显示更改。
Windows, OS X, Linux
有什么建议吗?这似乎是一件经常被忽视的重要事情,我将非常感谢学习如何在所有主要 OSes 之间实现这一目标。
提前致谢。
有几个选项。一种是在 Linux 和 OSX 上使用 entr
- 网站是 here。那么你的命令是:
ls -d * | entr sh -c 'script.bash && reloadbrowser.bash'
entr
的替代方法是使用 fswatch
或 inotifywait
- 语法非常相似。我相信您也可以在 Windows 上使用 fswatch
。
然后我们进入浏览器刷新的问题。这将取决于浏览器和 OS。在 OSX 上,您可以像这样为 Safari 使用 Applescript:
#!/usr/bin/osascript
tell application "Safari"
set currentURL to URL of current tab of front window
set URL of current tab of front window to currentURL
end tell
在 OSX 上使用 Google Chrome,您可以使用:
#!/usr/bin/osascript
tell application "Google Chrome" to reload active tab of window 1
在 Linux 上,您可以按照 here 所述使用 xdotool
。
顺便说一句,在 OSX 上,我将安装 entr
和 fswatch
以及 homebrew
使用:
brew install fswatch
brew install entr
文件已编辑。文件已保存。 Bash 脚本在保存时是 运行。浏览器会自行刷新以自动显示更改。
Windows, OS X, Linux
有什么建议吗?这似乎是一件经常被忽视的重要事情,我将非常感谢学习如何在所有主要 OSes 之间实现这一目标。
提前致谢。
有几个选项。一种是在 Linux 和 OSX 上使用 entr
- 网站是 here。那么你的命令是:
ls -d * | entr sh -c 'script.bash && reloadbrowser.bash'
entr
的替代方法是使用 fswatch
或 inotifywait
- 语法非常相似。我相信您也可以在 Windows 上使用 fswatch
。
然后我们进入浏览器刷新的问题。这将取决于浏览器和 OS。在 OSX 上,您可以像这样为 Safari 使用 Applescript:
#!/usr/bin/osascript
tell application "Safari"
set currentURL to URL of current tab of front window
set URL of current tab of front window to currentURL
end tell
在 OSX 上使用 Google Chrome,您可以使用:
#!/usr/bin/osascript
tell application "Google Chrome" to reload active tab of window 1
在 Linux 上,您可以按照 here 所述使用 xdotool
。
顺便说一句,在 OSX 上,我将安装 entr
和 fswatch
以及 homebrew
使用:
brew install fswatch
brew install entr