From 22aedb88241a8b2d1b12f8f52b90a9d020a36079 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Mon, 3 Apr 2023 09:49:01 +0200 Subject: [PATCH] nushell: Generate starship and zoxide config from nix --- home-manager/modules/nushell/default.nix | 8 ++-- home-manager/modules/nushell/starship.nu | 27 ----------- home-manager/modules/nushell/zoxide.nu | 61 ------------------------ 3 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644 home-manager/modules/nushell/starship.nu delete mode 100644 home-manager/modules/nushell/zoxide.nu diff --git a/home-manager/modules/nushell/default.nix b/home-manager/modules/nushell/default.nix index c009b25..dcbdd53 100644 --- a/home-manager/modules/nushell/default.nix +++ b/home-manager/modules/nushell/default.nix @@ -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} ''; }; }; diff --git a/home-manager/modules/nushell/starship.nu b/home-manager/modules/nushell/starship.nu deleted file mode 100644 index a33effd..0000000 --- a/home-manager/modules/nushell/starship.nu +++ /dev/null @@ -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)" -} diff --git a/home-manager/modules/nushell/zoxide.nu b/home-manager/modules/nushell/zoxide.nu deleted file mode 100644 index 35d06b1..0000000 --- a/home-manager/modules/nushell/zoxide.nu +++ /dev/null @@ -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.