nushell.github.io icon indicating copy to clipboard operation
nushell.github.io copied to clipboard

docs: fix syntax

Open bf opened this issue 5 months ago • 5 comments

Add missing ) to docs.

bf avatar Sep 30 '25 09:09 bf

Working example is now

$env.config = ($env.config | upsert hooks {
    env_change: {
        PWD: [{
            code: 'print $"changing directory from ($before) to ($after)"'
        }]
    }
})

website at https://www.nushell.sh/book/hooks.html#hooks-as-strings currently shows broken example:

$env.config = ($env.config | upsert hooks {
    env_change: {
        PWD: {
            code: 'print $"changing directory from ($before) to ($after)"'
        }
    }
}

bf avatar Sep 30 '25 09:09 bf

Are the parentheses even needed at all? This works but it will also overwrite your existing env_change.PWD if it already exists.

$env.config = $env.config | upsert hooks {
    env_change: {
        PWD: [{
            code: 'print $"changing directory from ($before) to ($after)"'
        }]
    }
}

fdncred avatar Sep 30 '25 11:09 fdncred

We should probably go further and update these to use the "modern" style:

# Make sure the `PWD` hook list exists
$env.config.hooks.env_change.PWD = $env.config.hooks.env_change.PWD? | default []

# Add hook(s)
$env.config.hooks.env_change.PWD ++= [
    {
        condition: {|_, after| $after == /some/path/to/directory }
        code: 'def foo [] { print "foo" }'
    }
    {
        condition: {|before, _| $before == /some/path/to/directory }
        code: 'hide foo'
    }
]

$env.config.hooks.env_change.PWD ++= [
    {
        code: 'print $"changing directory from ($before) to ($after)"'
    }
]

Bahex avatar Oct 05 '25 12:10 Bahex

I like to merged this pull request but how do I get access to the repository?

wsx7524999 avatar Oct 19 '25 22:10 wsx7524999

I like to merged this pull request but how do I get access to the repository?

Only maintainers have access.

If this PR gets updated similar to bahex's suggestion, we'll land it.

fdncred avatar Oct 20 '25 01:10 fdncred