1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-28 02:27:44 +00:00

nushell: reorder config and make zoxide work

This commit is contained in:
RGBCube 2025-07-19 18:42:15 +03:00
parent a6f262f2a9
commit 648f6ec70f
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M

View file

@ -1,121 +1,6 @@
use std-rfc/clip use std-rfc/clip
use std null_device use std null_device
source ~/.config/nushell/zoxide.nu
$env.CARAPACE_BRIDGES = "inshellisense,carapace,zsh,fish,bash"
source ~/.config/nushell/carapace.nu
# Retrieve the output of the last command.
def _ []: nothing -> any {
$env.last?
}
# Create a directory and cd into it.
def --env mc [path: path]: nothing -> nothing {
mkdir $path
cd $path
}
# Create a directory, cd into it and initialize version control.
def --env mcg [path: path]: nothing -> nothing {
mkdir $path
cd $path
jj git init --colocate
}
def --env "nu-complete jc" [commandline: string] {
let stor = stor open
if $stor.jc_completions? == null {
stor create --table-name jc_completions --columns { value: str, description: str, is_flag: bool }
}
if $stor.jc_completions_ran? == null {
stor create --table-name jc_completions_ran --columns { _: bool }
}
if $stor.jc_completions_ran == [] { try {
let about = ^jc --about
| from json
let magic = $about
| get parsers
| each { { value: $in.magic_commands?, description: $in.description } }
| where value != null
| flatten
let options = $about
| get parsers
| select argument description
| rename value description
let inherent = ^jc --help
| lines
| split list "" # Group with empty lines as boundary.
| where { $in.0? == "Options:" } | get 0 # Get the first section that starts with "Options:"
| skip 1 # Remove header
| each { str trim }
| parse "{short}, {long} {description}"
| update description { str trim }
| each {|record|
[[value, description];
[$record.short, $record.description],
[$record.long, $record.description],
]
}
| flatten
for entry in $magic {
stor insert --table-name jc_completions --data-record ($entry | insert is_flag false)
}
for entry in ($options ++ $inherent) {
stor insert --table-name jc_completions --data-record ($entry | insert is_flag true)
}
stor insert --table-name jc_completions_ran --data-record { _: true }
} }
if ($commandline | str contains "-") {
$stor.jc_completions
} else {
$stor.jc_completions
| where is_flag == 0
} | select value description
}
# Run `jc` (JSON Converter).
def --wrapped jc [...arguments: string@"nu-complete jc"]: [any -> table, any -> record, any -> string] {
let run = ^jc ...$arguments | complete
if $run.exit_code != 0 {
error make {
msg: "jc exection failed"
label: {
text: ($run.stderr | str replace "jc:" "" | str replace "Error -" "" | str trim)
span: (metadata $arguments).span
}
}
}
if "--help" in $arguments or "-h" in $arguments {
$run.stdout
} else {
$run.stdout | from json
}
}
# `nu-highlight` with default colors
#
# Custom themes can produce a lot more ansi color codes and make the output
# exceed discord's character limits
def nu-highlight-default [] {
let input = $in
$env.config.color_config = {}
$input | nu-highlight
}
$env.config.history.file_format = "sqlite" $env.config.history.file_format = "sqlite"
$env.config.history.isolation = false $env.config.history.isolation = false
$env.config.history.max_size = 10_000_000 $env.config.history.max_size = 10_000_000
@ -210,10 +95,20 @@ $env.config.hooks.display_output = {||
$env.config.hooks.command_not_found = [] $env.config.hooks.command_not_found = []
# `nu-highlight` with default colors
#
# Custom themes can produce a lot more ansi color codes and make the output
# exceed discord's character limits
def nu-highlight-default [] {
let input = $in
$env.config.color_config = {}
$input | nu-highlight
}
# Copy the current commandline, add syntax highlighting, wrap it in a # Copy the current commandline, add syntax highlighting, wrap it in a
# markdown code block, copy that to the system clipboard. # markdown code block, copy that to the system clipboard.
# #
# Perfect for sharing code snippets on discord # Perfect for sharing code snippets on Discord.
def "nu-keybind commandline-copy" []: nothing -> nothing { def "nu-keybind commandline-copy" []: nothing -> nothing {
commandline commandline
| nu-highlight-default | nu-highlight-default
@ -541,3 +436,108 @@ module dump {
} }
use dump use dump
# Retrieve the output of the last command.
def _ []: nothing -> any {
$env.last?
}
# Create a directory and cd into it.
def --env mc [path: path]: nothing -> nothing {
mkdir $path
cd $path
}
# Create a directory, cd into it and initialize version control.
def --env mcg [path: path]: nothing -> nothing {
mkdir $path
cd $path
jj git init --colocate
}
def --env "nu-complete jc" [commandline: string] {
let stor = stor open
if $stor.jc_completions? == null {
stor create --table-name jc_completions --columns { value: str, description: str, is_flag: bool }
}
if $stor.jc_completions_ran? == null {
stor create --table-name jc_completions_ran --columns { _: bool }
}
if $stor.jc_completions_ran == [] { try {
let about = ^jc --about
| from json
let magic = $about
| get parsers
| each { { value: $in.magic_commands?, description: $in.description } }
| where value != null
| flatten
let options = $about
| get parsers
| select argument description
| rename value description
let inherent = ^jc --help
| lines
| split list "" # Group with empty lines as boundary.
| where { $in.0? == "Options:" } | get 0 # Get the first section that starts with "Options:"
| skip 1 # Remove header
| each { str trim }
| parse "{short}, {long} {description}"
| update description { str trim }
| each {|record|
[[value, description];
[$record.short, $record.description],
[$record.long, $record.description],
]
}
| flatten
for entry in $magic {
stor insert --table-name jc_completions --data-record ($entry | insert is_flag false)
}
for entry in ($options ++ $inherent) {
stor insert --table-name jc_completions --data-record ($entry | insert is_flag true)
}
stor insert --table-name jc_completions_ran --data-record { _: true }
} }
if ($commandline | str contains "-") {
$stor.jc_completions
} else {
$stor.jc_completions
| where is_flag == 0
} | select value description
}
# Run `jc` (JSON Converter).
def --wrapped jc [...arguments: string@"nu-complete jc"]: [any -> table, any -> record, any -> string] {
let run = ^jc ...$arguments | complete
if $run.exit_code != 0 {
error make {
msg: "jc exection failed"
label: {
text: ($run.stderr | str replace "jc:" "" | str replace "Error -" "" | str trim)
span: (metadata $arguments).span
}
}
}
if "--help" in $arguments or "-h" in $arguments {
$run.stdout
} else {
$run.stdout | from json
}
}
source ~/.config/nushell/zoxide.nu
$env.CARAPACE_BRIDGES = "inshellisense,carapace,zsh,fish,bash"
source ~/.config/nushell/carapace.nu