mirror of
https://github.com/fredrikr79/nixos.git
synced 2025-12-19 16:00:41 +01:00
fix nnn with nushell
This commit is contained in:
1
home.nix
1
home.nix
@@ -112,6 +112,7 @@ in
|
||||
".config/jj".source = home/config/jj;
|
||||
".icons/default".source = "${pkgs.vanilla-dmz}/share/icons/Vanilla-DMZ";
|
||||
".config/nushell/themes".source = home/config/nushell/themes;
|
||||
".config/nushell/quitcd".source = home/config/nushell/quitcd;
|
||||
};
|
||||
|
||||
home.sessionVariables = {
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
# # config.nu
|
||||
# #
|
||||
# # Installed by:
|
||||
# # version = "0.106.1"
|
||||
# #
|
||||
# # This file is used to override default Nushell settings, define
|
||||
# # (or import) custom commands, or run any other startup tasks.
|
||||
# # See https://www.nushell.sh/book/configuration.html
|
||||
# #
|
||||
# # Nushell sets "sensible defaults" for most configuration settings,
|
||||
# # so your `config.nu` only needs to override these defaults if desired.
|
||||
# #
|
||||
# # You can open this file in your default editor using:
|
||||
# # config nu
|
||||
# #
|
||||
# # You can also pretty-print and page through the documentation for configuration
|
||||
# # options using:
|
||||
# # config nu --doc | nu-highlight | less -R
|
||||
# config.nu
|
||||
#
|
||||
# Installed by:
|
||||
# version = "0.106.1"
|
||||
#
|
||||
# This file is used to override default Nushell settings, define
|
||||
# (or import) custom commands, or run any other startup tasks.
|
||||
# See https://www.nushell.sh/book/configuration.html
|
||||
#
|
||||
# Nushell sets "sensible defaults" for most configuration settings,
|
||||
# so your `config.nu` only needs to override these defaults if desired.
|
||||
#
|
||||
# You can open this file in your default editor using:
|
||||
# config nu
|
||||
#
|
||||
# You can also pretty-print and page through the documentation for configuration
|
||||
# options using:
|
||||
# config nu --doc | nu-highlight | less -R
|
||||
|
||||
|
||||
###
|
||||
@@ -108,3 +108,6 @@ $env.PATH = ($env.PATH |
|
||||
|
||||
source ./themes/dracula.nu
|
||||
|
||||
source ./quitcd/quitcd.nu
|
||||
$env.NNN_TMPFILE = $"($env.HOME)/.config/nnn/.lastd"
|
||||
$env.EDITOR = "nvim"
|
||||
|
||||
39
home/config/nushell/quitcd/quitcd.nu
Normal file
39
home/config/nushell/quitcd/quitcd.nu
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user