repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix(nushell): load wezterm integration from modules

beb55af6e551e2f377bbdb5b29eaf271a730d63c

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

nushell/modules/wezterm_integration.nu

Added
new file mode 100644
1 +# WezTerm Shell Integration for Nushell
2 +# =====================================
3 +# Emits OSC 1337 (user vars) and OSC 7 (cwd) so wezterm can:
4 +# - Track the running command via WEZTERM_PROG
5 +# - Know the current working directory (new tabs spawn in the right place)
6 +# - Surface arbitrary data from nushell into the wezterm status bar
7 +#
8 +# OSC 133 (prompt zones) is NOT enabled — nushell's implementation
9 +# has known bugs with wezterm (scrolling on keypress).
10 +# See: https://github.com/wezterm/wezterm/discussions/5859
12 +# To install: add `use wezterm_integration.nu` to your config.nu
14 +# ---------------------------------------------------------------------------
15 +# Core: set a user var via OSC 1337
16 +# ---------------------------------------------------------------------------
17 +# Values must be base64-encoded. The BEL (\x07) terminates the sequence.
18 +# Mirrors __wezterm_set_user_var() from the bash/zsh wezterm.sh integration.
19 +export-env {
20 + def __wezterm_set_user_var [name: string, value: string] {
21 + let b64 = ($value | encode base64)
22 + let osc = (ansi --osc $"1337;SetUserVar=($name)=($b64)=")
23 + print -n ($osc + (char bel))
24 + }
26 + # Emit OSC 7 so wezterm knows the current working directory.
27 + # New tabs opened from this pane will use this as their cwd.
28 + def __wezterm_osc7 [] {
29 + let hostname = (hostname)
30 + let cwd = ($env.PWD | str replace --all '\\' '/')
31 + let osc = (ansi --osc $"7;file://($hostname)($cwd)")
32 + print -n ($osc + (char bel))
33 + }
35 + # -------------------------------------------------------------------------
36 + # pre_execution hook: tell wezterm what command is running
37 + # -------------------------------------------------------------------------
38 + # Fires just before each command executes. Sets WEZTERM_PROG so wezterm
39 + # knows what is happening in the pane. Cleared in pre_prompt after completion.
40 + $env.config.hooks.pre_execution = (
41 + $env.config.hooks.pre_execution
42 + | default []
43 + | append {
44 + condition: { true }
45 + code: {
46 + let cmd = (commandline)
47 + __wezterm_set_user_var "WEZTERM_PROG" $cmd
48 + }
49 + }
50 + )
52 + # -------------------------------------------------------------------------
53 + # pre_prompt hook: clean up and update cwd
54 + # -------------------------------------------------------------------------
55 + # Fires after every command completes, before the next prompt is shown.
56 + # Clears WEZTERM_PROG (shell is idle) and emits OSC 7 for the cwd.
57 + $env.config.hooks.pre_prompt = (
58 + $env.config.hooks.pre_prompt
59 + | default []
60 + | append {
61 + condition: { true }
62 + code: {
63 + __wezterm_set_user_var "WEZTERM_PROG" ""
64 + __wezterm_osc7
65 + }
66 + }
67 + )
69 + # -------------------------------------------------------------------------
70 + # env_change.PWD hook: update cwd on cd
71 + # -------------------------------------------------------------------------
72 + # Fires when $PWD changes (e.g. via `cd`, `z`, nushell's block cd).
73 + # Refreshes OSC 7 so wezterm always knows the current directory.
74 + let current_pwd_hooks = ($env.config.hooks.env_change | get --optional PWD | default [])
75 + $env.config.hooks.env_change = ($env.config.hooks.env_change | merge {
76 + PWD: ($current_pwd_hooks | append {
77 + condition: { true }
78 + code: { __wezterm_osc7 }
79 + })
80 + })

nushell/wezterm_integration.nu

Deleted
deleted file mode 100644
1 -# WezTerm Shell Integration for Nushell
2 -# =====================================
3 -# Emits OSC 1337 (user vars) and OSC 7 (cwd) so wezterm can:
4 -# - Track the running command via WEZTERM_PROG
5 -# - Know the current working directory (new tabs spawn in the right place)
6 -# - Surface arbitrary data from nushell into the wezterm status bar
7 -#
8 -# OSC 133 (prompt zones) is NOT enabled — nushell's implementation
9 -# has known bugs with wezterm (scrolling on keypress).
10 -# See: https://github.com/wezterm/wezterm/discussions/5859
11 -#
12 -# To install: add `use wezterm_integration.nu` to your config.nu
14 -# ---------------------------------------------------------------------------
15 -# Core: set a user var via OSC 1337
16 -# ---------------------------------------------------------------------------
17 -# Values must be base64-encoded. The BEL (\x07) terminates the sequence.
18 -# Mirrors __wezterm_set_user_var() from the bash/zsh wezterm.sh integration.
19 -export-env {
20 - def __wezterm_set_user_var [name: string, value: string] {
21 - let b64 = ($value | encode base64)
22 - let osc = (ansi --osc $"1337;SetUserVar=($name)=($b64)=")
23 - print -n ($osc + (char bel))
24 - }
26 - # Emit OSC 7 so wezterm knows the current working directory.
27 - # New tabs opened from this pane will use this as their cwd.
28 - def __wezterm_osc7 [] {
29 - let hostname = (hostname)
30 - let cwd = ($env.PWD | str replace --all '\\' '/')
31 - let osc = (ansi --osc $"7;file://($hostname)($cwd)")
32 - print -n ($osc + (char bel))
33 - }
35 - # -------------------------------------------------------------------------
36 - # pre_execution hook: tell wezterm what command is running
37 - # -------------------------------------------------------------------------
38 - # Fires just before each command executes. Sets WEZTERM_PROG so wezterm
39 - # knows what is happening in the pane. Cleared in pre_prompt after completion.
40 - $env.config.hooks.pre_execution = (
41 - $env.config.hooks.pre_execution
42 - | default []
43 - | append {
44 - condition: { true }
45 - code: {
46 - let cmd = (commandline)
47 - __wezterm_set_user_var "WEZTERM_PROG" $cmd
48 - }
49 - }
50 - )
52 - # -------------------------------------------------------------------------
53 - # pre_prompt hook: clean up and update cwd
54 - # -------------------------------------------------------------------------
55 - # Fires after every command completes, before the next prompt is shown.
56 - # Clears WEZTERM_PROG (shell is idle) and emits OSC 7 for the cwd.
57 - $env.config.hooks.pre_prompt = (
58 - $env.config.hooks.pre_prompt
59 - | default []
60 - | append {
61 - condition: { true }
62 - code: {
63 - __wezterm_set_user_var "WEZTERM_PROG" ""
64 - __wezterm_osc7
65 - }
66 - }
67 - )
69 - # -------------------------------------------------------------------------
70 - # env_change.PWD hook: update cwd on cd
71 - # -------------------------------------------------------------------------
72 - # Fires when $PWD changes (e.g. via `cd`, `z`, nushell's block cd).
73 - # Refreshes OSC 7 so wezterm always knows the current directory.
74 - let current_pwd_hooks = ($env.config.hooks.env_change | get --optional PWD | default [])
75 - $env.config.hooks.env_change = ($env.config.hooks.env_change | merge {
76 - PWD: ($current_pwd_hooks | append {
77 - condition: { true }
78 - code: { __wezterm_osc7 }
79 - })
80 - })
81 -}