Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

watch for filesystem

Watch for file changes and execute Nu code when they happen.

Signature

> watch {flags} (path) (closure)

Flags

  • --debounce-ms, -d {int}: Debounce changes for this many milliseconds (default: 100). Adjust if you find that single writes are reported as multiple events
  • --glob, -g {string}: Only report changes for files that match this glob pattern (default: all files)
  • --recursive, -r {bool}: Watch all directories under <path> recursively. Will be ignored if <path> is a file (default: true)
  • --quiet, -q: Hide the initial status message (default: false)
  • --verbose, -v: Operate in verbose mode (default: false)

Parameters

  • path: The path to watch. Can be a file or directory.
  • closure: Some Nu code to run whenever a file changes. The closure will be passed operation, path, and new_path (for renames only) arguments in that order.

Input/output types:

inputoutput
nothingtable

Examples

Run cargo test whenever a Rust file changes

> watch . --glob=**/*.rs {|| cargo test }

Watch all changes in the current directory

> watch . { |op, path, new_path| $"($op) ($path) ($new_path)"}

Log all changes in a directory

> watch /foo/bar { |op, path| $"($op) - ($path)(char nl)" | save --append changes_in_bar.log }

Note: if you are looking to run a command every N units of time, this can be accomplished with a loop and sleep

> loop { command; sleep duration }