forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvim.nu
More file actions
147 lines (130 loc) · 3.61 KB
/
nvim.nu
File metadata and controls
147 lines (130 loc) · 3.61 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
## neovim configurations
# local vcs_root = require('lspconfig.util').root_pattern('.git/')
# function HookPwdChanged(after, before)
# vim.b.pwd = after
# local git_dir = vcs_root(after)
# vim.api.nvim_command('silent tcd! '..(git_dir or after))
# end
# function OppositePwd()
# local tab = vim.api.nvim_get_current_tabpage()
# local wins = vim.api.nvim_tabpage_list_wins(tab)
# local cwin = vim.api.nvim_tabpage_get_win(tab)
# for _, w in ipairs(wins) do
# if cwin ~= w then
# local b = vim.api.nvim_win_get_buf(w)
# local pwd = vim.b[b].pwd
# if pwd then return pwd end
# end
# end
# end
# function ReadTempDrop(path, action)
# vim.api.nvim_command(action or 'botright vnew')
# local win = vim.api.nvim_get_current_win()
# local buf = vim.api.nvim_create_buf(true, true)
# vim.api.nvim_win_set_buf(win, buf)
# vim.api.nvim_command('read '..path)
# vim.fn.delete(path)
# end
def nvim_tcd [] {
[
{|before, after|
if not ($env.NVIM? | is-empty) {
nvim --headless --noplugin --server $env.NVIM --remote-send $"<cmd>lua HookPwdChanged\('($after)', '($before)')<cr>"
}
}
]
}
export-env {
$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 == null {
$val
} else {
$o | append $val
}
})
}
def edit [action file] {
if ($env.NVIM? | is-empty) {
nvim $file
} else {
let af = ($file | each {|f|
if ($f|str substring ..1) in ['/', '~'] {
$f
} else {
$"($env.PWD)/($f)"
}
})
let cmd = $"<cmd>($action) ($af|str join ' ')<cr>"
nvim --headless --noplugin --server $env.NVIM --remote-send $cmd
}
}
# nvim tcd
export def tcd [path?: string] {
let after = if ($path | is-empty) {
$env.PWD
} else {
$path
}
nvim --headless --noplugin --server $env.NVIM --remote-send $"<cmd>lua HookPwdChanged\('($after)', '($env.PWD)')<cr>"
}
export def e [...file: string] {
if ($file|is-empty) {
nvim
} else {
edit vsplit $file
}
}
export def c [...file: string] {
if ($file|is-empty) {
nvim
} else {
edit split $file
}
}
export def v [...file: string] {
if ($file|is-empty) {
nvim
} else {
edit vsplit $file
}
}
export def x [...file: string] {
if ($file|is-empty) {
nvim
} else {
edit tabnew $file
}
}
# drop stdout to nvim buf
export def drop [] {
if ($env.NVIM? | is-empty) {
echo $in
} else {
let c = $in
let temp = (mktemp -t nuvim.XXXXXXXX|str trim)
$c | save -f $temp
nvim --headless --noplugin --server $env.NVIM --remote-send $"<cmd>lua ReadTempDrop\('($temp)')<cr>"
}
}
export def nvim-lua [...expr: string] {
if ($env.NVIM? | is-empty) {
echo "not found nvim instance"
} else {
nvim --headless --noplugin --server $env.NVIM --remote-send $'<cmd>lua vim.g.remote_expr_lua = ($expr|str join " ")<cr>'
do -i { nvim --headless --noplugin --server $env.NVIM --remote-expr 'g:remote_expr_lua' } | complete | get stderr
}
}
export def opwd [] {
nvim-lua 'OppositePwd()'
}
export def nvim-srv [port: int=9999] {
nvim --headless --listen $"0.0.0.0:($port)"
}
export def nvc [addr: string] {
nvim --remote-ui --server $addr
}
export def nvdc [addr: string] {
neovide --multigrid --maximized --server $addr
}