Auto-reload browser when I save changes to html file, in Chrome?

后端 未结 23 2147
半阙折子戏
半阙折子戏 2020-12-12 11:46

I\'m editing an HTML file in Vim and I want the browser to refresh whenever the file underneath changes.

Is there a plugin for Google Chrome that will listen for ch

23条回答
  •  孤城傲影
    2020-12-12 12:40

    This works for me (in Ubuntu):

    #!/bin/bash
    #
    # Watches the folder or files passed as arguments to the script and when it
    # detects a change it automatically refreshes the current selected Chrome tab or
    # window.
    #
    # Usage:
    # ./chrome-refresher.sh /folder/to/watch
    
    TIME_FORMAT='%F %H:%M'
    OUTPUT_FORMAT='%T Event(s): %e fired for file: %w. Refreshing.'
    
    while inotifywait --exclude '.+\.swp$' -e modify -q \
        -r --timefmt "${TIME_FORMAT}" --format "${OUTPUT_FORMAT}" "$@"; do
        xdotool search --onlyvisible --class chromium windowactivate --sync key F5 \
        search --onlyvisible --class gnome-terminal windowactivate
    done
    

    You may need to install inotify and xdotool packages (sudo apt-get install inotify-tools xdotool in Ubuntu) and to change args of --class to the actual names of your preferred browser and terminal.

    Start the script as described and just open index.html in a browser. After each save in vim the script will focus your browser's window, refresh it, and then return to the terminal.

提交回复
热议问题