2023-05-23 13:24:39 +02:00
|
|
|
# Maintain a list of working directories and navigate them
|
2023-04-09 19:00:20 +02:00
|
|
|
|
|
|
|
# the directory stack
|
2023-05-23 13:24:39 +02:00
|
|
|
# current slot is DIRS_POSITION, but that entry doesn't hold $PWD (until leaving it for some other)
|
|
|
|
# till then, we let CD change PWD freely
|
2023-04-09 19:00:20 +02:00
|
|
|
export-env {
|
|
|
|
let-env DIRS_POSITION = 0
|
|
|
|
let-env DIRS_LIST = [($env.PWD | path expand)]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add one or more directories to the list.
|
|
|
|
# PWD becomes first of the newly added directories.
|
2023-05-19 22:27:45 +02:00
|
|
|
export def-env add [
|
2023-04-09 19:00:20 +02:00
|
|
|
...paths: string # directory or directories to add to working list
|
|
|
|
] {
|
|
|
|
mut abspaths = []
|
|
|
|
for p in $paths {
|
|
|
|
let exp = ($p | path expand)
|
|
|
|
if ($exp | path type) != 'dir' {
|
|
|
|
let span = (metadata $p).span
|
|
|
|
error make {msg: "not a directory", label: {text: "not a directory", start: $span.start, end: $span.end } }
|
|
|
|
}
|
|
|
|
$abspaths = ($abspaths | append $exp)
|
|
|
|
|
|
|
|
}
|
|
|
|
let-env DIRS_LIST = ($env.DIRS_LIST | insert ($env.DIRS_POSITION + 1) $abspaths | flatten)
|
|
|
|
|
2023-05-23 13:24:39 +02:00
|
|
|
|
|
|
|
_fetch 1
|
2023-04-09 19:00:20 +02:00
|
|
|
}
|
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export alias enter = add
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
|
2023-04-09 19:00:20 +02:00
|
|
|
# Advance to the next directory in the list or wrap to beginning.
|
2023-05-19 22:27:45 +02:00
|
|
|
export def-env next [
|
2023-04-09 19:00:20 +02:00
|
|
|
N:int = 1 # number of positions to move.
|
|
|
|
] {
|
|
|
|
_fetch $N
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export alias n = next
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
|
2023-04-09 19:00:20 +02:00
|
|
|
# Back up to the previous directory or wrap to the end.
|
2023-05-19 22:27:45 +02:00
|
|
|
export def-env prev [
|
2023-04-09 19:00:20 +02:00
|
|
|
N:int = 1 # number of positions to move.
|
|
|
|
] {
|
|
|
|
_fetch (-1 * $N)
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export alias p = prev
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
|
2023-04-09 19:00:20 +02:00
|
|
|
# Drop the current directory from the list, if it's not the only one.
|
|
|
|
# PWD becomes the next working directory
|
2023-05-19 22:27:45 +02:00
|
|
|
export def-env drop [] {
|
2023-04-09 19:00:20 +02:00
|
|
|
if ($env.DIRS_LIST | length) > 1 {
|
2023-05-23 13:24:39 +02:00
|
|
|
let-env DIRS_LIST = ($env.DIRS_LIST | reject $env.DIRS_POSITION)
|
|
|
|
if ($env.DIRS_POSITION >= ($env.DIRS_LIST | length)) {$env.DIRS_POSITION = 0}
|
2023-04-09 19:00:20 +02:00
|
|
|
}
|
|
|
|
|
2023-05-23 13:24:39 +02:00
|
|
|
_fetch -1 --forget_current # step to previous slot
|
|
|
|
|
2023-04-09 19:00:20 +02:00
|
|
|
}
|
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export alias dexit = drop
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
|
2023-04-09 19:00:20 +02:00
|
|
|
# Display current working directories.
|
2023-05-19 22:27:45 +02:00
|
|
|
export def-env show [] {
|
2023-04-09 19:00:20 +02:00
|
|
|
mut out = []
|
|
|
|
for $p in ($env.DIRS_LIST | enumerate) {
|
2023-05-23 13:24:39 +02:00
|
|
|
let is_act_slot = $p.index == $env.DIRS_POSITION
|
2023-04-09 19:00:20 +02:00
|
|
|
$out = ($out | append [
|
|
|
|
[active, path];
|
2023-05-23 13:24:39 +02:00
|
|
|
[($is_act_slot),
|
|
|
|
(if $is_act_slot {$env.PWD} else {$p.item}) # show current PWD in lieu of active slot
|
|
|
|
]
|
2023-04-09 19:00:20 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
$out
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export alias shells = show
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export def-env goto [shell?: int] {
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
if $shell == null {
|
2023-05-19 22:27:45 +02:00
|
|
|
return (show)
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if $shell < 0 or $shell >= ($env.DIRS_LIST | length) {
|
|
|
|
let span = (metadata $shell | get span)
|
|
|
|
error make {
|
|
|
|
msg: $"(ansi red_bold)invalid_shell_index(ansi reset)"
|
|
|
|
label: {
|
|
|
|
text: $"`shell` should be between 0 and (($env.DIRS_LIST | length) - 1)"
|
|
|
|
start: $span.start
|
|
|
|
end: $span.end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let-env DIRS_POSITION = $shell
|
|
|
|
|
|
|
|
cd ($env.DIRS_LIST | get $env.DIRS_POSITION)
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:27:45 +02:00
|
|
|
export alias g = goto
|
REFACTOR: remove the shell commands (#8415)
Related to #8368.
# Description
as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands
have been re-implemented in pure-`nushell` in the standard library.
this PR removes the `rust` implementations of these commands.
- all the "shells" tests have been removed from
`crates/nu-commnand/tests/commands/` in
2cc6a82da6f77c01f2a0d06847eabde168a2e56b, except for the `exit` command
- `cd` does not use the `shells` feature in its source code anymore =>
that does not change its single-shell behaviour
- all the command implementations have been removed from
`crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has
been modified accordingly
- the `exit` command now does not compute any "shell" related things
- the `--now` option has been removed from `exit`, as it does not serve
any purpose without sub-shells
# User-Facing Changes
users may now not use `enter`, `shells`, `g`, `n` and `p`
now they would have to use the standard library to have access to
equivalent features, thanks to the `dirs.nu` module introduced by @bobhy
in #8368
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :black_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
# After Submitting
the website will have to be regenerated to reflect the removed commands
:+1:
2023-05-13 19:40:11 +02:00
|
|
|
|
2023-04-09 19:00:20 +02:00
|
|
|
# fetch item helper
|
|
|
|
def-env _fetch [
|
2023-05-23 13:24:39 +02:00
|
|
|
offset: int, # signed change to position
|
|
|
|
--forget_current # true to skip saving PWD
|
2023-04-09 19:00:20 +02:00
|
|
|
] {
|
2023-05-23 13:24:39 +02:00
|
|
|
if not ($forget_current) {
|
|
|
|
# first record current working dir in current slot of ring, to track what CD may have done.
|
|
|
|
$env.DIRS_LIST = ($env.DIRS_LIST | upsert $env.DIRS_POSITION $env.PWD)
|
|
|
|
}
|
|
|
|
|
|
|
|
# figure out which entry to move to
|
2023-04-09 19:00:20 +02:00
|
|
|
# nushell 'mod' operator is really 'remainder', can return negative values.
|
|
|
|
# see: https://stackoverflow.com/questions/13683563/whats-the-difference-between-mod-and-remainder
|
2023-05-23 13:24:39 +02:00
|
|
|
let len = ($env.DIRS_LIST | length)
|
|
|
|
mut pos = ($env.DIRS_POSITION + $offset) mod $len
|
|
|
|
if ($pos < 0) { $pos += $len}
|
|
|
|
|
|
|
|
# if using a different position in ring, CD there.
|
|
|
|
if ($pos != $env.DIRS_POSITION) {
|
|
|
|
$env.DIRS_POSITION = $pos
|
|
|
|
cd ($env.DIRS_LIST | get $pos )
|
|
|
|
}
|
2023-04-09 19:00:20 +02:00
|
|
|
}
|