1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

refactor: (#418)

* refactor:  move in one commit

Eveything in modules should probably be changed to `exported` defs.
The idea is to move everything first to keep proper history.

* refactor: 📝 add modules readme (wip)

* refactor:  small move

* refactor: 📝 changed nestring, updated modules readme

* refactor: 📝 to document or not to document

* fix: 🐛 themes

replaced the template to use `main` and regenerated them
from lemnos themes.

* Revert "fix: 🐛 themes"

This reverts commit 4918d3633c8d2d81950a0ed0cfd9eb84241bc886.

* refactor:  introduce sourced

- Created a source `root` in which sourcable demos are stored.
  Some might get converted to modules later on.
- Moved some files to bin too.

* fix: 🐛 fehbg.nu

* fix: 🐛 modules/after.nu

* moved some other stuff around

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
Mel Massadian 2023-04-26 00:56:25 +02:00 committed by GitHub
parent 382696cd21
commit c47ccd42b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 185 additions and 12 deletions

143
modules/nvim/nvim.nu Normal file
View file

@ -0,0 +1,143 @@
## 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 {
let-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 {
$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=1111] {
nvim --headless --listen $"0.0.0.0:($port)"
}
export def nvide-conn [addr: string] {
neovide --multigrid --maximized --remote-tcp addr
}