-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux-wrapper.nu
executable file
·53 lines (45 loc) · 1.03 KB
/
tmux-wrapper.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env nu
# NOTE: currently rest parameter does not work like zsh `$@`
def --wrapped wrapper [...args] {
let bin = '/opt/homebrew/bin/tmux'
mut server = if 'KITTY_WINDOW_ID' in $env {
'kitty'
} else if 'ALACRITTY_WINDOW_ID' in $env {
'alacritty'
} else if 'WEZTERM_PANE' in $env {
'wezterm'
} else if $env.TERM_PROGRAM? == 'vscode' {
'vscode'
} else if 'ITERM_SESSION_ID' in $env {
'iterm'
} else {
'default'
}
if $env.NVIM? != null { $server += '-nvim-term' }
if ($args | is-not-empty) {
if $args.0 == 'which-server' {
return $server
} else {
exec $bin -L $server ...($args)
}
} else {
exec $bin -L $server attach
}
}
def --wrapped main [...args] {
wrapper ...($args)
# test_wrapper
}
use std assert
#[test]
def test_inside_nvim [] {
$env.NVIM = foo
let r = (wrapper which-server)
assert ($r ends-with '-nvim-term')
}
#[test]
def test_outside_nvim [] {
$env.NVIM = null
let r = (wrapper which-server)
assert not ($r ends-with '-nvim-term')
}