nushell: Generate starship and zoxide config from nix
This commit is contained in:
parent
80987fc79b
commit
22aedb8824
3 changed files with 5 additions and 91 deletions
|
@ -1,7 +1,9 @@
|
|||
{ config, lib, ... }:
|
||||
{ pkgs, config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.eboskma.programs.nushell;
|
||||
starship-nu = pkgs.runCommand "starship-nu" { } ''${pkgs.starship}/bin/starship init nu > $out'';
|
||||
zoxide-nu = pkgs.runCommand "zoxide-nu" { } ''${pkgs.zoxide}/bin/zoxide init nushell > $out'';
|
||||
in
|
||||
{
|
||||
options.eboskma.programs.nushell = { enable = mkEnableOption "nu shell"; };
|
||||
|
@ -13,8 +15,8 @@ in
|
|||
envFile.source = ./env.nu;
|
||||
|
||||
extraConfig = ''
|
||||
source ${./starship.nu}
|
||||
source ${./zoxide.nu}
|
||||
source ${starship-nu}
|
||||
source ${zoxide-nu}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
let-env STARSHIP_SHELL = "nu"
|
||||
let-env STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
let-env PROMPT_MULTILINE_INDICATOR = (^/etc/profiles/per-user/erwin/bin/starship prompt --continuation)
|
||||
|
||||
# Does not play well with default character module.
|
||||
# TODO: Also Use starship vi mode indicators?
|
||||
let-env PROMPT_INDICATOR = ""
|
||||
|
||||
let-env PROMPT_COMMAND = {
|
||||
# jobs are not supported
|
||||
let width = (term size).columns
|
||||
^/etc/profiles/per-user/erwin/bin/starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
}
|
||||
|
||||
# Whether we have config items
|
||||
let has_config_items = (not ($env | get -i config | is-empty))
|
||||
|
||||
let-env config = if $has_config_items {
|
||||
$env.config | upsert render_right_prompt_on_last_line true
|
||||
} else {
|
||||
{render_right_prompt_on_last_line: true}
|
||||
}
|
||||
|
||||
let-env PROMPT_COMMAND_RIGHT = {
|
||||
let width = (term size).columns
|
||||
^/etc/profiles/per-user/erwin/bin/starship prompt --right $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
# Code generated by zoxide. DO NOT EDIT.
|
||||
|
||||
# =============================================================================
|
||||
#
|
||||
# Hook configuration for zoxide.
|
||||
#
|
||||
|
||||
# Initialize hook to add new entries to the database.
|
||||
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
||||
let-env __zoxide_hooked = true
|
||||
let-env config = ($env | default {} config).config
|
||||
let-env config = ($env.config | default {} hooks)
|
||||
let-env config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
||||
let-env config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
||||
let-env config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
|
||||
zoxide add -- $dir
|
||||
}))
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
#
|
||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||
#
|
||||
|
||||
# Jump to a directory using only keywords.
|
||||
def-env __zoxide_z [...rest:string] {
|
||||
# `z -` does not work yet, see https://github.com/nushell/nushell/issues/4769
|
||||
let arg0 = ($rest | append '~').0
|
||||
let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
|
||||
$arg0
|
||||
} else {
|
||||
(zoxide query --exclude $env.PWD -- $rest | str trim -r -c "\n")
|
||||
}
|
||||
cd $path
|
||||
}
|
||||
|
||||
# Jump to a directory using interactive search.
|
||||
def-env __zoxide_zi [...rest:string] {
|
||||
cd $'(zoxide query -i -- $rest | str trim -r -c "\n")'
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
#
|
||||
# Commands for zoxide. Disable these using --no-cmd.
|
||||
#
|
||||
|
||||
alias z = __zoxide_z
|
||||
alias zi = __zoxide_zi
|
||||
|
||||
# =============================================================================
|
||||
#
|
||||
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
|
||||
#
|
||||
# zoxide init nushell | save -f ~/.zoxide.nu
|
||||
#
|
||||
# Now, add this to the end of your config file (find it by running
|
||||
# `$nu.config-path` in Nushell):
|
||||
#
|
||||
# source ~/.zoxide.nu
|
||||
#
|
||||
# Note: zoxide only supports Nushell v0.73.0 and above.
|
Loading…
Reference in a new issue