Skip to content

Instantly share code, notes, and snippets.

@lcomino
Last active February 28, 2019 02:41
Show Gist options
  • Save lcomino/6a926cd6d5ee9569ef669a94c254a7ba to your computer and use it in GitHub Desktop.
Save lcomino/6a926cd6d5ee9569ef669a94c254a7ba to your computer and use it in GitHub Desktop.
Run command each time the file changes (PowerShell)

#Script

function watch($file, $command) {
    $this_time = (get-item $file).LastWriteTime
    $last_time = $this_time
    while($true) {
        if ($last_time -ne $this_time) {
            $last_time = $this_time
            invoke-command $command
        }
        sleep 1
        $this_time = (get-item $file).LastWriteTime
    }
}

#How
watch File {Command Here}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment