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

view source for debug

View a block, module, or a definition.

Command Type

built-in

Signature

> view source {flags} (item)

Flags

  • --dependencies, -d: Also show every custom command the item calls, transitively, and every constant those bodies read.

Parameters

  • item: Name or block to view.

Input/output types:

inputoutput
nothingstring

Examples

View the source of a code block.

> let abc = {|| echo 'hi' }; view source $abc
{|| echo 'hi' }

View the source of a custom command.

> def hi [] { echo 'Hi!' }; view source hi
def hi [] { echo 'Hi!' }

View the source of a custom command, which participates in the caller environment.

> def --env foo [] { $env.BAR = 'BAZ' }; view source foo
def --env foo [] { $env.BAR = 'BAZ' }

View the source of a custom command with flags.

> def --wrapped --env foo [...rest: string] { print $rest }; view source foo
def --env --wrapped foo [ ...rest: string] { print $rest }

View the source of a custom command with flags and arguments.

> def test [a?:any --b:int ...rest:string] { echo 'test' }; view source test
def test [ a?: any --b: int ...rest: string] { echo 'test' }

View the source of a module.

> module mod-foo { export-env { $env.FOO_ENV = 'BAZ' } }; view source mod-foo
 export-env { $env.FOO_ENV = 'BAZ' }

View the source of an alias.

> alias hello = echo hi; view source hello
echo hi

View a command together with the commands it calls.

> def helper [] { 42 }; def caller [] { helper }; view source caller --dependencies
def caller [] { helper }

def helper [] { 42 }

View the file where a definition lives via metadata.

> view source some_command | metadata

Notes

The def header is rebuilt from the signature instead of being quoted from the source, so export and attributes are lost. That holds with or without --dependencies.

--dependencies applies to a custom command; on an alias, a module, a closure or a block id it does nothing. It follows only the calls the parser can see, so a closure written inside the body is followed even when it is run through a variable, but one that arrives as an argument is not. And a command built on a large module can pull in a lot of output.

A constant is rebuilt the same way, as const <name> = <value>, because only the name is recorded with a source span. So the value is the one the command actually reads: an expression such as path self shows up already resolved, and an explicit type annotation is lost. $nu and the record bound by use <module> are left out — neither is written as a const anywhere.