Skip to content

Commit

Permalink
use $env. instead of let-env (nushell#543)
Browse files Browse the repository at this point in the history
related to nushell/nushell#9574

Commands used
```nushell
sd --string-mode "let-env " '$env.' **/*
git rst before_v0.60/
```
  • Loading branch information
amtoine committed Jul 1, 2023
1 parent c37fd04 commit a61256d
Show file tree
Hide file tree
Showing 32 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion custom-menus/zoxide-menu.nu
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __edit_keybinding [] {
}

export-env {
let-env config = ($env.config
$env.config = ($env.config
| upsert menus ($env.config.menus | append (__zoxide_menu))
| upsert keybindings ($env.config.keybindings | append [(__zoxide_keybinding) (__edit_keybinding)])
)
Expand Down
2 changes: 1 addition & 1 deletion hooks/direnv/config.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## To enable direnv in nushell we must run code in the context of the current shell - i.e it cannot be within a block and it needs to run as a "code" string as per https://github.com/nushell/nushell/pull/5982 (so you must run nushell 0.66 or later). That way it works as if you'd typed in and run the code directly in your shell.
## Direnv knows what to do otherwise and will export the env to load (or unload) based on what is in your current environment so this is all that is needed with some checks for empty strings, defaulting then to an empty table so that load-env is always happy.

let-env config = {
$env.config = {
hooks: {
pre_prompt: [{
code: "
Expand Down
2 changes: 1 addition & 1 deletion hooks/direnv/direnv.nu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def direnv [] {
}

export-env {
let-env config = ( $env.config | upsert hooks.env_change.PWD { |config|
$env.config = ( $env.config | upsert hooks.env_change.PWD { |config|
let o = ($config | get -i hooks.env_change.PWD)
let val = (direnv)
if $o == $nothing {
Expand Down
2 changes: 1 addition & 1 deletion hooks/dynamic-load/dynamic-load.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def dynamic_load [] {
}

export-env {
let-env config = ( $env.config | upsert hooks.env_change.PWD { |config|
$env.config = ( $env.config | upsert hooks.env_change.PWD { |config|
let o = ($config | get -i hooks.env_change.PWD)
let val = (dynamic_load)
if $o == $nothing {
Expand Down
6 changes: 3 additions & 3 deletions hooks/filesystem/autojump.nu
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
# Run `j` to jump arround

def autojump_add_to_database [dir] {
let-env AUTOJUMP_SOURCED = 1
$env.AUTOJUMP_SOURCED = 1
autojump --add $dir
}
def-env j [dir] {
let-env AUTOJUMP_SOURCED = 1
$env.AUTOJUMP_SOURCED = 1
cd (autojump $dir)
}
let-env config = ($env.config | upsert hooks.env_change.PWD {|config|
$env.config = ($env.config | upsert hooks.env_change.PWD {|config|
let val = ($config | get -i hooks.env_change.PWD)

if $val == $nothing {
Expand Down
2 changes: 1 addition & 1 deletion modules/base16/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Next, set up Nushell config, assuming the base16 colors are generated
use ~/.config/nushell/base16.nu
# File containing base16 colors
let-env BASE16_TXT = "/tmp/base16.txt"
$env.BASE16_TXT = "/tmp/base16.txt"
let config = {
color_config: (base16 build-nu-config $env.BASE16_TXT)
Expand Down
2 changes: 1 addition & 1 deletion modules/base16/base16.nu
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export def build-alacritty-config [base_txt: path] {
# | save --raw "~/.config/alacritty/alacritty_colors.yml"
let conf = ($base16 | apply-base16-mustache $template)

let-env ALACRITTY_CONFIG = $conf
$env.ALACRITTY_CONFIG = $conf

nu -c "$nu.env.ALACRITTY_CONFIG | save --raw '~/.config/alacritty/alacritty_colors.yml'"
}
Expand Down
2 changes: 1 addition & 1 deletion modules/docker/docker.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export-env {
for c in [podman nerdctl docker] {
if not (which $c | is-empty) {
let-env docker-cli = $c
$env.docker-cli = $c
break
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/kubernetes/kubernetes.nu
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export def `kcache flush` [] {
}

export-env {
let-env KUBERNETES_SCHEMA_URL = $"file:https:///($env.HOME)/.config/kubernetes-json-schema/all.json"
let-env KUBERNETES_RESOURCE_ABBR = {
$env.KUBERNETES_SCHEMA_URL = $"file:https:///($env.HOME)/.config/kubernetes-json-schema/all.json"
$env.KUBERNETES_RESOURCE_ABBR = {
s: services
d: deployments
p: pods
Expand Down Expand Up @@ -388,7 +388,7 @@ export def-env kcconf [name: string@"nu-complete kube ctx"] {
let dist = $"($env.HOME)/.kube/config.d"
mkdir $dist
kconf export $name | save -fr $"($dist)/($name)"
let-env KUBECONFIG = $"($dist)/($name)"
$env.KUBECONFIG = $"($dist)/($name)"
}

### common
Expand Down
2 changes: 1 addition & 1 deletion modules/nvim/nvim.nu
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def nvim_tcd [] {
}

export-env {
let-env config = ( $env.config | upsert hooks.env_change.PWD { |config|
$env.config = ( $env.config | upsert hooks.env_change.PWD { |config|
let o = ($config | get -i hooks.env_change.PWD)
let val = (nvim_tcd)
if $o == $nothing {
Expand Down
6 changes: 3 additions & 3 deletions modules/prompt/async_git_prompt/prompt.nu
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def prompt-create-right-prompt [] {
$nothing
}

let-env PROMPT_COMMAND = { prompt-create-left-prompt }
let-env PROMPT_COMMAND_RIGHT = { prompt-create-right-prompt }
let-env PROMPT_INDICATOR = { $" (ansi green_bold)〉" }
$env.PROMPT_COMMAND = { prompt-create-left-prompt }
$env.PROMPT_COMMAND_RIGHT = { prompt-create-right-prompt }
$env.PROMPT_INDICATOR = { $" (ansi green_bold)〉" }
6 changes: 3 additions & 3 deletions modules/prompt/full-line.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#
# to use:
# 1. copy this file to `($nu.default-config-dir | path add 'scripts')` (Or someplace on your $env.NU_LIB_DIRS path, defined in env.nu)
# 2. cut `let-env PROMPT_COMMAND` and `PROMPT_OMMAND_RIGHT' from your env.nu.
# 2. cut `$env.PROMPT_COMMAND` and `PROMPT_OMMAND_RIGHT' from your env.nu.
# These will depend on `use full-line`, which can not be done in env.nu.
# You can leave the `PROMPT-*INDICATOR*` statements in env.nu or
# consolidate all prompt stuff in config.nu.
# 3. Add new prompt setup stuff somewhere in config.nu:
# ```
# use prompt-builder.nu
# let-env PROMPT_COMMAND = {|| prompt-builder }
# let-env PROMPT_COMMAND_RIGHT = ""
# $env.PROMPT_COMMAND = {|| prompt-builder }
# $env.PROMPT_COMMAND_RIGHT = ""
# ```
#
# credit panache-git for the git status widget.
Expand Down
10 changes: 5 additions & 5 deletions modules/prompt/oh-my-minimal.nu
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ export def get_prompt [nerd?] {
#
# in the config.nu you would do something like
# use "c:\some\path\to\nu_scripts\engine-q\prompt\oh-my-minimal.nu" get_prompt
# let-env PROMPT_COMMAND = { (get_prompt).left_prompt }
# let-env PROMPT_COMMAND_RIGHT = { (get_prompt).right_prompt }
# let-env PROMPT_INDICATOR = " "
# $env.PROMPT_COMMAND = { (get_prompt).left_prompt }
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt).right_prompt }
# $env.PROMPT_INDICATOR = " "
# or with nerdfonts
# let-env PROMPT_COMMAND = { (get_prompt 1).left_prompt }
# let-env PROMPT_COMMAND_RIGHT = { (get_prompt 1).right_prompt }
# $env.PROMPT_COMMAND = { (get_prompt 1).left_prompt }
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 1).right_prompt }

}
6 changes: 3 additions & 3 deletions modules/prompt/oh-my-v2-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ The thought would be that at some point this file source read another file for c

In order to use this script you need to source it and then set these.
```
let-env PROMPT_COMMAND = { (get_prompt 8bit).left_prompt }
let-env PROMPT_COMMAND_RIGHT = { (get_prompt 8bit).right_prompt }
let-env PROMPT_INDICATOR = { "" }
$env.PROMPT_COMMAND = { (get_prompt 8bit).left_prompt }
$env.PROMPT_COMMAND_RIGHT = { (get_prompt 8bit).right_prompt }
$env.PROMPT_INDICATOR = { "" }
```

I'd love for someone to take up the torch and work on this script in order to make it better, configurable, awesome.
Expand Down
6 changes: 3 additions & 3 deletions modules/prompt/oh-my.nu
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export def git_prompt [] {
#
# in the config.nu you would do something like
# use "c:\some\path\to\nu_scripts\prompt\oh-my.nu" git_prompt
# let-env PROMPT_COMMAND = { (git_prompt).left_prompt }
# let-env PROMPT_COMMAND_RIGHT = { (git_prompt).right_prompt }
# let-env PROMPT_INDICATOR = " "
# $env.PROMPT_COMMAND = { (git_prompt).left_prompt }
# $env.PROMPT_COMMAND_RIGHT = { (git_prompt).right_prompt }
# $env.PROMPT_INDICATOR = " "
}
4 changes: 2 additions & 2 deletions modules/prompt/panache-git.nu
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# - Disable the separate prompt indicator by setting it to an empty string
# - For example, with this file in your home directory:
# use ~/panache-git.nu panache-git
# let-env PROMPT_COMMAND = { panache-git }
# let-env PROMPT_INDICATOR = { "" }
# $env.PROMPT_COMMAND = { panache-git }
# $env.PROMPT_INDICATOR = { "" }
# - Restart Nushell
#
# For more documentation or to file an issue, see https://github.com/ehdevries/panache-git
Expand Down
12 changes: 6 additions & 6 deletions modules/prompt/powerline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ power init
```
or
```
let-env NU_POWER_SCHEMA = [
$env.NU_POWER_SCHEMA = [
[
{source: pwd, color: '#353230'}
{source: git, color: '#504945'}
Expand All @@ -38,19 +38,19 @@ power init
`$env.NU_POWER_SCHEMA` support configuring dynamically

## mode
- `let-env NU_POWER_MODE = '<power|fast>'` fast mode and default mode (experimental)
- `let-env NU_POWER_DECORATOR = '<power|plain>'` power mode and plain mode
- `let-env NU_POWER_FRAME = '<default|fill>'` two line prompt (experimental)
- `$env.NU_POWER_MODE = '<power|fast>'` fast mode and default mode (experimental)
- `$env.NU_POWER_DECORATOR = '<power|plain>'` power mode and plain mode
- `$env.NU_POWER_FRAME = '<default|fill>'` two line prompt (experimental)

### benchmark
```
let-env NU_POWER_BENCHMARK = true
$env.NU_POWER_BENCHMARK = true
```
Then execute a few commands casually, such as pressing the Enter key continuously.
then execute

```
let-env NU_POWER_MODE = 'fast' # or 'power'
$env.NU_POWER_MODE = 'fast' # or 'power'
```

Go ahead and press enter,
Expand Down
Loading

0 comments on commit a61256d

Please sign in to comment.