nix machine / user configurations

feat(wolumonde): use nushell

ptr.pet 7b8f5393 6384f20d

verified
Changed files
+147
hosts
wolumonde
modules
modules
+1
hosts/wolumonde/modules/nushell.nix
···
+
../../../modules/nushell/default.nix
+20
modules/nushell/aliases.nu
···
+
alias l = ls
+
alias ll = ls -l
+
alias la = ls -a
+
+
alias cat = bat
+
alias c = bat
+
+
alias g = git
+
alias gs = git status
+
alias ga = git add
+
+
alias n = nix
+
alias nfu = nix flake update
+
alias nfs = nix flake show
+
alias nb = nix build
+
alias nd = nix develop
+
alias ns = nix shell
+
+
def mem [] { sys mem }
+
def df [] { sys disks }
+82
modules/nushell/default.nix
···
+
{ lib, pkgs, ... }:
+
{
+
environment.shells = [pkgs.nushell];
+
users.users.root.shell = pkgs.nushell;
+
+
home-manager.users.root = {
+
programs.nushell = {
+
enable = true;
+
package = pkgs.nushell;
+
shellAliases = {
+
myip = lib.mkForce "echo";
+
};
+
extraEnv = ''
+
source-env ${./prompt.nu}
+
'';
+
extraConfig = ''
+
let carapace_completer = {|spans: list<string>|
+
carapace $spans.0 nushell ...$spans
+
| from json
+
| if ($in | default [] | where value == $"($spans | last)ERR" | is-empty) { $in } else { null }
+
}
+
$env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense'
+
+
let fish_completer = {|spans|
+
${lib.getExe pkgs.fish} --command $'complete "--do-complete=($spans | str join " ")"'
+
| $"value(char tab)description(char newline)" + $in
+
| from tsv --flexible --no-infer
+
}
+
+
let zoxide_completer = {|spans|
+
$spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD}
+
}
+
+
let multiple_completers = {|spans|
+
## alias fixer start https://www.nushell.sh/cookbook/external_completers.html#alias-completions
+
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
+
}
+
## alias fixer end
+
+
match $spans.0 {
+
__zoxide_z | __zoxide_zi => $zoxide_completer
+
_ => $carapace_completer
+
} | do $in $spans
+
}
+
+
$env.config = {
+
show_banner: false,
+
completions: {
+
case_sensitive: false # case-sensitive completions
+
quick: true # set to false to prevent auto-selecting completions
+
partial: true # set to false to prevent partial filling of the prompt
+
algorithm: "fuzzy" # prefix or fuzzy
+
external: {
+
# set to false to prevent nushell looking into $env.PATH to find more suggestions
+
enable: true
+
# set to lower can improve completion performance at the cost of omitting some options
+
max_results: 100
+
completer: $multiple_completers
+
}
+
}
+
}
+
$env.PATH = ($env.PATH |
+
split row (char esep) |
+
append /usr/bin/env
+
)
+
+
source ${./aliases.nu}
+
'';
+
};
+
programs.carapace.enable = true;
+
programs.carapace.enableNushellIntegration = true;
+
};
+
}
+44
modules/nushell/prompt.nu
···
+
let host_colors = {
+
higashi: {start: "0xEC5228", end: "0xEF9651"},
+
wolumonde: {start: "0x603F26", end: "0x6C4E31"},
+
}
+
let user_colors = {
+
kirara: {start: "0xFF407D", end: "0xEE99C2"},
+
root: {start: "0xC5172E", end: "0xBF3131"},
+
}
+
+
def create_left_prompt [] {
+
let hostname = sys host | get hostname
+
let username = ^whoami
+
+
let c = $host_colors | get $hostname
+
let hostname_fmt = $hostname | ansi gradient --fgstart $c.start --fgend $c.end
+
let c = $user_colors | get $username
+
let username_fmt = $username | ansi gradient --fgstart $c.start --fgend $c.end
+
+
let dir = match (do -i { $env.PWD | path relative-to $nu.home-path }) {
+
null => $env.PWD
+
'' => '~'
+
$relative_pwd => ([~ $relative_pwd] | path join)
+
}
+
+
let separator_color = ansi light_cyan
+
let string_color = ansi light_yellow
+
$"($separator_color)//($hostname_fmt)($separator_color)/($username_fmt)($separator_color)/($string_color)cwd=\"($dir)\""
+
}
+
+
def create_right_prompt [] {
+
()
+
}
+
+
# Use nushell functions to define your right and left prompt
+
$env.PROMPT_COMMAND = {|| create_left_prompt }
+
# FIXME: This default is not implemented in rust code as of 2023-09-08.
+
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
+
+
# The prompt indicators are environmental variables that represent
+
# the state of the prompt
+
$env.PROMPT_INDICATOR = {|| "/ " }
+
$env.PROMPT_INDICATOR_VI_INSERT = {|| "/: " }
+
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "/ " }
+
$env.PROMPT_MULTILINE_INDICATOR = {|| "/::: " }