From d177037ed289ed61f882fa2afdb0e34e7eabae33 Mon Sep 17 00:00:00 2001 From: fj0r <82698591+fj0r@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:42:14 +0800 Subject: [PATCH] merge nvdc into nvc (#764) use a unified nvc to start the neovim client, and then have a flag --gui to start the neovim gui program. And collect some common GUI startup methods, detect which one exists and start which one. --------- Co-authored-by: nash --- modules/nvim/nvim.nu | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/modules/nvim/nvim.nu b/modules/nvim/nvim.nu index abba85ef..5d0cd445 100644 --- a/modules/nvim/nvim.nu +++ b/modules/nvim/nvim.nu @@ -51,17 +51,18 @@ export-env { }) } -def edit [action file] { +def edit [action ...file] { if ($env.NVIM? | is-empty) { - nvim $file + nvim ...$file } else { - let af = ($file | each {|f| + let af = $file + | each {|f| if ($f|str substring ..1) in ['/', '~'] { $f } else { $"($env.PWD)/($f)" } - }) + } let cmd = $"($action) ($af|str join ' ')" nvim --headless --noplugin --server $env.NVIM --remote-send $cmd } @@ -81,7 +82,7 @@ export def e [...file: string] { if ($file|is-empty) { nvim } else { - edit vsplit $file + edit vsplit ...$file } } @@ -89,7 +90,7 @@ export def c [...file: string] { if ($file|is-empty) { nvim } else { - edit split $file + edit split ...$file } } @@ -97,7 +98,7 @@ export def v [...file: string] { if ($file|is-empty) { nvim } else { - edit vsplit $file + edit vsplit ...$file } } @@ -105,7 +106,7 @@ export def x [...file: string] { if ($file|is-empty) { nvim } else { - edit tabnew $file + edit tabnew ...$file } } @@ -134,14 +135,25 @@ export def opwd [] { nvim-lua 'OppositePwd()' } -export def nvim-srv [port: int=9999] { +export def nvs [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 --maximized --server $addr +export def nvc [ + addr: string + --gui(-g) +] { + if $gui { + let gs = { + neovide: [--maximized --server $addr] + } + for g in ($gs | transpose prog args) { + if not (which $g.prog | is-empty) { + ^$g.prog ...$g.args + break + } + } + } else { + nvim --remote-ui --server $addr + } }