Skip to content

Commit 8bcfcb1

Browse files
pheentyJanDeDobbeleer
authored andcommitted
refactor(nush): remove mutable variables from nushell init script
mutable variables, while supported, are considered unwanted in nu
1 parent ecbf9e6 commit 8bcfcb1

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

src/shell/scripts/omp.nu

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,23 @@ def --wrapped _omp_get_prompt [
3131
type: string,
3232
...args: string
3333
] {
34-
mut execution_time = -1
35-
mut no_status = true
3634
# We have to do this because the initial value of `$env.CMD_DURATION_MS` is always `0823`, which is an official setting.
3735
# See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
38-
if $env.CMD_DURATION_MS != '0823' {
39-
$execution_time = $env.CMD_DURATION_MS | into int
40-
$no_status = false
36+
let execution_time = match $env.CMD_DURATION_MS {
37+
'0823' => -1
38+
$ms => { $ms | into int }
4139
}
4240

43-
(
44-
^$_omp_executable print $type
45-
--save-cache
46-
--shell=nu
47-
$"--shell-version=($env.POSH_SHELL_VERSION)"
48-
$"--status=($env.LAST_EXIT_CODE)"
49-
$"--no-status=($no_status)"
50-
$"--execution-time=($execution_time)"
51-
$"--terminal-width=((term size).columns)"
52-
$"--job-count=(job list | length)"
53-
...$args
54-
)
41+
^$_omp_executable print $type
42+
--save-cache
43+
--shell=nu
44+
$"--shell-version=($env.POSH_SHELL_VERSION)"
45+
$"--status=($env.LAST_EXIT_CODE)"
46+
$"--no-status=($execution_time < 0)"
47+
$"--execution-time=($execution_time)"
48+
$"--terminal-width=((term size).columns)"
49+
$"--job-count=(job list | length)"
50+
...$args
5551
}
5652

5753
$env.PROMPT_MULTILINE_INDICATOR = (
@@ -63,10 +59,10 @@ $env.PROMPT_MULTILINE_INDICATOR = (
6359
$env.PROMPT_COMMAND = {||
6460
# hack to set the cursor line to 1 when the user clears the screen
6561
# this obviously isn't bulletproof, but it's a start
66-
mut clear = false
67-
if $nu.history-enabled {
68-
$clear = (history | is-empty) or ((history | last 1 | get 0.command) == "clear")
69-
}
62+
let clear = $nu.history-enabled and (
63+
(history | is-empty)
64+
or (history | last | get command?) == "clear"
65+
)
7066

7167
if ($env.SET_POSHCONTEXT? | is-not-empty) {
7268
do --env $env.SET_POSHCONTEXT

0 commit comments

Comments
 (0)