Add --env and --wrapped flags to def (#10566)

This commit is contained in:
Jakub Žádník
2023-10-02 21:13:31 +03:00
committed by GitHub
parent 0d367af24a
commit eb6870cab5
20 changed files with 385 additions and 191 deletions

View File

@ -23,7 +23,7 @@ export-env {
# Add one or more directories to the list.
# PWD becomes first of the newly added directories.
export def-env add [
export def --env add [
...paths: string # directory or directories to add to working list
] {
mut abspaths = []
@ -45,7 +45,7 @@ export def-env add [
export alias enter = add
# Advance to the next directory in the list or wrap to beginning.
export def-env next [
export def --env next [
N:int = 1 # number of positions to move.
] {
_fetch $N
@ -54,7 +54,7 @@ export def-env next [
export alias n = next
# Back up to the previous directory or wrap to the end.
export def-env prev [
export def --env prev [
N:int = 1 # number of positions to move.
] {
_fetch (-1 * $N)
@ -64,7 +64,7 @@ export alias p = prev
# Drop the current directory from the list, if it's not the only one.
# PWD becomes the next working directory
export def-env drop [] {
export def --env drop [] {
if ($env.DIRS_LIST | length) > 1 {
$env.DIRS_LIST = ($env.DIRS_LIST | reject $env.DIRS_POSITION)
if ($env.DIRS_POSITION >= ($env.DIRS_LIST | length)) {$env.DIRS_POSITION = 0}
@ -78,7 +78,7 @@ export def-env drop [] {
export alias dexit = drop
# Display current working directories.
export def-env show [] {
export def --env show [] {
mut out = []
for $p in ($env.DIRS_LIST | enumerate) {
let is_act_slot = $p.index == $env.DIRS_POSITION
@ -95,7 +95,7 @@ export def-env show [] {
export alias shells = show
export def-env goto [shell?: int] {
export def --env goto [shell?: int] {
if $shell == null {
return (show)
}
@ -119,7 +119,7 @@ export def-env goto [shell?: int] {
export alias g = goto
# fetch item helper
def-env _fetch [
def --env _fetch [
offset: int, # signed change to position
--forget_current # true to skip saving PWD
--always_cd # true to always cd

View File

@ -34,7 +34,7 @@ use log.nu
# ```nushell
# >_ std path add {linux: "foo", windows: "bar", darwin: "baz"}
# ```
export def-env "path add" [
export def --env "path add" [
--ret (-r) # return $env.PATH, useful in pipelines to avoid scoping.
--append (-a) # append to $env.PATH instead of prepending to.
...paths # the paths to add to $env.PATH.