nushell: move to modules/home
Signed-off-by: Bloxx12 <charlie@charlieroot.dev> Change-Id: I6a6a6964b332aee4de78ddbba4d16b55f6783485
This commit is contained in:
parent
71505a4629
commit
8c3ff343b0
10 changed files with 183 additions and 128 deletions
1
modules/home/nushell/completions.nu
Normal file
1
modules/home/nushell/completions.nu
Normal file
|
@ -0,0 +1 @@
|
|||
|
300
modules/home/nushell/config.nu
Normal file
300
modules/home/nushell/config.nu
Normal file
|
@ -0,0 +1,300 @@
|
|||
#! /usr/bin/env nu
|
||||
|
||||
$env.config = {
|
||||
bracketed_paste: true
|
||||
buffer_editor: "hx"
|
||||
datetime_format: {}
|
||||
edit_mode: vi
|
||||
error_style: fancy
|
||||
float_precision: 2
|
||||
footer_mode: 25
|
||||
render_right_prompt_on_last_line: false
|
||||
show_banner: false
|
||||
use_ansi_coloring: true
|
||||
use_kitty_protocol: true
|
||||
|
||||
shell_integration: {
|
||||
osc2: false
|
||||
osc7: true
|
||||
osc8: true
|
||||
osc9_9: false
|
||||
osc133: true
|
||||
osc633: true
|
||||
reset_application_mode: true
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.color_config = {
|
||||
binary: '#b48ead'
|
||||
block: '#81a1c1'
|
||||
cell-path: '#e5e9f0'
|
||||
closure: '#88c0d0'
|
||||
custom: '#8fbcbb'
|
||||
duration: '#ebcb8b'
|
||||
float: '#bf616a'
|
||||
glob: '#8fbcbb'
|
||||
int: '#b48ead'
|
||||
list: '#88c0d0'
|
||||
nothing: '#bf616a'
|
||||
range: '#ebcb8b'
|
||||
record: '#88c0d0'
|
||||
string: '#a3be8c'
|
||||
|
||||
bool: {|| if $in { '#88c0d0' } else { '#ebcb8b' } }
|
||||
|
||||
datetime: {|| (date now) - $in |
|
||||
if $in < 1hr {
|
||||
{ fg: '#bf616a' attr: 'b' }
|
||||
} else if $in < 6hr {
|
||||
'#bf616a'
|
||||
} else if $in < 1day {
|
||||
'#ebcb8b'
|
||||
} else if $in < 3day {
|
||||
'#a3be8c'
|
||||
} else if $in < 1wk {
|
||||
{ fg: '#a3be8c' attr: 'b' }
|
||||
} else if $in < 6wk {
|
||||
'#88c0d0'
|
||||
} else if $in < 52wk {
|
||||
'#81a1c1'
|
||||
} else { 'dark_gray' }
|
||||
}
|
||||
|
||||
filesize: {|e|
|
||||
if $e == 0b {
|
||||
'#e5e9f0'
|
||||
} else if $e < 1mb {
|
||||
'#88c0d0'
|
||||
} else {{ fg: '#81a1c1' }}
|
||||
}
|
||||
|
||||
shape_and: { fg: '#b48ead' attr: 'b' }
|
||||
shape_binary: { fg: '#b48ead' attr: 'b' }
|
||||
shape_block: { fg: '#81a1c1' attr: 'b' }
|
||||
shape_bool: '#88c0d0'
|
||||
shape_closure: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_custom: '#a3be8c'
|
||||
shape_datetime: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_directory: '#88c0d0'
|
||||
shape_external: '#88c0d0'
|
||||
shape_external_resolved: '#88c0d0'
|
||||
shape_externalarg: { fg: '#a3be8c' attr: 'b' }
|
||||
shape_filepath: '#88c0d0'
|
||||
shape_flag: { fg: '#81a1c1' attr: 'b' }
|
||||
shape_float: { fg: '#bf616a' attr: 'b' }
|
||||
shape_garbage: { fg: '#FFFFFF' bg: '#FF0000' attr: 'b' }
|
||||
shape_glob_interpolation: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_globpattern: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_int: { fg: '#b48ead' attr: 'b' }
|
||||
shape_internalcall: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_keyword: { fg: '#b48ead' attr: 'b' }
|
||||
shape_list: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_literal: '#81a1c1'
|
||||
shape_match_pattern: '#a3be8c'
|
||||
shape_matching_brackets: { attr: 'u' }
|
||||
shape_nothing: '#bf616a'
|
||||
shape_operator: '#ebcb8b'
|
||||
shape_or: { fg: '#b48ead' attr: 'b' }
|
||||
shape_pipe: { fg: '#b48ead' attr: 'b' }
|
||||
shape_range: { fg: '#ebcb8b' attr: 'b' }
|
||||
shape_raw_string: { fg: '#8fbcbb' attr: 'b' }
|
||||
shape_record: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_redirection: { fg: '#b48ead' attr: 'b' }
|
||||
shape_signature: { fg: '#a3be8c' attr: 'b' }
|
||||
shape_string: '#a3be8c'
|
||||
shape_string_interpolation: { fg: '#88c0d0' attr: 'b' }
|
||||
shape_table: { fg: '#81a1c1' attr: 'b' }
|
||||
shape_vardecl: { fg: '#81a1c1' attr: 'u' }
|
||||
shape_variable: '#b48ead'
|
||||
|
||||
foreground: '#e5e9f0'
|
||||
background: '#2e3440'
|
||||
cursor: '#e5e9f0'
|
||||
|
||||
empty: '#81a1c1'
|
||||
header: { fg: '#a3be8c' attr: 'b' }
|
||||
hints: '#4c566a'
|
||||
leading_trailing_space_bg: { attr: 'n' }
|
||||
row_index: { fg: '#a3be8c' attr: 'b' }
|
||||
search_result: { fg: '#bf616a' bg: '#e5e9f0' }
|
||||
separator: '#e5e9f0'
|
||||
}
|
||||
|
||||
$env.config.ls = {
|
||||
clickable_links: true
|
||||
use_ls_colors: true
|
||||
}
|
||||
|
||||
$env.config.rm.always_trash = true
|
||||
|
||||
$env.config.table = {
|
||||
header_on_separator: true
|
||||
footer_inheritance: true
|
||||
index_mode: always
|
||||
mode: compact
|
||||
missing_value_symbol: kek
|
||||
padding: {left: 1 right: 1}
|
||||
show_empty: false
|
||||
trim: {
|
||||
methodology: wrapping
|
||||
truncating_suffix: "..."
|
||||
wrapping_try_keep_words: true
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.explore = {
|
||||
command_bar_text: {fg: "#C4C9C6"}
|
||||
highlight: {fg: black bg: yellow}
|
||||
status: {
|
||||
error: {fg: white bg: red}
|
||||
warn: {}
|
||||
info: {}
|
||||
}
|
||||
status_bar_background: {fg: "#1D1F21" bg: "#C4C9C6"}
|
||||
table: {
|
||||
split_line: {fg: "#404040"}
|
||||
selected_cell: {bg: light_blue}
|
||||
selected_row: {}
|
||||
selected_column: {}
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.history = {
|
||||
file_format: sqlite
|
||||
isolation: false
|
||||
max_size: 100_000
|
||||
sync_on_enter: true
|
||||
}
|
||||
|
||||
$env.config.cursor_shape = {
|
||||
vi_insert: line
|
||||
vi_normal: block
|
||||
}
|
||||
|
||||
$env.config.hooks = {
|
||||
command_not_found: {|| }
|
||||
|
||||
pre_execution: [
|
||||
{
|
||||
let prompt = commandline | str trim
|
||||
|
||||
if ($prompt | is-empty) {
|
||||
return
|
||||
}
|
||||
|
||||
print $"(ansi title)($prompt) — nu(char bel)"
|
||||
}
|
||||
]
|
||||
|
||||
env_change: {
|
||||
PWD: [
|
||||
{||
|
||||
if not ($env.PWD | path join .envrc | path exists) {
|
||||
return
|
||||
}
|
||||
if (which direnv | is-empty) {
|
||||
return
|
||||
}
|
||||
|
||||
direnv export json | from json | default {} | load-env
|
||||
$env.PATH = $env.PATH | split row (char env_sep)
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
let menus = [
|
||||
{
|
||||
name: completion_menu
|
||||
only_buffer_difference: false
|
||||
marker: $"(ansi yellow)╋ "
|
||||
type: {
|
||||
layout: ide
|
||||
min_completion_width: 0
|
||||
max_completion_width: 150
|
||||
max_completion_height: 25
|
||||
padding: 0
|
||||
border: false
|
||||
cursor_offset: 0
|
||||
description_mode: "prefer_right"
|
||||
min_description_width: 0
|
||||
max_description_width: 50
|
||||
max_description_height: 10
|
||||
description_offset: 1
|
||||
correct_cursor_pos: true
|
||||
}
|
||||
style: {
|
||||
text: white
|
||||
selected_text: white_reverse
|
||||
description_text: yellow
|
||||
match_text: { attr: u }
|
||||
selected_match_text: { attr: ur }
|
||||
}
|
||||
}
|
||||
{
|
||||
name: history_menu
|
||||
only_buffer_difference: true
|
||||
marker: $env.PROMPT_INDICATOR
|
||||
type: {
|
||||
layout: list
|
||||
page_size: 10
|
||||
}
|
||||
style: {
|
||||
text: white
|
||||
selected_text: white_reverse
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
$env.config.menus = $env.config.menus
|
||||
| where name not-in ($menus | get name)
|
||||
| append $menus
|
||||
|
||||
$env.config.keybindings ++= [
|
||||
{
|
||||
name: copy_commandline
|
||||
modifier: alt
|
||||
keycode: char_c
|
||||
mode: [vi_normal vi_insert]
|
||||
event: {
|
||||
send: executehostcommand
|
||||
cmd: 'commandline | nu-highlight | $"```ansi\n($in)\n```" | wl-copy $in'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
let env_vars_file = '/tmp/nushell-env-vars'
|
||||
if not ($env_vars_file | path exists) {
|
||||
open /etc/profile
|
||||
| lines
|
||||
| select 11
|
||||
| str trim
|
||||
| split column ' ' del path
|
||||
| get path.0
|
||||
| open $in
|
||||
| str trim
|
||||
| lines
|
||||
| parse 'export {name}="{value}"'
|
||||
| transpose --header-row --as-record
|
||||
| tee { load-env $in }
|
||||
| to nuon
|
||||
| save --force $env_vars_file
|
||||
} else {
|
||||
open $env_vars_file
|
||||
| from nuon
|
||||
| load-env $in
|
||||
}
|
||||
|
||||
def switch [] {
|
||||
nh os switch --file ($env.NH_FLAKE | path join default.nix) (open /etc/hostname | str trim)
|
||||
}
|
||||
|
||||
# fix sudo by prepending /run/wrappers/bin to the PATH.
|
||||
$env.PATH = ($env.PATH | split row (char esep) | prepend '/run/wrappers/bin')
|
||||
$env.PATH = ($env.PATH | split row (char esep) | prepend '/etc/profiles/per-user/cr/bin')
|
||||
|
||||
carapace _carapace nushell
|
||||
| save -f ($nu.user-autoload-dirs | path join carapace.nu)
|
||||
|
||||
source ./prompt.nu
|
||||
source ./zoxide.nu
|
22
modules/home/nushell/nu.hjem.nix
Normal file
22
modules/home/nushell/nu.hjem.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
||||
packages = with pkgs; [
|
||||
nushell
|
||||
inshellisense
|
||||
carapace
|
||||
];
|
||||
environment.sessionVariables = {
|
||||
CARAPACE_BRIDGES = "inshellisense,carapace,clap,bash";
|
||||
CARAPACE_MATCH = 1;
|
||||
};
|
||||
|
||||
files = {
|
||||
".config/nushell/config.nu".source = ./config.nu;
|
||||
".config/nushell/prompt.nu".source = ./prompt.nu;
|
||||
".config/nushell/zoxide.nu".source = ./zoxide.nu;
|
||||
};
|
||||
}
|
73
modules/home/nushell/prompt.nu
Normal file
73
modules/home/nushell/prompt.nu
Normal file
|
@ -0,0 +1,73 @@
|
|||
use std null_device
|
||||
|
||||
export-env {
|
||||
load-env {
|
||||
PROMPT_COMMAND: {||
|
||||
let exit_code = $env.LAST_EXIT_CODE
|
||||
mut path_segment = $env.PWD | path basename
|
||||
|
||||
let exit_code_segment = if ($exit_code == 0) {
|
||||
""
|
||||
} else {
|
||||
$"(ansi yellow)━┫(ansi red)($exit_code)(ansi yellow)┣━"
|
||||
}
|
||||
|
||||
[$"(ansi yellow)┏" $exit_code_segment "━ " $path_segment "\n"] | str join
|
||||
}
|
||||
TRANSIENT_PROMPT_COMMAND: {||
|
||||
let path_segment = $env.PWD | path basename
|
||||
|
||||
let exit_code_segment = if ($env.LAST_EXIT_CODE == 0) {
|
||||
""
|
||||
} else {
|
||||
$"(ansi yellow)━┫(ansi red)($env.LAST_EXIT_CODE)(ansi yellow)┣━"
|
||||
}
|
||||
|
||||
[$"(ansi yellow)━" $exit_code_segment "━ " $path_segment] | str join
|
||||
}
|
||||
PROMPT_INDICATOR_VI_INSERT: $"(ansi yellow)┃ "
|
||||
PROMPT_INDICATOR_VI_NORMAL: $"(ansi yellow)┋ "
|
||||
PROMPT_MULTILINE_INDICATOR: $"(ansi yellow)┃ "
|
||||
TRANSIENT_PROMPT_INDICATOR_VI_INSERT: " "
|
||||
TRANSIENT_PROMPT_INDICATOR_VI_NORMAL: " "
|
||||
TRANSIENT_PROMPT_MULTILINE_INDICATOR: $"(ansi yellow)┃ "
|
||||
|
||||
config: (
|
||||
$env.config? | default {} | merge {
|
||||
render_right_prompt_on_last_line: true
|
||||
}
|
||||
)
|
||||
|
||||
PROMPT_COMMAND_RIGHT: {||
|
||||
let jj_status = try {
|
||||
jj --quiet --color always --ignore-working-copy log --no-graph --revisions @ --template '
|
||||
separate(
|
||||
" ",
|
||||
if(empty, label("empty", "(empty)")),
|
||||
coalesce(
|
||||
surround(
|
||||
"\"",
|
||||
"\"",
|
||||
if(
|
||||
description.first_line().substr(0, 24).starts_with(description.first_line()),
|
||||
description.first_line().substr(0, 24),
|
||||
description.first_line().substr(0, 23) ++ "…"
|
||||
)
|
||||
),
|
||||
label(if(empty, "empty"), description_placeholder)
|
||||
),
|
||||
bookmarks.join(", "),
|
||||
change_id.shortest(),
|
||||
commit_id.shortest(),
|
||||
if(conflict, label("conflict", "(conflict)")),
|
||||
if(divergent, label("divergent prefix", "(divergent)")),
|
||||
if(hidden, label("hidden prefix", "(hidden)")),
|
||||
)
|
||||
' err> $null_device
|
||||
} catch {
|
||||
""
|
||||
}
|
||||
$jj_status
|
||||
}
|
||||
}
|
||||
}
|
54
modules/home/nushell/zoxide.nu
Normal file
54
modules/home/nushell/zoxide.nu
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Initialize hook to add new entries to the database.
|
||||
export-env {
|
||||
$env.config = (
|
||||
$env.config?
|
||||
| default {}
|
||||
| upsert hooks { default {} }
|
||||
| upsert hooks.env_change { default {} }
|
||||
| upsert hooks.env_change.PWD { default [] }
|
||||
)
|
||||
let __zoxide_hooked = (
|
||||
$env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } }
|
||||
)
|
||||
if not $__zoxide_hooked {
|
||||
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append {
|
||||
__zoxide_hook: true,
|
||||
code: {|_, dir| zoxide add -- $dir}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
def zoxide_completions [context: string] {
|
||||
let parts = $context | split row " " | skip 1
|
||||
{
|
||||
options: {
|
||||
sort: false,
|
||||
completion_algorithm: substring,
|
||||
case_sensitive: false,
|
||||
},
|
||||
completions: (^zoxide query --list --exclude $env.PWD -- ...$parts | lines | first 10)
|
||||
}
|
||||
}
|
||||
|
||||
# Jump to a directory using only keywords.
|
||||
def --env --wrapped __zoxide_z [...rest: string@zoxide_completions] {
|
||||
let path = match $rest {
|
||||
[] => {'~'},
|
||||
[ '-' ] => {'-'},
|
||||
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
|
||||
_ => {
|
||||
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
||||
}
|
||||
}
|
||||
cd $path
|
||||
}
|
||||
|
||||
# Jump to a directory using interactive search.
|
||||
def --env --wrapped __zoxide_zi [...rest:string] {
|
||||
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
alias z = __zoxide_z
|
||||
alias zi = __zoxide_zi
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
self,
|
||||
sources,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
@ -10,10 +10,9 @@ let
|
|||
inherit (lib.options) mkOption;
|
||||
inherit (lib.types) listOf str package;
|
||||
inherit (config.meta.mainUser) username;
|
||||
|
||||
nushell = pkgs.callPackage (self + "/packages/nushell") { };
|
||||
in
|
||||
{
|
||||
imports = [ (sources.hjem + "/modules/nixos") ];
|
||||
options.meta = {
|
||||
users = mkOption {
|
||||
type = listOf str;
|
||||
|
@ -52,7 +51,7 @@ in
|
|||
};
|
||||
package = mkOption {
|
||||
type = package;
|
||||
default = nushell;
|
||||
default = pkgs.nushell;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -72,7 +71,7 @@ in
|
|||
"nix"
|
||||
"docker"
|
||||
];
|
||||
shell = nushell;
|
||||
shell = pkgs.nushell;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue