diff --git a/hm/modules/common/shellenv/config.nu b/hm/modules/common/shellenv/config.nu new file mode 100644 index 0000000..e102380 --- /dev/null +++ b/hm/modules/common/shellenv/config.nu @@ -0,0 +1,32 @@ +let fish_completer = {|spans| + fish --command $'complete "--do-complete=($spans | str join " ")"' + | from tsv --flexible --noheaders --no-infer + | rename value description +} + +let zoxide_completer = {|spans| + $spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD} +} + +# This completer will use fish by default +let external_completer = {|spans| + let expanded_alias = scope aliases + | where name == $spans.0 + | get -i 0.expansion + + let spans = if $expanded_alias != null { + $spans + | skip 1 + | prepend ($expanded_alias | split row ' ' | take 1) + } else { + $spans + } + + match $spans.0 { + # use zoxide completions for zoxide commands + __zoxide_z | __zoxide_zi => $zoxide_completer + _ => $fish_completer + } | do $in $spans +} + +$env.config.completions.external.completer = $external_completer diff --git a/hm/modules/common/shellenv/default.nix b/hm/modules/common/shellenv/default.nix index fa050e5..25376b8 100644 --- a/hm/modules/common/shellenv/default.nix +++ b/hm/modules/common/shellenv/default.nix @@ -29,12 +29,20 @@ in programs.nushell = { enable = true; - configFile.text = '' - $env.config = { - edit_mode: vi, - show_banner: false - } - ''; + configFile.source = ./config.nu; + settings = { + show_banner = false; + completions.external = { + enable = true; + max_results = 200; + }; + edit_mode = "vi"; + cursor_shape = { + emacs = "line"; + vi_insert = "line"; + vi_normal = "block"; + }; + }; }; programs.fzf = { @@ -78,7 +86,8 @@ in programs.zoxide = { enable = true; - enableFishIntegration = true; + # we have our own fish completion plugin for zoxide + enableFishIntegration = false; enableNushellIntegration = true; enableBashIntegration = true; }; @@ -112,44 +121,36 @@ in fish_vi_key_bindings set -g fish_greeting ''; - plugins = [ - { - name = "autopair"; - src = pkgs.fetchFromGitHub { - owner = "jorgebucaran"; - repo = "autopair.fish"; - rev = "4d1752ff5b39819ab58d7337c69220342e9de0e2"; - hash = "sha256-qt3t1iKRRNuiLWiVoiAYOu+9E7jsyECyIqZJ/oRIT1A="; - }; - } - { - name = "fzf"; - src = pkgs.fetchFromGitHub { - owner = "PatrickF1"; - repo = "fzf.fish"; - rev = "8920367cf85eee5218cc25a11e209d46e2591e7a"; - hash = "sha256-T8KYLA/r/gOKvAivKRoeqIwE2pINlxFQtZJHpOy9GMM="; - }; - } - { - name = "sponge"; - src = pkgs.fetchFromGitHub { - owner = "meaningful-ooo"; - repo = "sponge"; - rev = "384299545104d5256648cee9d8b117aaa9a6d7be"; - hash = "sha256-MdcZUDRtNJdiyo2l9o5ma7nAX84xEJbGFhAVhK+Zm1w="; - }; - } - { - name = "done"; - src = pkgs.fetchFromGitHub { - owner = "franciscolourenco"; - repo = "done"; - rev = "eb32ade85c0f2c68cbfcff3036756bbf27a4f366"; - hash = "sha256-DMIRKRAVOn7YEnuAtz4hIxrU93ULxNoQhW6juxCoh4o="; - }; - } - ]; + plugins = + [ + { + name = "autopair"; + src = pkgs.fishPlugins.autopair.src; + } + { + name = "fzf"; + src = pkgs.fishPlugins.fzf.src; + } + { + name = "done"; + src = pkgs.fishPlugins.done.src; + } + { + name = "sponge"; + src = pkgs.fishPlugins.sponge.src; + } + ] + ++ lib.optionals config.programs.zoxide.enable [ + { + name = "zoxide.fish"; + src = pkgs.fetchFromGitHub { + owner = "icezyclon"; + repo = "zoxide.fish"; + rev = "a6dabb16dd2de570a2005617ea4510f0beb6dc53"; + hash = "sha256-aGajwgFdB+wtjyryD/EQXSQ3SCFKwDJFjaZjLiJHt3E="; + }; + } + ]; }; programs.nix-index = { @@ -174,6 +175,7 @@ in enable = true; enableFishIntegration = true; enableBashIntegration = true; + enableNushellIntegration = false; git = true; }; diff --git a/reference/users/youwen/nixos.nix b/reference/users/youwen/nixos.nix index 1da37bd..7ccc49b 100644 --- a/reference/users/youwen/nixos.nix +++ b/reference/users/youwen/nixos.nix @@ -7,7 +7,7 @@ "networkmanager" "wheel" ]; - shell = pkgs.fish; + shell = pkgs.nushell; initialHashedPassword = "$y$j9T$v0OkEeCntj8KwgPJQxyWx0$dx8WtFDYgZZ8WE3FWetWwRfutjQkznRuJ0IG3LLAtP2"; }; }