fix nnn with nushell

This commit is contained in:
2025-09-29 11:41:50 +02:00
parent 643c6ec8ba
commit 14b17d5d0b
3 changed files with 61 additions and 18 deletions

View File

@@ -112,6 +112,7 @@ in
".config/jj".source = home/config/jj; ".config/jj".source = home/config/jj;
".icons/default".source = "${pkgs.vanilla-dmz}/share/icons/Vanilla-DMZ"; ".icons/default".source = "${pkgs.vanilla-dmz}/share/icons/Vanilla-DMZ";
".config/nushell/themes".source = home/config/nushell/themes; ".config/nushell/themes".source = home/config/nushell/themes;
".config/nushell/quitcd".source = home/config/nushell/quitcd;
}; };
home.sessionVariables = { home.sessionVariables = {

View File

@@ -1,21 +1,21 @@
# # config.nu # config.nu
# # #
# # Installed by: # Installed by:
# # version = "0.106.1" # version = "0.106.1"
# # #
# # This file is used to override default Nushell settings, define # This file is used to override default Nushell settings, define
# # (or import) custom commands, or run any other startup tasks. # (or import) custom commands, or run any other startup tasks.
# # See https://www.nushell.sh/book/configuration.html # See https://www.nushell.sh/book/configuration.html
# # #
# # Nushell sets "sensible defaults" for most configuration settings, # Nushell sets "sensible defaults" for most configuration settings,
# # so your `config.nu` only needs to override these defaults if desired. # so your `config.nu` only needs to override these defaults if desired.
# # #
# # You can open this file in your default editor using: # You can open this file in your default editor using:
# # config nu # config nu
# # #
# # You can also pretty-print and page through the documentation for configuration # You can also pretty-print and page through the documentation for configuration
# # options using: # options using:
# # config nu --doc | nu-highlight | less -R # config nu --doc | nu-highlight | less -R
### ###
@@ -108,3 +108,6 @@ $env.PATH = ($env.PATH |
source ./themes/dracula.nu source ./themes/dracula.nu
source ./quitcd/quitcd.nu
$env.NNN_TMPFILE = $"($env.HOME)/.config/nnn/.lastd"
$env.EDITOR = "nvim"

View File

@@ -0,0 +1,39 @@
# Run nnn with dynamic changing directory to the environment.
#
# $env.XDG_CONFIG_HOME sets the home folder for `nnn` folder and its $env.NNN_TMPFILE variable.
# See manual NNN(1) for more information.
#
# Import module using `use quitcd.nu n` to have `n` command in your context.
export def --env n [
...args : string # Extra flags to launch nnn with.
--selective = false # Change directory only when exiting via ^G.
]: nothing -> nothing {
# The behaviour is set to cd on quit (nnn checks if $env.NNN_TMPFILE is set).
# Hard-coded to its respective behaviour in `nnn` source-code.
let nnn_tmpfile = $env
| default '~/.config/' 'XDG_CONFIG_HOME'
| get 'XDG_CONFIG_HOME'
| path join 'nnn/.lastd'
| path expand
# Launch nnn. Add desired flags after `^nnn`, ex: `^nnn -eda ...$args`,
# or make an alias `alias n = n -eda`.
if $selective {
^nnn -e ...$args
} else {
NNN_TMPFILE=$nnn_tmpfile ^nnn -e ...$args
}
if ($nnn_tmpfile | path exists) {
# Remove <cd '> from the first part of the string and the last single quote <'>.
# Fix post-processing of nnn's given path that escapes its single quotes with POSIX syntax.
let path = open $nnn_tmpfile
| str replace --all --regex `^cd '|'$` ``
| str replace --all `'\''` `'`
^rm -- $nnn_tmpfile
cd $path
}
}