Last active
September 9, 2025 18:15
-
-
Save fdncred/32b0d2cd4be5b6b6ab64b8a52067e31a to your computer and use it in GitHub Desktop.
nushell config files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check for env var exists | |
# "FOO" | env exists? | |
def "env exists" [] { | |
each {|s| $s in (env).name } | |
} | |
let bn = (ansi { fg: '#ffffff' bg: '#000000' }) | |
let bb = (ansi { fg: '#ffffff' bg: '#555555' }) | |
let rn = (ansi { fg: '#ffffff' bg: '#AA0000' }) | |
let rb = (ansi { fg: '#ffffff' bg: '#FF5555' }) | |
let gn = (ansi { fg: '#000000' bg: '#00AA00' }) | |
let gb = (ansi { fg: '#000000' bg: '#55FF55' }) | |
let yn = (ansi { fg: '#000000' bg: '#AAAA00' }) | |
let yb = (ansi { fg: '#000000' bg: '#FFFF55' }) | |
let un = (ansi { fg: '#ffffff' bg: '#0000AA' }) | |
let ub = (ansi { fg: '#ffffff' bg: '#5555FF' }) | |
let mn = (ansi { fg: '#ffffff' bg: '#AA00AA' }) | |
let mb = (ansi { fg: '#ffffff' bg: '#FF55FF' }) | |
let cn = (ansi { fg: '#000000' bg: '#00AAAA' }) | |
let cb = (ansi { fg: '#000000' bg: '#55FFFF' }) | |
let wn = (ansi { fg: '#000000' bg: '#AAAAAA' }) | |
let wb = (ansi { fg: '#000000' bg: '#FFFFFF' }) | |
let s = 'XXXXXX' | |
let r = (ansi reset) | |
# show some standard colors vertically | |
def standard-colors [] { | |
[ | |
[color normal bold]; | |
[Black $"($bn)($s)($r)" $"($bb)($s)($r)"] | |
[Red $"($rn)($s)($r)" $"($rb)($s)($r)"] | |
[Green $"($gn)($s)($r)" $"($gb)($s)($r)"] | |
[Yellow $"($yn)($s)($r)" $"($yb)($s)($r)"] | |
[Blue $"($un)($s)($r)" $"($ub)($s)($r)"] | |
[Magenta $"($mn)($s)($r)" $"($mb)($s)($r)"] | |
[Cyan $"($cn)($s)($r)" $"($cb)($s)($r)"] | |
[White $"($wn)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# https://www.ditig.com/256-colors-cheat-sheet | |
# 38;5;<num> for these palleted index numbers | |
# Xterm 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #800000 #008000 #808000 #000080 #800080 #008080 #C0C0C0 | |
# Xterm 8 9 10 11 12 13 14 15 | |
# Bold #808080 #FF0000 #00FF00 #FFFF00 #0000FF #FF00FF #00FFFF #FFFFFF | |
# show some standard colors wide | |
def wide-colors [] { | |
# Code 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #AA0000 #00AA00 #AAAA00 #0000AA #AA00AA #00AAAA #AAAAAA | |
# Bold #555555 #FF5555 #55FF55 #FFFF55 #5555FF #FF55FF #55FFFF #FFFFFF | |
# [code '0' '1' '2' '3' '4' '5' '6' '7']; | |
[ | |
[name black red green yellow blue magenta cyan white]; | |
[normal $"($bn)($s)($r)" $"($rn)($s)($r)" $"($gn)($s)($r)" $"($yn)($s)($r)" $"($un)($s)($r)" $"($mn)($s)($r)" $"($cn)($s)($r)" $"($wn)($s)($r)"] | |
[bold $"($bb)($s)($r)" $"($rb)($s)($r)" $"($gb)($s)($r)" $"($yb)($s)($r)" $"($ub)($s)($r)" $"($mb)($s)($r)" $"($cb)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# get the terminal size with ansi escape codes | |
def terminal-size [] { | |
let sz = (input (ansi size) --bytes-until 'R') | |
# $sz should look like this | |
# Length: 9 (0x9) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5b 33 38 3b 31 35 30 52 •[38;150R | |
# let sz_len = ($sz | size).bytes | |
let sz_len = ($sz | bytes length) | |
# so let's skip the esc[ and R | |
# let r = (for x in 2..($sz_len - 2) { | |
# # This substring removes the 0x added by fmt | |
# char -u (($sz | get $x | into int | fmt).lowerhex | str substring 2..) | |
# } | str join) | |
let r = ($sz | bytes at [2 ($sz_len - 2)]) | |
# $r should look like 38;150 | |
let size = ($r | split row ';') | |
# output in record syntax | |
{ | |
rows: ($size | get 0) | |
columns: ($size | get 1) | |
} | |
} | |
# get background color with x11 ansi escapes | |
# have to hit ctrl+g after the statement to get the value in $x | |
# let x = input $"(ansi -o '11;?')(char bel)" --bytes-until (char bel) | |
# when input = rgb:4_numbers/4_numbers/4_numbers like rgb:1919/1313/2323 | |
# this means 16-bit rgb components. 16^4 means four hex digits. FFFF is 65535 | |
# 48-bit color. it could be 1 number 4-bits, 2 8-bits, 3 12-bits, 4 16-bits | |
# #3a7 is the same as #3000a0007000. | |
# refernce https://www.x.org/releases/X11R7.7/doc/man/man7/X.7.xhtml#heading11 | |
# mine was rgb:1919/1313/2323 | |
# (('1919' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# (('1313' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# (('2323' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# or | |
# 0x1919 / 0x100 | math round | |
# 0x1313 / 0x100 | math round | |
# 0x2323 / 0x100 | math round | |
# get the background color with ansi escapes | |
def get-bg [] { | |
# have to hit control+g in kitty to get value in $bg | |
let bg = (input $"(ansi -o '11;?')(ansi st)" --bytes-until '\') | |
# $bg should look like this | |
# Length: 26 (0x1a) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 31 39 31 39 2f 31 33 •]11;rgb:1919/13 | |
# 00000010: 31 33 2f 32 33 32 33 1b 5c 07 13/2323•\• | |
# jt's output | |
# Length: 24 (0x18) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 33 66 33 66 2f 33 66 •]11;rgb:3f3f/3f | |
# 00000010: 33 66 2f 33 66 33 66 07 3f/3f3f• | |
# so let's skip the prefix and suffix and just get | |
# 1919/1313/2323 | |
# let rgb_string = ($bg | split chars | range 9..22 | str collect) | |
# TODO figure how other ways that string can start so we can programmatically | |
# calculate the start_index better. It's probably not always \x1b]11;rgb: | |
let start_index = 9 | |
let end_index = ($bg | bytes index-of 0x[1b 5c]) | |
let term_data = ($bg | bytes at [$start_index,$end_index]) | |
let rgb_string = ($term_data | decode utf-8) | |
# let bg_len = ($bg | size).bytes | |
# # so let's skip the prefix and suffix and just get | |
# # 1919/1313/2323 | |
# let rgb_string = (for x in 9..($bg_len - 4) { | |
# # This substring removes the 0x added by fmt after conversion to char | |
# char -u (($bg | get $x | into int | fmt).lowerhex | str substring 2..) | |
# } | str collect) | |
let rgb = ($rgb_string | split row '/') | |
let r = ($rgb | get 0) | |
let g = ($rgb | get 1) | |
let b = ($rgb | get 2) | |
# ('1313' | into int -r 16) / 256 | math round | fmt).lowerhex | |
let red = (($r | into int -r 16) / 256 | math round | fmt).lowerhex | |
let green = (($g | into int -r 16) / 256 | math round | fmt).lowerhex | |
let blue = (($b | into int -r 16) / 256 | math round | fmt).lowerhex | |
# output in record syntax | |
{ | |
red: $red | |
green: $green | |
blue: $blue | |
hex: $"#($red | str substring 2..)($green | str substring 2..)($blue | str substring 2..)" | |
rgb: $"RGB(char lp)(($red | into int | fmt).display), (($green | into int | fmt).display), (($blue | into int | fmt).display)(char rp)" | |
} | |
} | |
# Clear the screen with ansi escapes | |
def cls [] { | |
ansi cls | |
} | |
# Full term reset, cls, clear buffer, attributes off, | |
def clsterm [] { | |
$"(ansi esc)c(ansi clsb)(ansi cls)(ansi reset)(ansi home)" | |
} | |
# good for things like this | |
# ps | where name =~ Firefox | get mem | sum | |
def sum [] { | |
reduce {|acc, item| $acc + $item } | |
} | |
# written by Kubouch for virtualenv | |
def is-string [ | |
x # value to check to see if it's a string | |
] { | |
($x | describe) == "string" | |
} | |
# does an env var exist? | |
def has-env [name: string] { | |
$name in (env).name | |
} | |
# go to a path like $nu.config-path | goto | |
def-env goto [] { | |
let input = $in | |
cd ( | |
if ($input | path type) == file { | |
($input | path dirname) | |
} else { | |
$input | |
} | |
) | |
} | |
# run cargo nextest for nushell | |
def cargo_tests [] { | |
cargo nextest run --all --features=extra | |
} | |
# run cargo clippy for nushell | |
def cargo_clippy [] { | |
cargo clippy --all --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect | |
} | |
def old-ls [path?] { | |
if $path == $nothing { | |
ls . | sort-by type name -i | |
} else { | |
ls $path | sort-by type name -i | |
} | |
} | |
# ls sort type name -i | |
def lss [path?] { | |
if $path == $nothing { | |
old-ls . | |
} else { | |
old-ls $path | |
} | |
} | |
def-env cc [dir = ""] { | |
let cctemp = ['C:\Users\dschroeder\source\repos\forks', 'C:\'] | |
let default = 'C:\Users\dschroeder\source\repos\forks' | |
let complete_dir = (if $dir == "" { | |
$default | |
} else { | |
$cctemp | |
| reduce -f "" { |$it, $acc| if $acc == "" { | |
let new_path = ([$it $dir] | path join) | |
if ($new_path | path exists) { | |
$new_path | |
} else { | |
"" | |
} | |
} else { | |
$acc | |
} | |
} | |
}) | |
let complete_dir = if $complete_dir == "" { $default } else { $complete_dir } | |
let-env PWD = $complete_dir | |
} | |
# select a column from a table | |
def column [n] { transpose | select $n | transpose -i | headers } | |
# get the nushell star count | |
def stars [] { | |
http get https://api.github.com/repos/nushell/nushell | get stargazers_count | |
} | |
# hide all prompt variables | |
def-env hide_prompt [] { | |
hide-env PROMPT_COMMAND | |
hide-env PROMPT_COMMAND_RIGHT | |
hide-env PROMPT_INDICATOR | |
} | |
# match | |
def matcher [input, matchers: record] { | |
echo $matchers | get $input | do $in | |
} | |
# matcher example | |
# > let x = "3" | |
# matcher $x { | |
# 1: { echo "you chose one" }, | |
# 2: { echo "you chose two" }, | |
# 3: { echo "you chose three" } | |
# } | |
# quick way to get an abbreviated directory | |
def pwd-short [] { | |
$env.PWD | str replace $nu.home-path '~' -s | |
} | |
def show [] { | |
let gitProxy = (if (git config --global --list | grep proxy | empty?) { 'Off' } else { 'On' }) | |
version | transpose | rename nu-ver value | |
print [ | |
[name, value]; | |
['Git Proxy', $gitProxy] | |
] | |
} | |
#ls in text grid | |
def lg [ | |
--date(-t) #sort by date | |
--reverse(-r) #reverse order | |
] { | |
let t = if $date {"true"} else {"false"} | |
let r = if $reverse {"true"} else {"false"} | |
switch $t { | |
"true": { | |
switch $r { | |
"true": { | |
ls | sort-by -r modified | grid -c | |
}, | |
"false": { | |
ls | sort-by modified | grid -c | |
} | |
} | |
}, | |
"false": { | |
switch $r { | |
"true": { | |
ls | sort-by -i -r type name | grid -c | |
}, | |
"false": { | |
ls | sort-by -i type name | grid -c | |
} | |
} | |
} | |
} | |
} | |
# Switch-case like instruction | |
def switch [ | |
var #input var to test | |
cases: record #record with all cases | |
# | |
# Example: | |
# let x = 3 | |
# switch $x { | |
# 1: { echo "you chose one" }, | |
# 2: { echo "you chose two" }, | |
# 3: { echo "you chose three" } | |
# } | |
] { | |
echo $cases | get $var | do $in | |
} | |
# Check how many downloads nushell has had | |
def nudown [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | | |
get assets | | |
flatten | | |
select name download_count created_at | | |
update created_at {|r| $r.created_at | into datetime | date format '%m/%d/%Y %H:%M:%S'} | |
} | |
# Ye old start command | |
def start [path] { | |
if $nu.os-info.name == "windows" { | |
^start $path | |
} else if $nu.os-info.name == "macos" { | |
^open $path | |
} else { | |
xdg-open $path | |
} | |
} | |
# get a list of sysinternals downloads | |
def show-sysinternals [] { | |
let sysinternals_list = (http get https://live.sysinternals.com | split row '<br>' | where $it !~ "<pre|pre>|<dir>") | |
$sysinternals_list | | |
each {|i| $i | from ssv -a -m 3 -n | get 0} | | |
update column1 {|d| $d.column1 | str trim | into datetime} | | |
update column2 {|c| $c.column2 | str replace '(<A HREF="/)' '' | str replace '(">.*)' '' | | |
split column ' ' filesize filename } | flatten | flatten | | |
update filesize {|f| $f.filesize | into filesize} | | |
rename filedate | move filename --before filedate | move filedate --after filesize | |
} | |
def show_banner [] { | |
let ellie = [ | |
" __ ," | |
" .--()°'.'" | |
"'|, . ,' " | |
' !_-(_\ ' | |
] | |
let s = (sys) | |
print $"(ansi reset)(ansi green)($ellie.0)" | |
print $"(ansi green)($ellie.1) (ansi yellow) (ansi yellow_bold)Nushell (ansi reset)(ansi yellow)v(version | get version)(ansi reset)" | |
print $"(ansi green)($ellie.2) (ansi light_blue) (ansi light_blue_bold)RAM (ansi reset)(ansi light_blue)($s.mem.used) / ($s.mem.total)(ansi reset)" | |
print $"(ansi green)($ellie.3) (ansi light_purple)ﮫ (ansi light_purple_bold)Uptime (ansi reset)(ansi light_purple)($s.host.uptime)(ansi reset)" | |
} | |
# Returns a filtered table that has distinct values in the specified column | |
def uniq-by2 [ | |
column: string # The column to scan for duplicate values | |
] { | |
reduce { |item, acc| | |
if ($acc | any { |storedItem| | |
($storedItem | get $column) == ($item | get $column) | |
}) { | |
$acc | |
} else { | |
$acc | append $item | |
} | |
} | |
} | |
# how to use uniq-by | |
# let people = [ | |
# {name: 'A', email: '[email protected]'}, | |
# {name: 'a', email: '[email protected]'}, | |
# {name: 'b', email: '[email protected]'} | |
# ] | |
# $people | uniq-by email | |
# How to change the cursor with ansi escape sequences | |
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Functions-using-CSI-_-ordered-by-the-final-character_s_ | |
# CSI Ps SP q | |
# Set cursor style (DECSCUSR), VT520. | |
# Ps = 0 ⇒ blinking block. | |
# Ps = 1 ⇒ blinking block (default). | |
# Ps = 2 ⇒ steady block. | |
# Ps = 3 ⇒ blinking underline. | |
# Ps = 4 ⇒ steady underline. | |
# Ps = 5 ⇒ blinking bar, xterm. | |
# Ps = 6 ⇒ steady bar, xterm. | |
# Example $"(ansi csi)5 q" should change it to a blinking bar | |
# Delete all branches that are not in the excepts list | |
# Usage: del-branches [main] | |
def del-branches ( | |
excepts:list # don't delete branch in the list | |
--dry-run(-d) # do a dry-run | |
) { | |
let branches = (git branch | lines | str trim) | |
let remote_branches = (git branch -r | lines | str replace '^.+?/' '' | uniq) | |
if $dry_run { | |
print "Starting Dry-Run" | |
} else { | |
print "Deleting for real" | |
} | |
$branches | each {|it| | |
if ($it not-in $excepts) and ($it not-in $remote_branches) and (not ($it | str starts-with "*")) { | |
# git branch -D $it | |
if $dry_run { | |
print $"git branch -D ($it)" | |
} else { | |
print $"Deleting ($it) for real" | |
#git branch -D $it | |
} | |
} | |
} | |
} | |
def pwd [] { $env.PWD } | |
def stefans_meeting_pr_list [] { | |
gh pr list --json url,number,author,title,labels,isDraft | | |
from json | | |
each {|i| | |
[$"- [($i.number)]\(($i.url)\) ($i.title) \(@($i.author.login)\)", | |
($i.labels | | |
each {|l| | |
$l | | |
get name | | |
$" - ($in)" | |
}), | |
(if $i.isDraft {" - Currently marked as draft"}) | |
] | | |
each while { $in } | | |
flatten | | |
to text | |
} | | |
reverse | | |
to text | |
} | |
def history-stats [ | |
--summary (-s): int = 5 | |
--last-cmds (-l): int | |
--verbose (-v): bool | |
] { | |
let top_commands = ( | |
history | |
| if ($last_cmds != $nothing) { last $last_cmds } else { $in } | |
| get command | |
| split column ' ' command | |
| uniq -c | |
| flatten | |
| sort-by --reverse count | |
| first $summary | |
| table -n 1 | |
) | |
if ($verbose) { | |
let total_cmds = (history | length) | |
let unique_cmds = (history | get command | uniq | length) | |
print $"(ansi green)Total commands in history:(ansi reset) ($total_cmds)" | |
print $"(ansi green)Unique commands:(ansi reset) ($unique_cmds)" | |
print "" | |
print $"(ansi green)Top ($summary)(ansi reset) most used commands:" | |
} | |
$top_commands | |
} | |
def history-search [ | |
str: string = '' # search string | |
--cwd(-c) # Filter search result by directory | |
--exit(-e): int = 0 # Filter search result by exit code | |
--before(-b): datetime = 2100-01-01 # Only include results added before this date | |
--after(-a): datetime = 1970-01-01 # Only include results after this date | |
--limit(-l): int = 25# How many entries to return at most | |
] { | |
if $cwd == false { | |
history | |
| where start_timestamp != "" | |
| update start_timestamp {|r| $r.start_timestamp | into datetime} | |
| where command =~ $str and exit_status == $exit and start_timestamp > $after and start_timestamp < $before | |
| first $limit | |
} else { | |
history | |
| where start_timestamp != "" | |
| update start_timestamp {|r| $r.start_timestamp | into datetime} | |
| where command =~ $str and cwd == $env.PWD and exit_status == $exit and start_timestamp > $after and start_timestamp < $before | |
| first $limit | |
} | |
} | |
# Get values from simple key-value object | |
def get-values [] { | |
let subject = $in | |
let keys = ($subject | columns) | |
$keys | each {|it| $subject | get $it } | |
} | |
# Get an abbreviated path | |
def spwd [] { | |
let home = (if ($nu.os-info.name == windows) { $env.USERPROFILE } else { $env.HOME }) | |
let sep = (if ($nu.os-info.name == windows) { "\\" } else { "/" }) | |
let spwd_paths = ( | |
$"!/($env.PWD)" | | |
str replace $"!/($home)" ~ -s | | |
split row $sep | |
) | |
# Darren's hack to make all slashes point to the right | |
let sep = '/' | |
# end hack | |
let spwd_len = (($spwd_paths | length) - 1) | |
for -n i in $spwd_paths { | |
let spwd_src = ($i.item | split chars) | |
if ($i.index == $spwd_len) { | |
print -n $i.item | |
} else if ($spwd_src.0 == ".") { | |
print -n $".($spwd_src.1)($sep)" | |
} else { | |
print -n $"($spwd_src.0)($sep)" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Hello, from config.nu" | |
# nushell version in md table | |
def nuvermd [] { version | transpose key value | to md } | |
# nushell version in table | |
def nuver [] { version | transpose key value } | |
# ls in a grid with colors and icons | |
def lsg [] { ls | sort-by type name -i | grid -c -i | str trim } | |
# tokei output in nushell table | |
def tok [] { tokei | lines | skip 1 | str join "\n" | detect columns | where Language !~ '[-=(]' | into int Files Lines Code Comments Blanks } | |
def path_underline [color: string] { | |
{|p| if ($p | path exists) { $color + "_underline" } else { $color } } | |
} | |
def is_alias [cmd: string] { | |
$cmd in (scope aliases | get name) | |
} | |
# attributes | |
# code meaning | |
# l blink | |
# b bold | |
# d dimmed | |
# h hidden | |
# i italic | |
# r reverse | |
# s strikethrough | |
# u underline | |
# n nothing | |
# defaults to nothing | |
# region: Themes | |
# region: Dark Theme | |
let dark_theme = { | |
# color for nushell primitives | |
separator: white | |
leading_trailing_space_bg: {bg: dark_gray} # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
bool: {|| if $in { 'light_cyan' } else { 'light_gray' } } | |
int: white | |
filesize: {|e| | |
if $e == 0b { | |
'white' | |
} else if $e < 1mb { | |
'cyan' | |
} else { 'blue' } | |
} | |
duration: white | |
date: {|| | |
(date now) - $in | if $in < 1hr { | |
'purple' | |
} else if $in < 6hr { | |
'red' | |
} else if $in < 1day { | |
'yellow' | |
} else if $in < 3day { | |
'green' | |
} else if $in < 1wk { | |
'light_green' | |
} else if $in < 6wk { | |
'cyan' | |
} else if $in < 52wk { | |
'blue' | |
} else { 'dark_gray' } | |
} | |
range: white | |
float: white | |
string: white | |
nothing: white | |
binary: white | |
cellpath: white | |
row_index: green_bold | |
record: white | |
list: white | |
block: white | |
hints: dark_gray | |
search_result: {bg: red fg: white} | |
# shapes are used to change the cli syntax highlighting | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_closure: green_bold | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: darkorange | |
shape_externalarg: green_bold | |
shape_external_resolved: light_yellow_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
shape_garbage: {fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: {attr: u} | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
} | |
# endregion | |
# region: Base16 Theme | |
# #DCDCAA #4ec9b0 | |
# #1e1e1e | |
# #569cd6 | |
let base00 = "#181818" # Default Background | |
let base01 = "#282828" # Lighter Background (Used for status bars, line number and folding marks) | |
let base02 = "#383838" # Selection Background | |
let base03 = "#585858" # Comments, Invisibles, Line Highlighting | |
let base04 = "#b8b8b8" # Dark Foreground (Used for status bars) | |
let base05 = "#d8d8d8" # Default Foreground, Caret, Delimiters, Operators | |
let base06 = "#e8e8e8" # Light Foreground (Not often used) | |
let base07 = "#f8f8f8" # Light Background (Not often used) | |
let base08 = "#ab4642" # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted | |
let base09 = "#dc9656" # Integers, Boolean, Constants, XML Attributes, Markup Link Url | |
let base0a = "#f7ca88" # Classes, Markup Bold, Search Text Background | |
let base0b = "#a1b56c" # Strings, Inherited Class, Markup Code, Diff Inserted | |
let base0c = "#86c1b9" # Support, Regular Expressions, Escape Characters, Markup Quotes | |
let base0d = "#7cafc2" # Functions, Methods, Attribute IDs, Headings | |
let base0e = "#ba8baf" # Keywords, Storage, Selector, Markup Italic, Diff Changed | |
let base0f = "#a16946" # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?> | |
let base16_theme = { | |
separator: $base03 | |
leading_trailing_space_bg: $base04 | |
header: $base0b | |
date: $base0e | |
filesize: $base0d | |
row_index: $base0c | |
bool: $base08 | |
int: $base0b | |
duration: $base08 | |
range: $base08 | |
float: $base08 | |
string: $base04 | |
nothing: $base08 | |
binary: $base08 | |
cellpath: $base08 | |
# shape_garbage: { fg: $base07 bg: $base08 attr: b} # base16 white on red | |
# but i like the regular white on red for parse errors | |
shape_garbage: {fg: "#FFFFFF" bg: "#FF0000" attr: b} | |
shape_bool: $base0d | |
shape_int: {fg: $base0e attr: b} | |
shape_float: {fg: $base0e attr: b} | |
shape_range: {fg: $base0a attr: b} | |
shape_internalcall: {fg: $base0c attr: b} | |
shape_external: $base0c | |
shape_externalarg: {fg: $base0b attr: b} | |
shape_literal: $base0d | |
shape_operator: $base0a | |
shape_signature: {fg: $base0b attr: b} | |
shape_string: $base0b | |
shape_filepath: $base0d | |
shape_globpattern: {fg: $base0d attr: b} | |
shape_variable: $base0e | |
shape_flag: {fg: $base0d attr: b} | |
shape_custom: {attr: b} | |
} | |
# endregion | |
# region: myTheme | |
let my_theme = { | |
binary: red | |
bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
cellpath: cyan | |
date: {|| | |
(date now) - $in | if $in < 1hr { | |
'red3b' #"\e[38;5;160m" #'#e61919' # 160 | |
} else if $in < 6hr { | |
'orange3' #"\e[38;5;172m" #'#e68019' # 172 | |
} else if $in < 1day { | |
'yellow3b' #"\e[38;5;184m" #'#e5e619' # 184 | |
} else if $in < 3day { | |
'chartreuse2b' #"\e[38;5;112m" #'#80e619' # 112 | |
} else if $in < 1wk { | |
'green3b' #"\e[38;5;40m" #'#19e619' # 40 | |
} else if $in < 6wk { | |
'darkturquoise' #"\e[38;5;44m" #'#19e5e6' # 44 | |
} else if $in < 52wk { | |
'deepskyblue3b' #"\e[38;5;32m" #'#197fe6' # 32 | |
} else { 'dark_gray' } | |
} | |
duration: blue_bold | |
filesize: {|e| if $e == 0b { 'black' } else if $e < 1mb { 'ub' } else { 'cyan' } } | |
float: red | |
foreground: green3b | |
header: cb | |
hints: dark_gray | |
int: green | |
leading_trailing_space_bg: {bg: dark_gray_dimmed} | |
nothing: red | |
range: purple | |
row_index: yb | |
separator: yd | |
# string: { if $in =~ '^#\w{6}$' { $in } else { 'white' } } | |
string: {|x| if $x =~ '^#[a-fA-F\d]+' { $x } else { 'default' } } | |
# search_result: {fg: white bg: blue} | |
search_result: blue_reverse | |
# shapes are used to change the cli syntax highlighting | |
# shape_and: purple_bold | |
# shape_binary: purple_bold | |
shape_block: "#33ff00" | |
# shape_bool: light_cyan | |
shape_bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
shape_closure: "#ffb000" | |
# shape_custom: green | |
# shape_datetime: cyan_bold | |
# shape_directory: cyan | |
# shape_external: light_green | |
shape_externalarg: light_purple | |
shape_external: darkorange | |
shape_external_resolved: light_yellow_bold | |
# shape_externalarg: {|| if ($in | path exists) { 'light_red_underline' } else { 'light_red' } } | |
# shape_filepath: {|| if ($in | path exists) { 'light_green_underline' } else { 'light_green' } } | |
shape_filepath: cyan | |
# shape_flag: blue_bold | |
# shape_float: purple_bold | |
# shape_garbage: { fg: white bg: red attr: b} | |
shape_garbage: {fg: red attr: u} | |
# shape_globpattern: cyan_bold | |
# shape_int: purple_bold | |
shape_internallcall: cyan_bold | |
# shape_list: cyan_bold | |
# shape_literal: blue | |
# shape_match_pattern: green | |
shape_matching_brackets: {fg: red bg: default attr: b} | |
# shape_nothing: light_cyan | |
# shape_operator: yellow | |
# shape_or: purple_bold | |
# shape_pipe: purple_bold | |
# shape_range: yellow_bold | |
# shape_record: cyan_bold | |
# shape_redirection: purple_bold | |
# shape_signature: green_bold | |
# shape_string: green | |
# shape_string: {|| if ($in | path exists) { 'bold_yellow_underline' } else { 'bold_yellow' } } | |
shape_string_interpolation: cyan_bold | |
# shape_table: blue_bold | |
# shape_variable: purple | |
# shape_vardecl: purple | |
} | |
# endregion | |
# region: lightTheme | |
let light_theme = { | |
# color for nushell primitives | |
separator: dark_gray | |
leading_trailing_space_bg: {attr: n} # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
bool: {|| if $in { 'dark_cyan' } else { 'dark_gray' } } | |
int: dark_gray | |
filesize: {|e| | |
if $e == 0b { | |
'dark_gray' | |
} else if $e < 1mb { | |
'cyan_bold' | |
} else { 'blue_bold' } | |
} | |
duration: dark_gray | |
date: {|| | |
(date now) - $in | if $in < 1hr { | |
'purple' | |
} else if $in < 6hr { | |
'red' | |
} else if $in < 1day { | |
'yellow' | |
} else if $in < 3day { | |
'green' | |
} else if $in < 1wk { | |
'light_green' | |
} else if $in < 6wk { | |
'cyan' | |
} else if $in < 52wk { | |
'blue' | |
} else { 'dark_gray' } | |
} | |
range: dark_gray | |
float: dark_gray | |
string: dark_gray | |
nothing: dark_gray | |
binary: dark_gray | |
cellpath: dark_gray | |
row_index: green_bold | |
record: white | |
list: white | |
block: white | |
hints: dark_gray | |
search_result: {fg: white bg: red} | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_closure: green_bold | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: cyan | |
shape_externalarg: green_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: {fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: {attr: u} | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
} | |
# endregion | |
# endregion | |
# region: External Completers | |
let carapace_completer = {|spans: list<string>| | |
carapace $spans.0 nushell ...$spans | |
| from json | |
} | |
let zoxide_completer = {|spans| | |
$spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD } | |
} | |
let external_completer = {|spans| | |
# if the current command is an alias, get it's expansion | |
let expanded_alias = (scope aliases | where name == $spans.0 | get -i 0 | get -i expansion) | |
# overwrite | |
let spans = ( | |
if $expanded_alias != null { | |
# put the first word of the expanded alias first in the span | |
$spans | skip 1 | prepend ($expanded_alias | split row " " | take 1) | |
} else { | |
$spans | |
} | |
) | |
match $spans.0 { | |
z|zi => $zoxide_completer | |
__zoxide_z|__zoxide_zi => $zoxide_completer | |
_ => $carapace_completer | |
} | do $in $spans | |
} | |
# endregion | |
# region: Config | |
$env.config = { | |
# region: Settings | |
show_banner: true # true or false to enable or disable the welcome banner at startup | |
ls: { | |
use_ls_colors: true # use the LS_COLORS environment variable to colorize output | |
clickable_links: true # true or false to enable or disable clickable links in the ls listing. your terminal has to support links. | |
} | |
rm: { | |
always_trash: true # always act as if -t was given. Can be overridden with -p | |
} | |
table: { | |
mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other | |
index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column | |
show_empty: false # show 'empty list' and 'empty record' placeholders for command output | |
padding: {left: 1 right: 1} # a left right padding of each column in a table | |
trim: { | |
# A strategy of managing table view in case of limited space. | |
methodology: wrapping # truncating or wrapping | |
wrapping_try_keep_words: true | |
# A suffix which will be used with 'truncating' methodology | |
truncating_suffix: "…" # "⋯" "︙" | |
} | |
header_on_separator: true # show header text on separator/border line | |
footer_inheritance: true # render footer in parent table if child is big enough (extended table option) | |
# abbreviated_row_count: 10 # limit data rows from top and bottom after reaching a set point | |
} | |
error_style: "fancy" # "fancy" or "plain" for screen reader-friendly error messages | |
# Whether an error message should be printed if an error of a certain kind is triggered. | |
display_errors: { | |
exit_code: false # assume the external command prints an error message | |
# Core dump errors are always printed, and SIGPIPE never triggers an error. | |
# The setting below controls message printing for termination by all other signals. | |
termination_signal: true | |
} | |
# datetime_format determines what a datetime rendered in the shell would look like. | |
# Behavior without this configuration point will be to "humanize" the datetime display, | |
# showing something like "a day ago." | |
datetime_format: { | |
# normal: '%a, %d %b %Y %H:%M:%S %z' # shows up in displays of variables or other datetime's outside of tables | |
# table: '%m/%d/%y %I:%M:%S %p' # generally shows up in tabular outputs such as ls. commenting this out will change it to the default human readable datetime format | |
} | |
explore: { | |
table: { | |
selected_cell: {bg: 'blue'} | |
show_cursor: false | |
} | |
try: { | |
reactive: true | |
} | |
} | |
history: { | |
max_size: 1_000_000 # Session has to be reloaded for this to take effect | |
sync_on_enter: true # Enable to share the history between multiple sessions, else you have to close the session to persist history to file | |
file_format: sqlite # "sqlite" or "plaintext" | |
isolation: true | |
} | |
completions: { | |
case_sensitive: false # set to true to enable case-sensitive completions | |
quick: true # set this to false to prevent auto-selecting completions when only one remains | |
partial: true # set this to false to prevent partial filling of the prompt | |
algorithm: prefix # prefix, fuzzy | |
external: { | |
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow | |
max_results: 10 # setting it lower can improve completion performance at the cost of omitting some options | |
completer: null | |
} | |
use_ls_colors: true # set this to true to enable file/path/directory completions using LS_COLORS | |
} | |
# filesize: { | |
# metric: true # true => KB, MB, GB (ISO standard), false => KiB, MiB, GiB (Windows standard) | |
# format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto | |
# } | |
filesize: { | |
# filesize.unit (string): One of either: | |
# - A filesize unit: "B", "kB", "KiB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "PB", "PiB", "EB", or "EiB". | |
# - An automatically scaled unit: "metric" or "binary". | |
# | |
# "metric" will use units with metric (SI) prefixes like kB, MB, or GB. | |
# "binary" will use units with binary prefixes like KiB, MiB, or GiB. | |
# Otherwise, setting this to one of the filesize units will use that particular unit when displaying all file sizes. | |
unit: 'B' | |
# filesize.precision (int or nothing): | |
# The number of digits to display after the decimal point for file sizes. | |
# When set to `null`, all digits after the decimal point will be displayed. | |
precision: 2 | |
# filesize.show_unit (bool): | |
# Whether to show or hide the file size unit. Useful if `$env.config.filesize.unit` is set to a fixed unit, | |
# and you don't want that same unit repeated over and over again in which case you can set this to `false`. | |
show_unit: false | |
} | |
cursor_shape: { | |
emacs: underscore # block, underscore, line, blink_block, blink_underscore, blink_line (line is the default) | |
vi_insert: block # block, underscore, line , blink_block, blink_underscore, blink_line (block is the default) | |
vi_normal: line # block, underscore, line, blink_block, blink_underscore, blink_line (underscore is the default) | |
} | |
# color_config: $base16_theme | |
# color_config: $light_theme | |
# color_config: $default_theme | |
color_config: $my_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record | |
# use_grid_icons: true | |
footer_mode: auto #5 # always, never, number_of_rows, auto | |
float_precision: 2 # the precision for displaying floats in tables | |
# buffer_editor: 'C:\Users\us991808\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd' # command that will be used to edit the current line buffer with ctr+e | |
buffer_editor: nvim | |
use_ansi_coloring: true | |
bracketed_paste: true # enable bracketed paste, currently useless on windows | |
edit_mode: emacs # emacs, vi | |
# shell_integration: true # enables terminal markers and a workaround to arrow keys stop working issue | |
shell_integration: { | |
# osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title | |
osc2: true | |
# osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory | |
osc7: true | |
# osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it. show_clickable_links is deprecated in favor of osc8 | |
osc8: true | |
# osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal | |
osc9_9: true | |
# osc133 is several escapes invented by Final Term which include the supported ones below. | |
# 133;A - Mark prompt start | |
# 133;B - Mark prompt end | |
# 133;C - Mark pre-execution | |
# 133;D;exit - Mark execution finished with exit code | |
# This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is | |
osc133: true | |
# osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features | |
# 633;A - Mark prompt start | |
# 633;B - Mark prompt end | |
# 633;C - Mark pre-execution | |
# 633;D;exit - Mark execution finished with exit code | |
# 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce | |
# 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal | |
# and also helps with the run recent menu in vscode | |
osc633: true | |
# reset_application_mode is escape \x1b[?1l and was added to help ssh work better | |
reset_application_mode: true | |
} | |
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt. | |
use_kitty_protocol: true # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this | |
highlight_resolved_externals: true # true enables highlighting of external commands in the repl resolved by which. | |
recursion_limit: 50 # the maximum number of times nushell allows recursion before stopping it | |
# endregion | |
plugins: {} # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration. | |
plugin_gc: { | |
# Configuration for plugin garbage collection | |
default: { | |
enabled: true # true to enable stopping of inactive plugins | |
stop_after: 0sec # how long to wait after a plugin is inactive to stop it | |
} | |
plugins: { | |
# alternate configuration for specific plugins, by name, for example: | |
# | |
gstat: { | |
stop_after: 0sec | |
} | |
# polars: { | |
# stop_after: 1hr | |
# } | |
} | |
} | |
# region: hooks | |
hooks: { | |
# run before the prompt is shown | |
pre_prompt: [ | |
{|| | |
null | |
} | |
] | |
# run before the repl input is run | |
pre_execution: [ | |
{|| | |
null | |
} | |
] | |
env_change: { | |
# run if the PWD environment is different since the last repl input | |
PWD: [ | |
# Print lsg on each folder change | |
{|before, after| | |
print (lsg) | |
# null | |
} | |
# Print the startup time to a file but $before is null, which only happens on startup | |
{|before, _| | |
if $before == null { | |
let file = ($nu.home-path | path join ".local" "share" "nushell" "startup-times.nuon") | |
if not ($file | path exists) { | |
mkdir ($file | path dirname) | |
touch $file | |
} | |
let ver = (version) | |
open $file | append { | |
date: (date now) | |
time: $nu.startup-time | |
build: ($ver.build_rust_channel) | |
allocator: ($ver.allocator) | |
version: ($ver.version) | |
commit: ($ver.commit_hash) | |
build_time: ($ver.build_time) | |
bytes_loaded: (view files | get size | math sum) | |
} | collect { save --force $file } | |
} | |
} | |
{ | |
condition: {|_, after| not ($after | path join 'toolkit.nu' | path exists) } | |
code: "hide toolkit" | |
} | |
{ | |
condition: {|_, after| $after | path join 'toolkit.nu' | path exists } | |
code: " | |
print $'(ansi default_underline)(ansi default_bold)toolkit(ansi reset) module (ansi green_italic)detected(ansi reset)...' | |
print $'(ansi yellow_italic)activating(ansi reset) (ansi default_underline)(ansi default_bold)toolkit(ansi reset) module with `(ansi default_dimmed)(ansi default_italic)use toolkit.nu(ansi reset)`' | |
use toolkit.nu | |
" | |
} | |
] | |
} | |
# run to display the output of a pipeline | |
display_output: {|| | |
# if (term size).columns > 100 { table -e } else { table } | |
table | |
} | |
command_not_found: {|| | |
null # return an error message when a command is not found | |
} | |
} | |
# endregion | |
# region: menus | |
# old timey crt colors | |
# https://superuser.com/questions/361297/what-colour-is-the-dark-green-on-old-fashioned-green-screen-computer-displays/1206781#1206781 | |
# #ffb000 <- 600nm P3 <--history_menu | |
# #ffcc00 <- 593nm | |
# #33ff00 <- 524nm <-- completion_menu | |
# #33ff33 <- P1 | |
# #00ff33 <- 506nm | |
# #66ff66 <- P24 | |
# #00ff66 <- 502nm | |
# #282828 <- background | |
menus: [ | |
{ | |
name: ide_completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: ide | |
min_completion_width: 0 | |
max_completion_width: 50 | |
# max_completion_height: 10, # will be limited by the available lines in the terminal | |
padding: 0 | |
border: true | |
cursor_offset: 0 | |
description_mode: "prefer_right" | |
min_description_width: 0 | |
max_description_width: 50 | |
max_description_height: 10 | |
description_offset: 1 | |
# If true, the cursor pos will be corrected, so the suggestions match up with the typed text | |
# | |
# C:\> str | |
# str join | |
# str trim | |
# str split | |
correct_cursor_pos: true | |
} | |
style: { | |
# text: { fg: "#33ff00" } | |
text: green | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
selected_text: {attr: r} | |
description_text: yellow | |
# match_text: { attr: u } | |
match_text: {fg: "#33ff00"} | |
# selected_match_text: { attr: ur } | |
selected_match_text: {fg: "#33ff00" attr: r} | |
} | |
} | |
# Configuration for default nushell menus | |
# Note the lack of souce parameter | |
{ | |
name: completion_menu | |
only_buffer_difference: false # Search is done on the text written after activating the menu | |
marker: $" \n❯ (char -u '1f4ce') " | |
# marker: "| " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
} | |
style: { | |
# text: { fg: "#33ff00" } | |
text: green | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
selected_text: {attr: r} | |
description_text: yellow | |
# match_text: { attr: u } | |
match_text: {fg: "#33ff00"} | |
# selected_match_text: { attr: ur } | |
selected_match_text: {fg: "#33ff00" attr: r} | |
} | |
} | |
{ | |
name: history_menu | |
only_buffer_difference: false | |
marker: $"(char -u '1f50d') " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#ffb000" | |
selected_text: {fg: "#ffb000" attr: r} | |
description_text: yellow | |
} | |
} | |
{ | |
name: help_menu | |
only_buffer_difference: true | |
marker: "? " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: "#7F00FF" | |
selected_text: {fg: "#ffff00" bg: "#7F00FF" attr: b} | |
description_text: "#ffff00" | |
} | |
} | |
# Example of extra menus created using a nushell source | |
# Use the source field to create a list of records that populates | |
# the menu | |
{ | |
name: fzf_history_menu_fzf_ui | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
open $nu.history-path | get history.command_line | to text | fzf +s --tac | str trim | |
| where $it =~ $buffer | |
| each {|v| {value: ($v | str trim)} } | |
} | |
} | |
{ | |
name: fzf_history_menu_nu_ui | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#66ff66" | |
selected_text: {fg: "#66ff66" attr: r} | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
open $nu.history-path | get history.command_line | to text | |
| fzf -f $buffer | |
| lines | |
| each {|v| {value: ($v | str trim)} } | |
} | |
} | |
{ | |
name: fzf_dir_menu_nu_ui | |
only_buffer_difference: true | |
marker: "# " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#66ff66" | |
selected_text: {fg: "#66ff66" attr: r} | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
ls $env.PWD | where type == dir | |
| sort-by name | get name | to text | |
| fzf -f $buffer | |
| each {|v| {value: ($v | str trim)} } | |
} | |
} | |
{ | |
name: commands_menu | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each {|it| {value: $it.name description: $it.usage} } | |
} | |
} | |
{ | |
name: vars_menu | |
only_buffer_difference: true | |
marker: "V " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope variables | |
| where name =~ $buffer | |
| sort-by name | |
| each {|it| {value: $it.name description: $it.type} } | |
} | |
} | |
{ | |
name: commands_with_description | |
only_buffer_difference: true | |
marker: "# " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each {|it| {value: $it.name description: $it.usage} } | |
} | |
} | |
{ | |
name: abbr_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope aliases | |
| where name == $buffer | |
| each {|it| {value: $it.expansion} } | |
} | |
} | |
# session menu | |
{ | |
name: history_menu_by_session | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: list | |
page_size: 10 | |
# layout: columnar | |
# columns: 4 | |
# col_width: 20 | |
# col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
history -l | |
| where session_id == (history session) | |
| select command | |
| where command =~ $buffer | |
| each {|it| {value: $it.command} } | |
| reverse | |
| uniq | |
} | |
} | |
] | |
# endregion | |
# region: keybindings | |
# mac keyboard | |
# home = fn + left | |
# end = fn + right | |
# pageup = fn + up | |
# pagedown = fn + down | |
# backspace = delete | |
# delete = fn + delete | |
keybindings: [ | |
{ | |
name: open_command_editor | |
modifier: control | |
keycode: char_o | |
mode: [emacs vi_normal vi_insert] | |
event: {send: openeditor} | |
} | |
{ | |
name: clear_everything | |
modifier: control | |
keycode: char_l | |
mode: emacs | |
event: [ | |
{send: clearscrollback} | |
] | |
} | |
{ | |
name: insert_newline | |
modifier: shift | |
keycode: enter | |
mode: emacs | |
event: {edit: insertnewline} | |
} | |
{ | |
name: completion_menu | |
modifier: none | |
keycode: tab | |
mode: emacs | |
event: { | |
until: [ | |
{send: menu name: completion_menu} | |
{send: menunext} | |
] | |
} | |
} | |
{ | |
name: completion_previous | |
modifier: shift | |
keycode: backtab | |
mode: emacs | |
event: {send: menuprevious} | |
} | |
{ | |
name: insert_last_token | |
modifier: alt | |
keycode: char_. | |
mode: emacs | |
event: [ | |
{edit: insertstring value: " !$"} | |
{send: enter} | |
] | |
} | |
{ | |
name: complete_hint_chunk | |
modifier: alt | |
keycode: right | |
mode: emacs | |
event: { | |
until: [ | |
{send: historyhintwordcomplete} | |
{edit: movewordright} | |
] | |
} | |
} | |
{ | |
name: un_complete_hint_chunk | |
modifier: alt | |
keycode: left | |
mode: emacs | |
event: [ | |
{edit: backspaceword} | |
] | |
} | |
{ | |
name: delete-word | |
modifier: control | |
keycode: backspace | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{edit: backspaceword} | |
] | |
} | |
} | |
{ | |
name: trigger-history-menu | |
modifier: control | |
keycode: char_x | |
mode: emacs | |
event: { | |
until: [ | |
{send: menu name: history_menu} | |
{send: menupagenext} | |
] | |
} | |
} | |
# ctrl+shift+x isn't even seen on mac | |
{ | |
name: trigger-history-previous | |
modifier: control | |
keycode: char_z | |
mode: emacs | |
event: { | |
until: [ | |
{send: menupageprevious} | |
{edit: undo} | |
] | |
} | |
} | |
{ | |
name: change_dir_with_fzf | |
modifier: control | |
keycode: char_f | |
mode: emacs | |
event: { | |
send: executehostcommand | |
cmd: "cd (ls | where type == dir | each { |it| $it.name} | str join (char nl) | fzf | decode utf-8 | str trim)" | |
} | |
} | |
{ | |
name: complete_in_cd | |
modifier: none | |
keycode: f2 | |
mode: emacs | |
event: [ | |
{edit: clear} | |
{edit: insertString value: "./"} | |
{send: Menu name: completion_menu} | |
] | |
} | |
# { | |
# name: reload_config | |
# modifier: none | |
# keycode: f5 | |
# mode: emacs | |
# event: { | |
# send: executehostcommand, | |
# cmd: $"source '($nu.config-path)'" | |
# } | |
# } | |
{ | |
name: reload_config | |
modifier: none | |
keycode: f5 | |
mode: [emacs vi_insert vi_normal] | |
event: [ | |
{edit: clear} | |
{send: executehostcommand cmd: $"source ($nu.env-path); source ($nu.config-path)"} | |
# { | |
# edit: insertString | |
# value: $"source ($nu.env-path); source ($nu.config-path)" | |
# } | |
# { send: Enter } | |
] | |
} | |
{ | |
name: clear | |
modifier: none | |
keycode: esc | |
mode: emacs | |
event: {edit: clear} | |
} | |
{ | |
name: test_fkeys | |
modifier: none | |
keycode: f3 | |
mode: emacs | |
event: [ | |
{edit: clear} | |
{edit: insertstring value: $"($env.PWD)"} | |
] | |
} | |
# { | |
# name: alias_menu | |
# modifier: control | |
# keycode: space | |
# mode: [emacs, vi_normal, vi_insert] | |
# event: { send: menu name: alias_menu } | |
# } | |
{ | |
name: abbr | |
modifier: control | |
keycode: space | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{send: menu name: abbr_menu} | |
{edit: insertchar value: ' '} | |
] | |
} | |
{ | |
name: fzf_edit | |
modifier: control | |
keycode: char_d | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ | |
send: executehostcommand | |
cmd: "do { |$file| if (not ($file | is-empty)) { nvim $file } } (fzf | str trim)" | |
} | |
] | |
} | |
# Keybindings used to trigger the user defined menus | |
# { | |
# name: history_menu | |
# modifier: control | |
# keycode: char_r | |
# mode: emacs | |
# event: { send: menu name: history_menu } | |
# } | |
{ | |
name: "history_menu_by_session" | |
modifier: alt | |
keycode: char_r | |
mode: emacs | |
event: {send: menu name: history_menu_by_session} | |
} | |
# { | |
# name: fuzzy_history | |
# modifier: control | |
# keycode: char_r | |
# mode: emacs | |
# event: { | |
# send: executehostcommand | |
# cmd: "commandline (history | each { |it| $it.command } | uniq | reverse | str join (char nl) | fzf --layout=reverse --height=40% -q (commandline) | decode utf-8 | str trim)" | |
# } | |
# } | |
# { | |
# name: fuzzy_history_fzf | |
# modifier: control | |
# keycode: char_r | |
# mode: [emacs , vi_normal, vi_insert] | |
# event: { | |
# send: executehostcommand | |
# cmd: "commandline ( | |
# history | |
# | each { |it| $it.command } | |
# | uniq | |
# | reverse | |
# | str join (char -i 0) | |
# | fzf --read0 --tiebreak=chunk --layout=reverse --multi --preview='echo {..}' --preview-window='bottom:3:wrap' --bind alt-up:preview-up,alt-down:preview-down --height=70% -q (commandline) | |
# | decode utf-8 | |
# | str trim | |
# )" | |
# } | |
# } | |
{ | |
name: fuzzy_history | |
modifier: control | |
keycode: char_r | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ | |
send: ExecuteHostCommand | |
cmd: "do { | |
$env.SHELL = /usr/bin/bash | |
commandline edit -r ( | |
history | |
| get command | |
| reverse | |
| uniq | |
| str join (char -i 0) | |
| fzf --scheme=history --read0 --layout=reverse --height=40% --bind 'tab:change-preview-window(right,70%|right)' -q (commandline) --preview='echo -n {} | nu --stdin -c \'nu-highlight\'' | |
| decode utf-8 | |
| str trim | |
) | |
}" | |
} | |
] | |
} | |
{ | |
name: fuzzy_dir | |
modifier: control | |
keycode: char_s | |
mode: emacs | |
event: { | |
send: executehostcommand | |
cmd: "commandline edit -a (ls **/* | where type == dir | get name | to text | fzf -q (commandline) | str trim);commandline set-cursor --end" | |
} | |
} | |
{ | |
name: fzf_dir_menu_nu_ui | |
modifier: control | |
keycode: char_n | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: fzf_dir_menu_nu_ui} | |
} | |
{ | |
#notworking | |
name: fzf_history_menu_fzf_ui | |
modifier: control | |
keycode: char_e | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: fzf_history_menu_fzf_ui} | |
} | |
{ | |
name: fzf_history_menu_nu_ui | |
modifier: control | |
keycode: char_w | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: fzf_history_menu_nu_ui} | |
} | |
{ | |
name: commands_menu | |
modifier: control | |
keycode: char_t | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: commands_menu} | |
} | |
{ | |
name: vars_menu | |
modifier: control | |
keycode: char_y | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: vars_menu} | |
} | |
{ | |
name: commands_with_description | |
modifier: control | |
keycode: char_u | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: commands_with_description} | |
} | |
{ | |
name: trigger-help-menu | |
modifier: control | |
keycode: char_q | |
mode: emacs | |
event: { | |
until: [ | |
{send: menu name: help_menu} | |
{send: menunext} | |
] | |
} | |
} | |
# for pr 11535 copy-n-paste | |
{ | |
name: copy_selection | |
modifier: control_shift | |
keycode: char_c | |
mode: emacs | |
event: {edit: copyselection} | |
} | |
{ | |
name: cut_selection | |
modifier: control_shift | |
keycode: char_x | |
mode: emacs | |
event: {edit: cutselection} | |
} | |
{ | |
name: select_all | |
modifier: control_shift | |
keycode: char_a | |
mode: emacs | |
event: {edit: selectall} | |
} | |
{ | |
name: paste | |
modifier: control_shift | |
keycode: char_v | |
mode: emacs | |
event: {edit: pastecutbufferbefore} | |
} | |
{ | |
name: ide_completion_menu | |
modifier: control | |
keycode: char_n | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{send: menu name: ide_completion_menu} | |
{send: menunext} | |
{edit: complete} | |
] | |
} | |
} | |
] | |
# endregion | |
} | |
# endregion | |
# Directories to search for scripts when calling source or use | |
# | |
# By default, <nushell-config-dir>/scripts is added | |
const NU_LIB_DIRS = [ | |
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts | |
'C:\Users\us991808\source\repos\forks\nu_scripts' | |
($nu.config-path | path dirname) | |
($nu.data-dir | path join 'completions') # default home for nushell completions | |
] | |
# Directories to search for plugin binaries when calling register | |
# | |
# By default, <nushell-config-dir>/plugins is added | |
const NU_PLUGIN_DIRS = [ | |
($nu.config-path | path dirname | path join 'plugins') | |
] | |
# Custom Commands | |
source defs.nu | |
# source tabline.nu | |
# prompt | |
use modules\prompt\oh-my.nu git_prompt | |
$env.PROMPT_COMMAND = {|| (git_prompt).left_prompt } | |
$env.PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt } | |
$env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) { $"(ansi green_bold)\n❯ (ansi reset)" } else { $"(ansi red_bold)\n❯ (ansi reset)" } } | |
$env.TRANSIENT_PROMPT_COMMAND = "" | |
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt } | |
$env.TRANSIENT_PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) { $"(ansi light_yellow_bold)❯ (ansi reset)" } else { $"(ansi light_red_bold)❯ (ansi reset)" } } | |
$env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e {fg: '#CB4B16'})(char -u '276f')(ansi -e {fg: '#CACA02'})(char -u '276f')(ansi -e {fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
# use modules\prompt\jalon-git.nu * | |
# $env.PROMPT_COMMAND = {|| full-left-prompt } | |
# $env.PROMPT_COMMAND_RIGHT = {|| "" } | |
# oh-my-posh transient prompt | |
# source ~\.oh-my-posh.nu | |
# source prompt\oh-my-v2.nu | |
# $env.PROMPT_COMMAND = { (get_prompt 24bit).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 24bit).right_prompt } | |
# $env.PROMPT_INDICATOR = { "" } | |
# use prompt\panache-git.nu prompt-with-panache | |
# $env.PROMPT_COMMAND = { prompt-with-panache } | |
# $env.PROMPT_INDICATOR = { "" } | |
# $env.PROMPT_COMMAND_RIGHT = { "" } | |
# external completions | |
use custom-completions\cargo\cargo-completions.nu * | |
use aliases\git\git-aliases.nu * | |
use custom-completions\git\git-completions.nu * | |
use custom-completions\gh\gh-completions.nu * | |
use custom-completions\rustup\rustup-completions.nu * | |
# other modules | |
use std-rfc/tables aggregate | |
# Microsoft Visual Studio env vars | |
#use modules/virtual_environments/nu_msvs/nu_msvs.nu | |
#nu_msvs activate --host x64 --target x64 | |
# get_weather | |
# use modules\weather\get-weather.nu get_weather | |
# temperature conversions | |
# source sourced\temp.nu | |
# zoxide | |
source ~/.zoxide.nu | |
hide LS_COLORS | |
# hide-env LS_COLORS | |
# setup completer | |
# This overrides the default completer and enables it | |
# source ~/.cache/carapace/init.nu | |
# atuin | |
# source ~\.local\share\atuin\init.nu | |
# $env.Path = ($env.Path | each {|r| $r | split row (char esep)} | flatten | uniq | str join (char esep)) | |
$env.Path = ($env.Path | uniq | filter { path exists }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Hello, from defs.nu" | |
# check for env var exists | |
# "FOO" | env exists? | |
def "env exists?" [] { | |
each {|s| $s in (env).name } | |
} | |
let bn = (ansi {fg: '#ffffff' bg: '#000000'}) | |
let bb = (ansi {fg: '#ffffff' bg: '#555555'}) | |
let rn = (ansi {fg: '#ffffff' bg: '#AA0000'}) | |
let rb = (ansi {fg: '#ffffff' bg: '#FF5555'}) | |
let gn = (ansi {fg: '#000000' bg: '#00AA00'}) | |
let gb = (ansi {fg: '#000000' bg: '#55FF55'}) | |
let yn = (ansi {fg: '#000000' bg: '#AAAA00'}) | |
let yb = (ansi {fg: '#000000' bg: '#FFFF55'}) | |
let un = (ansi {fg: '#ffffff' bg: '#0000AA'}) | |
let ub = (ansi {fg: '#ffffff' bg: '#5555FF'}) | |
let mn = (ansi {fg: '#ffffff' bg: '#AA00AA'}) | |
let mb = (ansi {fg: '#ffffff' bg: '#FF55FF'}) | |
let cn = (ansi {fg: '#000000' bg: '#00AAAA'}) | |
let cb = (ansi {fg: '#000000' bg: '#55FFFF'}) | |
let wn = (ansi {fg: '#000000' bg: '#AAAAAA'}) | |
let wb = (ansi {fg: '#000000' bg: '#FFFFFF'}) | |
let s = 'XXXXXX' | |
let r = (ansi reset) | |
def standard-colors [] { | |
[ | |
[color normal bold]; | |
[Black $"($bn)($s)($r)" $"($bb)($s)($r)"] | |
[Red $"($rn)($s)($r)" $"($rb)($s)($r)"] | |
[Green $"($gn)($s)($r)" $"($gb)($s)($r)"] | |
[Yellow $"($yn)($s)($r)" $"($yb)($s)($r)"] | |
[Blue $"($un)($s)($r)" $"($ub)($s)($r)"] | |
[Magenta $"($mn)($s)($r)" $"($mb)($s)($r)"] | |
[Cyan $"($cn)($s)($r)" $"($cb)($s)($r)"] | |
[White $"($wn)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# https://www.ditig.com/256-colors-cheat-sheet | |
# 38;5;<num> for these palleted index numbers | |
# Xterm 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #800000 #008000 #808000 #000080 #800080 #008080 #C0C0C0 | |
# Xterm 8 9 10 11 12 13 14 15 | |
# Bold #808080 #FF0000 #00FF00 #FFFF00 #0000FF #FF00FF #00FFFF #FFFFFF | |
def wide-colors [] { | |
# Code 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #AA0000 #00AA00 #AAAA00 #0000AA #AA00AA #00AAAA #AAAAAA | |
# Bold #555555 #FF5555 #55FF55 #FFFF55 #5555FF #FF55FF #55FFFF #FFFFFF | |
# [code '0' '1' '2' '3' '4' '5' '6' '7']; | |
[ | |
[name black red green yellow blue magenta cyan white]; | |
[normal $"($bn)($s)($r)" $"($rn)($s)($r)" $"($gn)($s)($r)" $"($yn)($s)($r)" $"($un)($s)($r)" $"($mn)($s)($r)" $"($cn)($s)($r)" $"($wn)($s)($r)"] | |
[bold $"($bb)($s)($r)" $"($rb)($s)($r)" $"($gb)($s)($r)" $"($yb)($s)($r)" $"($ub)($s)($r)" $"($mb)($s)($r)" $"($cb)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# get the terminal size with ansi escape codes | |
def terminal-size [] { | |
let sz = (input (ansi size) --bytes-until-any 'R' --suppress-output) | |
# $sz should look like this | |
# Length: 9 (0x9) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5b 33 38 3b 31 35 30 52 •[38;150R | |
# let sz_len = ($sz | size).bytes | |
let sz_len = ($sz | str length) | |
# so let's skip the esc[ and R | |
# let r = (for x in 2..($sz_len - 2) { | |
# # This substring removes the 0x added by fmt | |
# char -u (($sz | get $x | into int | fmt).lowerhex | str substring '2,') | |
# } | str join) | |
let r = ($sz | str substring 1..($sz_len - 1)) | |
# $r should look like 38;150 | |
let size = ($r | split row ';') | |
# output in record syntax | |
{ | |
columns: ($size | get 1 | into int) | |
rows: ($size | get 0 | into int) | |
} | |
} | |
# get background color with x11 ansi escapes | |
# have to hit ctrl+g after the statement to get the value in $x | |
# let x = input $"(ansi -o '11;?')(char bel)" --bytes-until (char bel) | |
# when input = rgb:4_numbers/4_numbers/4_numbers like rgb:1919/1313/2323 | |
# this means 16-bit rgb components. 16^4 means four hex digits. FFFF is 65535 | |
# 48-bit color. it could be 1 number 4-bits, 2 8-bits, 3 12-bits, 4 16-bits | |
# #3a7 is the same as #3000a0007000. | |
# refernce https://www.x.org/releases/X11R7.7/doc/man/man7/X.7.xhtml#heading11 | |
# mine was rgb:1919/1313/2323 | |
# (('1919' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# (('1313' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# (('2323' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# or | |
# 0x1919 / 0x100 | math round | |
# 0x1313 / 0x100 | math round | |
# 0x2323 / 0x100 | math round | |
# Get the background color through ansi escape sequences | |
def get-bg [] { | |
# get the response from the ansi escape sequence from the terminal | |
# have to hit control+g in kitty to get value in $bg | |
let bg = (input $"(ansi -o '11;?')(ansi st)" --bytes-until-any (ansi st) --suppress-output) | |
# $bg should look like this | |
# assumes output of the form ":0000/0000/0000" | |
# it should really look like "esc]11;rgb:0000/0000/0000esc\", not sure why it doesn't | |
# Length: 26 (0x1a) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 31 39 31 39 2f 31 33 •]11;rgb:1919/13 | |
# 00000010: 31 33 2f 32 33 32 33 1b 5c 07 13/2323•\• | |
# jt's output | |
# Length: 24 (0x18) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 33 66 33 66 2f 33 66 •]11;rgb:3f3f/3f | |
# 00000010: 33 66 2f 33 66 33 66 07 3f/3f3f• | |
# so let's skip the prefix and suffix and just get | |
# 1919/1313/2323 | |
# let rgb_string = ($bg | split chars | slice 9..22 | str join) | |
# TODO figure how other ways that string can start so we can programmatically | |
# calculate the start_index better. It's probably not always \x1b]11;rgb: | |
# let start_index = 9 | |
# let end_index = ($bg | bytes index-of 0x[1b 5c]) | |
# get the rgb values | |
let start_index = ($bg | str index-of ':' | into int) + 1 | |
let end_index = $bg | str length | |
# let term_data = $bg | into binary | bytes at $start_index..$end_index | |
# let rgb_string = ($term_data | decode utf-8) | |
let rgb_string = $bg | str substring $start_index..$end_index | |
# let bg_len = ($bg | size).bytes | |
# # so let's skip the prefix and suffix and just get | |
# # 1919/1313/2323 | |
# let rgb_string = (for x in 9..($bg_len - 4) { | |
# # This substring removes the 0x added by fmt after conversion to char | |
# char -u (($bg | get $x | into int | fmt).lowerhex | str substring '2,') | |
# } | str join) | |
# split the rgb string into the individual values | |
let rgb = $rgb_string | split row '/' | |
let r = $rgb | get 0 | |
let g = $rgb | get 1 | |
let b = $rgb | get 2 | |
# ('1313' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# convert the rgb values to hex | |
let red = (($r | into int -r 16) / 256 | math round | fmt).lowerhex | |
let green = (($g | into int -r 16) / 256 | math round | fmt).lowerhex | |
let blue = (($b | into int -r 16) / 256 | math round | fmt).lowerhex | |
# output in record syntax | |
{ | |
red: $red | |
green: $green | |
blue: $blue | |
hex: $"(ansi default)#($red | str substring 2.. | fill -a r -c 0 -w 2)($green | str substring 2.. | fill -a r -c 0 -w 2)($blue | str substring 2.. | fill -a r -c 0 -w 2)(ansi reset)" | |
rgb: $"RGB(char lp)(($red | into int | fmt).display), (($green | into int | fmt).display), (($blue | into int | fmt).display)(char rp)" | |
} | |
} | |
# Clear the screen with ansi escapes | |
def cls [] { | |
ansi cls | |
} | |
# Full term reset, cls, clear buffer, attributes off, | |
def clsterm [] { | |
$"(ansi esc)c(ansi clsb)(ansi cls)(ansi reset)(ansi home)" | |
} | |
# good for things like this | |
# ps | where name =~ Firefox | get mem | sum | |
def sum [] { | |
reduce {|acc, item| $acc + $item } | |
} | |
# written by Kubouch for virtualenv | |
def is-string [ | |
x # value to check to see if it's a string | |
] { | |
($x | describe) == "string" | |
} | |
def has-env [name: string] { | |
$name in (env).name | |
} | |
def --env goto [] { | |
let input = $in | |
cd ( | |
if ($input | path type) == file { | |
($input | path dirname) | |
} else { | |
$input | |
} | |
) | |
} | |
def cargo_tests [] { | |
cargo nextest run --all --all-features | |
} | |
def cargo_clippy [] { | |
cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err | |
} | |
# alias the built-in ls command to ls-builtins | |
alias ls-builtin = ls | |
# alias ls-builtin = ls | |
# alias lss to the new ls custom command | |
# alias ls = lss | |
# List the filenames, sizes, and modification times of items in a directory. | |
def ls [ | |
--all (-a), # Show hidden files | |
--long (-l), # Get all available columns for each entry (slower; columns are platform-dependent) | |
--short-names (-s), # Only print the file names, and not the path | |
--full-paths (-f), # display paths as absolute paths | |
--du (-d), # Display the apparent directory size ("disk usage") in place of the directory metadata size | |
--directory (-D), # List the specified directory itself instead of its contents | |
--mime-type (-m), # Show mime-type in type column instead of 'file' (based on filenames only; files' contents are not examined) | |
--threads (-t), # Use multiple threads to list contents. Output will be non-deterministic. | |
...pattern: glob, # The glob pattern to use. | |
]: [nothing -> table] { | |
let pattern = if ($pattern | is-empty) { ['.'] } else { $pattern } | |
( | |
ls-builtin | |
--all=$all | |
--long=$long | |
--short-names=$short_names | |
--full-paths=$full_paths | |
--du=$du | |
--directory=$directory | |
--mime-type=$mime_type | |
--threads=$threads | |
...$pattern | |
) | sort-by type name -i | |
} | |
# # alias the built-in ls command to ls-builtins | |
# alias ls-builtin = ls | |
# # alias lss to the new ls custom command | |
# alias ls = lss | |
def stars [] { | |
http get https://api.github.com/repos/nushell/nushell | get stargazers_count | |
} | |
def --env hide_prompt [] { | |
hide-env PROMPT_COMMAND | |
hide-env PROMPT_COMMAND_RIGHT | |
hide-env PROMPT_INDICATOR | |
} | |
def show_banner [] { | |
let ellie = [ | |
" __ ," | |
" .--()°'.'" | |
"'|, . ,' " | |
' !_-(_\ ' | |
] | |
let s = (sys) | |
print $"(ansi reset)(ansi green)($ellie.0)" | |
print $"(ansi green)($ellie.1) (ansi yellow) (ansi yellow_bold)Nushell (ansi reset)(ansi yellow)v(version | get version)(ansi reset)" | |
print $"(ansi green)($ellie.2) (ansi light_blue) (ansi light_blue_bold)RAM (ansi reset)(ansi light_blue)($s.mem.used) / ($s.mem.total)(ansi reset)" | |
print $"(ansi green)($ellie.3) (ansi light_purple)ﮫ (ansi light_purple_bold)Uptime (ansi reset)(ansi light_purple)($s.host.uptime)(ansi reset)" | |
} | |
# load visual studio environment | |
def --env vsenv [] { | |
print "Loading Visual Studio Environment" | |
let vsdev = (cmd /c `c:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat` -arch=amd64 -host_arch=amd64 &set) | |
let vars = $vsdev | lines -s | each {|var| parse "{KEY}={VAL}" } | flatten | where KEY != PWD | |
$vars | reduce -f {} {|i, acc| $acc | upsert $i.KEY $i.VAL } | load-env | |
print "Complete" | |
} | |
# get the environment details | |
def "env details" [] { | |
let e = ($env | reject config | transpose key value) | |
$e | each {|r| | |
let is_envc = ($r.key == ENV_CONVERSIONS) | |
let is_closure = ($r.value | describe | str contains 'closure') | |
let is_list = ($r.value | describe | str contains 'list') | |
if $is_envc { | |
echo [ | |
[key value]; | |
[ | |
($r.key) | |
( | |
$r.value | transpose key value | each {|ec| | |
let to_string = ($ec.value | get to_string | view source $in | nu-highlight) | |
let from_string = ($ec.value | get from_string | view source $in | nu-highlight) | |
echo ({'ENV_CONVERSIONS': {($ec.key): {'to_string': ($to_string) 'from_string': ($from_string)}}}) | |
} | |
) | |
] | |
] | |
} else if $is_closure { | |
let closure_value = (view source ($env | get $r.key) | nu-highlight) | |
echo [[key value]; [($r.key) ($closure_value)]] | |
} else if $is_list { | |
let list_value = ($env | get $r.key | split row (char esep)) | |
echo [[key value]; [($r.key) ($list_value)]] | |
} else { | |
echo [[key value]; [($r.key) ($r.value)]] | |
} | |
} | |
} | |
def env [] { env details | flatten | table -e } | |
# get windows service status | |
def get-win-svc [] { | |
sc queryex type=service state=all | collect {|x| | |
$x | parse -r '(?m)SERVICE_NAME:\s*(?<svc>\w*)\s*DISPLAY_NAME:\s*(?<dsp>.*)\s*TYPE\s*:\s*(?<type>[\da-f]*)\s*(?<typename>\w*)?\s*\s*STATE\s*:\s*(?<state>\d)\s*(?<status>\w*)\s*(?<state_opts>\(.*\))?\s*?WIN32_EXIT_CODE\s*:\s*(?<exit>\d*).*\s*SERVICE_EXIT_CODE\s*:\s*(?<svc_exit>\d)\s*.*\s*CHECKPOINT\s*:\s*(?<chkpt>.*)\s*WAIT_HINT\s*:\s(?<wait>.*)\s*PID\s*:\s*(?<pid>\d*)\s*FLAGS\s*:\s(?<flags>.*)?' | upsert status {|s| | |
if $s.status == RUNNING { | |
$"(ansi green)●(ansi reset)" | |
} else { | |
$"(ansi red)●(ansi reset)" | |
} | |
} | into int state exit svc_exit chkpt wait pid | |
} | |
} | |
# Only list the nushell environment variables | |
def env-nu [] { | |
$env | transpose key value | each {|r| | |
if ($r.value | describe) != string { | |
$r | |
} | |
} | transpose -ird | |
} | |
# Show a summarized table of nushell startup times | |
def startup-stats [] { | |
open ~/.local/share/nushell/startup-times.nuon | where build == release | group-by commit --to-table | rename commit data | update commit {|c| | |
$c.commit | str substring 0..7 | |
} | upsert perf {|r| | |
if ($r.data | length) > 3 { | |
# This throws out outliers by removing the top 3 slowest startup times | |
$r.data.time | sort | slice 0..(-3) | math avg | |
} else { | |
$r.data.time | math avg | |
} | |
} | upsert start_date {|s| | |
$s.data.date | sort | math min | format date '%Y-%m-%d' | |
} | upsert end_date {|e| | |
$e.data.date | sort | math max | format date '%Y-%m-%d' | |
} | upsert num_startups {|n| | |
$n.data | length | |
} | upsert bytes_loaded {|b| | |
$b.data.bytes_loaded | math avg | |
} | upsert perf_per_byte {|s| | |
# This throws out outliers by removing the top 3 slowest startup times | |
# sum_of_time / sum_of_bytes_loaded | |
if ($s.data.time | length) > 3 { | |
(($s.data.time | sort | slice 0..(-3) | math sum) / ($s.data.bytes_loaded | math sum)) | |
} else { | |
(($s.data.time | math sum) / ($s.data.bytes_loaded | math sum)) | |
} | |
} | sort-by start_date | |
} | |
# fzf with help commands | |
def helps [] { | |
help commands | get name | str join "\n" | fzf --preview-window 'up,60%,border-bottom,+{2}+3/3,~1' --preview 'nu -l -c "help {1} {2}"' | |
# https://github.com/junegunn/fzf/blob/master/ADVANCED.md | |
# The value of --preview-window option consists of 5 components delimited by , | |
# up — Position of the preview window | |
# 60% — Size of the preview window | |
# border-bottom — Preview window border only on the bottom side | |
# +{2}+3/3 — Scroll offset of the preview contents | |
# ~3 — Fixed header | |
# Let's break down the latter two. We want to display the bat output in the preview window with a certain scroll offset so that the matching line is positioned near the center of the preview window. | |
# +{2} — The base offset is extracted from the second token | |
# +3 — We add 3 lines to the base offset to compensate for the header part of bat output | |
# ───────┬────────────────────────────────────────────────────────── | |
# │ File: CHANGELOG.md | |
# ───────┼────────────────────────────────────────────────────────── | |
# 1 │ CHANGELOG | |
# 2 │ ========= | |
# 3 │ | |
# 4 │ 0.26.0 | |
# 5 │ ------ | |
# /3 adjusts the offset so that the matching line is shown at a third position in the window | |
# ~3 makes the top three lines fixed header so that they are always visible regardless of the scroll offset | |
# help commands | |
# | get name | |
# | str join "\n" | |
# | fzf --preview $"nu --config ($nu.config-path) --env-config ($nu.env-path) -c 'help {}'" | |
} | |
# Check how many downloads nushell has had | |
def get_github_downloads [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | get assets | flatten | select name download_count created_at | update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S' } | |
} | |
# Get brew downloads for the past 30 days | |
def get_brew_downloads [] { | |
let brew_dl = (http get https://formulae.brew.sh/api/formula/nushell.json) | |
let macos_dl = ($brew_dl | get analytics.install.30d.nushell) | |
# let linux_dl = ($brew_dl | get analytics-linux.install.30d.nushell) | |
# [[os downloads]; [macos $macos_dl] [linux $linux_dl]] | |
[[os downloads]; [macos $macos_dl]] | |
} | |
# Get cargo downloads for crate | |
def "get_cargo_downloads" [crate: string] { | |
# alternatively scrape this | |
# http get https://crates.io/api/v1/crates/nu | |
# http get https://crates.io/api/v1/crates/nu/0.76.0 | get version | |
cargo info $crate | |
| lines | |
| parse "{key}: {value}" | |
| str trim | |
| transpose -r | |
| into record | |
| merge ( | |
{ | |
versions: ( | |
cargo info $crate -VV | |
| lines -s | |
| skip 1 | |
| parse --regex '(?<version>\d+\.\d+\.\d+)\s+(?<released>.* ago)\s+(?<downloads>\d+)' | |
| into int downloads | |
) | |
} | |
) | |
} | |
def get_all_nu_downloads [version = "0.76.0"] { | |
# let github_dl = (get_github_downloads | where name =~ $version | get download_count | math sum) | |
let github_dl = (get_github_downloads | where name =~ $version) | |
let github_sum = ($github_dl | get download_count | math sum) | |
let gh_apple = ($github_dl | where name =~ "apple" | get download_count | math sum) | |
let gh_linux = ($github_dl | where name =~ "linux" | get download_count | math sum) | |
let gh_windows = ($github_dl | where name =~ "windows" | get download_count | math sum) | |
let brew_dl = (get_brew_downloads | get downloads | math sum) | |
let cargo_dl = (get_cargo_downloads nu | get versions | where version =~ $version | get downloads.0) | |
[ | |
[source downloads]; | |
[github $github_sum] | |
["\tgh_apple" $gh_apple] | |
["\tgh_linux" $gh_linux] | |
["\tgh_windows" $gh_windows] | |
[brew $brew_dl] | |
[cargo $cargo_dl] | |
[sum ($github_sum + $brew_dl + $cargo_dl)] | |
] | |
} | |
# get the system uptime | |
def uptime [] { | |
# sys | get host | get uptime | |
(sys host).uptime | |
} | |
# get the terminals default 16 colors. not supported on all terminals. | |
def get-terminal-colors [] { | |
let color_00 = (input $"(ansi -o '4;0;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_01 = (input $"(ansi -o '4;1;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_02 = (input $"(ansi -o '4;2;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_03 = (input $"(ansi -o '4;3;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_04 = (input $"(ansi -o '4;4;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_05 = (input $"(ansi -o '4;5;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_06 = (input $"(ansi -o '4;6;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_07 = (input $"(ansi -o '4;7;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_08 = (input $"(ansi -o '4;8;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_09 = (input $"(ansi -o '4;9;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_10 = (input $"(ansi -o '4;10;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_11 = (input $"(ansi -o '4;11;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_12 = (input $"(ansi -o '4;12;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_13 = (input $"(ansi -o '4;13;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_14 = (input $"(ansi -o '4;14;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_15 = (input $"(ansi -o '4;15;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
# goes through 4;255;? | |
[ | |
$color_00 | |
$color_01 | |
$color_02 | |
$color_03 | |
$color_04 | |
$color_05 | |
$color_06 | |
$color_07 | |
$color_08 | |
$color_09 | |
$color_10 | |
$color_11 | |
$color_12 | |
$color_13 | |
$color_14 | |
$color_15 | |
] | each {|col| | |
let rgb = $col | split row : | get 1 | split row / | |
# 16bit rgb to 8bit = 0xe7e7 | bits and 0x00ff | |
let red = ($"0x($rgb | get 0)" | into int | bits and 0x00ff) | |
let green = ($"0x($rgb | get 1)" | into int | bits and 0x00ff) | |
let blue = ($"0x($rgb | get 2)" | into int | bits and 0x00ff) | |
let red_hx = ($red | fmt).lowerhex | str substring 2.. | |
let green_hx = ($green | fmt).lowerhex | str substring 2.. | |
let blue_hx = ($blue | fmt).lowerhex | str substring 2.. | |
{ | |
red: $red_hx | |
green: $green_hx | |
blue: $blue_hx | |
hex: $"#($red_hx)($green_hx)($blue_hx)" | |
rgb: $"RGB(char lp)($red), ($green), ($blue)(char rp)" | |
} | |
} | |
} | |
# Deletes a history entry. | |
def 'history remove-item' [ | |
id: int = 0 # the id of the history entry to delete | |
--last # delete the last entry, ignore the id, if passed | |
] { | |
if $last { | |
open $nu.history-path | query db $"delete from history where id = \(select id from \(select id from history where session_id = (history session) order by id desc LIMIT 2) order by id asc LIMIT 1)" | |
} else { | |
if $id == 0 { | |
echo "You must pass an id or use --last" | |
exit 1 | |
} | |
open $nu.history-path | query db $"delete from history where id = ($id)" | |
} | |
null | |
} | |
# Find files using ripgrep (CDNcred from Discord) | |
def rgfind [file] { rg --files - . --no-messages | rg -S $file } | |
# Get my external ip address information (CDNcred + NotThe Dr01ds from Discord) | |
def whatsmyip [] { http get -H {User-agent: "curl"} http://ipinfo.io/what-is-my-ip } | |
# Find all indexes of a substring in a string. | |
def "str indices-of" [pattern: string]: string -> list<int> { | |
let searchString = $in | |
# since it's using regex, we need to escape the pattern. | |
# other patterns also probably need escaping like ^$*+?()[{\| | |
let pattern = if $pattern == "." { | |
"\\." | |
} else { | |
$pattern | |
} | |
let parsePattern = ['(?P<matches>' $pattern ')'] | str join | |
let matches = ($searchString | parse -r $parsePattern | get matches) | |
$matches | reduce -f [] {|it, acc| | |
let match = $it | |
let startSearchFrom = ( | |
if $acc == [] { 0 } else { $acc | last | get end } | |
) | |
let begin = ($searchString | str index-of $match --range ($startSearchFrom)..) | |
let end = $begin + ($match | str length) | |
[ | |
...$acc | |
{ | |
match: $match | |
begin: $begin | |
end: $end | |
} | |
] | |
} | |
} | |
def "get help" [] { | |
do { | |
$env.SHELL = 'c:\Users\us991808\.cargo\bin\nu.exe' | |
help commands | where command_type == built-in | |
| each {|c| | |
let search_terms = if ($c.search_terms == "") { "" } else { $"\(($c.search_terms))" } | |
let category = if ($c.category == "") { "" } else { $"\(Category: ($c.category))" } | |
$"(ansi white)($c.name?):(ansi light_blue) ($c.usage?) (ansi blue)($search_terms) ($category)(ansi reset)" | |
} | |
| to text | |
| fzf --ansi --tiebreak=begin,end,chunk --bind 'tab:change-preview-window(right,70%|right)' --preview="^echo {+1} {+2} {+3} | nu --stdin -c 'help ($in | parse `{c}:{u}` | get c.0)'" --exact | |
} | |
} | |
# simple command to shrink git repos | |
def shrink-git [] { | |
let folders = ls | where type == dir | |
$folders | each {|dir| | |
cd $dir.name | |
try { | |
ls -D .git | length | ignore | |
print $"(ansi red)Repacking (ansi green)($dir.name)(ansi reset)" | |
git repack -a -d -f --depth=250 --window=250 | ignore | |
} catch { | |
print $"(ansi purple)Skipping (ansi green)($dir.name)(ansi reset)" | |
} | |
} | |
} | |
# diff two tables (by devyn) | |
def table-diff [ | |
$left: list<any>, | |
$right: list<any>, | |
--keys (-k): list<string> = [], | |
] { | |
let left = if ($left | describe) !~ '^table' { $left | wrap value } else { $left } | |
let right = if ($right | describe) !~ '^table' { $right | wrap value } else { $right } | |
let left_selected = ($left | select ...$keys) | |
let right_selected = ($right | select ...$keys) | |
let left_not_in_right = ( | |
$left | filter {|row| not (($row | select ...$keys) in $right_selected) } | |
) | |
let right_not_in_left = ( | |
$right | filter {|row| not (($row | select ...$keys) in $left_selected) } | |
) | |
( | |
$left_not_in_right | insert side '<=' | |
) ++ ( | |
$right_not_in_left | insert side '=>' | |
) | |
} | |
# Delete all branches that are not in the excepts list | |
# Usage: del-branches [main] | |
def del-branches [ | |
excepts: list # don't delete branch in the list | |
--dry-run (-d) # do a dry-run | |
] { | |
let branches = (git branch | lines | str trim) | |
let remote_branches = (git branch -r | lines | str replace -r '^.+?/' '' | uniq) | |
if $dry_run { | |
print "Starting Dry-Run" | |
} else { | |
print "Deleting for real" | |
} | |
$branches | each {|it| | |
if ($it not-in $excepts) and ($it not-in $remote_branches) and (not ($it | str starts-with "*")) { | |
# git branch -D $it | |
if $dry_run { | |
print $"git branch -D ($it)" | |
} else { | |
print $"Deleting ($it) for real" | |
git branch -D $it | |
} | |
} | |
} | |
} | |
# Wrapper for the pspg pager | |
def --wrapped pspg [...args] { | |
let input = $in | |
$env.config.ls.clickable_links = false | |
$env.config.table.mode = 'rounded' | |
$env.config.table.header_on_separator = false | |
$env.config.footer_mode = 'never' | |
$input | ^pspg ...$args | |
} | |
def plugins [] { | |
plugin list | update commands { str join ', ' } | reject shell | update filename { path parse | get stem } | table --index 1 | |
} | |
# get the version information formatting the plugins differently | |
def ver [ --markdown (-m)] { | |
let plugin_modified = plugin list | insert last_modified {|plug| | |
ls $plug.filename | get 0?.modified? | |
} | select name last_modified | |
let ver = version | upsert build_time { into datetime } | upsert installed_plugins {|v| | |
$v | get installed_plugins | split row ', ' | parse '{name} {version}' | join $plugin_modified name | |
} | |
if $markdown { | |
$ver | to md | |
} else { | |
$ver | table -e | |
} | |
} | |
# custom command to wrap text in a column at a certain width | |
# will not break words but will break on spaces cr or crlf | |
# example: | |
# $data | update textcolumn { str-wrap } | |
def str-wrap [ --wrap-at (-w): number = 20] { | |
str replace -a "\r\n" "\n" | |
| str replace -a "\n" " SINGLENEWLINE " | |
| str trim | |
| split row -r "\\s+" | |
| reduce -f {joined: '' count: 0} {|word, state| | |
if ($word == "\n") { | |
{ | |
joined: ($state.joined + "\n") | |
count: 0 | |
} | |
} else if ($state.count < $wrap_at) { | |
if ($state.joined | is-empty) { | |
{ | |
joined: $word | |
count: ($word | str length) | |
} | |
} else { | |
{ | |
joined: ($state.joined + ' ' + $word) | |
count: ($state.count + 1 + ($word | str length)) | |
} | |
} | |
} else { | |
{ | |
joined: ($state.joined + "\n" + $word) | |
count: 0 | |
} | |
} | |
} | |
| get joined | |
| str replace -ar "\\s*SINGLENEWLINE\\s*" "\n" | |
} | |
# head replacement | |
# example: heady -f ~/desktop/wiztree.csv -b 200 | |
def heady [ --file (-f): path, --bytes (-b): int = 100, --binary]: [nothing -> string nothing -> binary] { | |
3 03:49:04 PM | |
if $binary { | |
open -r $file | into binary | first $bytes | |
} else { | |
open -r $file | into binary | first $bytes | decode utf8 | |
} | |
} | |
# Example usage: | |
# $env.PAGER = "less -SRX" | |
# open foo.txt | parse-external $env.PAGER | |
# or | |
# parse-external $env.PAGER foo.txt | |
def parse-external [command: string, ...rest: string] { | |
do {|parsed| | |
run-external $parsed.0 ...($parsed | skip 1) ...$rest | |
} (ast -f $"^($command)" | get content) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nushell Environment Config File | |
print "Hello, from env.nu" | |
# Some environment variables | |
# $env.GITHUB_USERNAME = "fdncred" | |
# $env.GITHUB_PASSWORD = "12345" | |
$env.LESS = "-FRXS" | |
$env.PAGER = "less" | |
$env.HOME = 'C:\Users\us991808' | |
$env.LANG = "en_US.UTF-8" | |
# $env.GIT_SSL_NO_VERIFY = "1" | |
$env.LIBCLANG_PATH = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin\libclang.dll' | |
$env.GIT_REPOS_HOME = 'C:\Users\us991808\source\repos\forks' | |
# Use nushell functions to define your right and left prompt | |
# note - i put this in my config.nu so i could utilize the NU_LIB_DIRS env var | |
# use "c:\Users\dschroeder\source\repos\forks\nu_scripts\prompt\oh-my.nu" git_prompt | |
# $env.PROMPT_COMMAND = { (git_prompt).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (git_prompt).right_prompt } | |
$env.TOPIARY_CONFIG_FILE = 'C:\Users\us991808\source\repos\forks\topiary-nushell\languages.ncl' | |
$env.TOPIARY_LANGUAGE_DIR = 'C:\Users\us991808\source\repos\forks\topiary-nushell\languages' | |
# The prompt indicators are environmental variables that represent | |
# the state of the prompt | |
# $env.PROMPT_INDICATOR = {|| " " } | |
# $env.PROMPT_INDICATOR_VI_INSERT = {|| ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = {|| "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = $"(ansi -e { fg: '#66cdaa'})(char -u 276f)(ansi -e { fg: '#76eec6'})(char -u 276f)(ansi -e { fg: '#7fffd4'})(char -u 276f)(ansi reset)(char space)" | |
# $env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e { fg: '#CB4B16'})(char -u '276f')(ansi -e { fg: '#CACA02'})(char -u '276f')(ansi -e { fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
# use "c:\Users\dschroeder\source\repos\forks\nu_scripts\prompt\oh-my-minimal.nu" get_prompt | |
# $env.PROMPT_COMMAND = { (get_prompt 1).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 1).right_prompt } | |
# $env.PROMPT_INDICATOR = { " " } | |
# $env.PROMPT_INDICATOR = { "〉" } | |
# $env.PROMPT_INDICATOR_VI_INSERT = { ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = { "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = { "::: " } | |
# $env.PROMPT_INDICATOR_HISTORY = { "? " } | |
# note - the string color will affect ls_colors | |
# if you make it wd, all colors for strings will | |
# be dimmed | |
# base16 | |
# https://github.com/Kirill-Bugaev/awesome-base16/blob/master/base16/apps/default_dark/dircolors | |
# $env.LS_COLORS = "no=00;37:fi=01;34:rs=00;37:di=00;34:ln=00;36:mh=00;37:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=00;05;37;41:mi=00;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=04;34:st=37;44:ex=00;32:*.cmd=00;33:*.exe=00;33:*.com=00;33:*.btm=00;33:*.bat=00;33:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz=01;31:*.bz2=01;31:*.bzip2=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.apk=01;31:*.gem=01;31:*.jpg=00;35:*.JPG=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.svg=00;35:*.svgz=00;35:*.mng=00;35:*.pcx=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.yuv=00;35:*.cgm=00;35:*.emf=00;35:*.eps=00;35:*.CR2=00;35:*.ico=00;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.html=00;32:*.css=00;32:*.rst=00;32:*.md=00;32:*.patch=00;32:*.diff=00;32:*.tex=00;32:*.xls=00;32:*.xlsx=00;32:*.doc=00;32:*.docx=00;32:*.ppt=00;32:*.pptx=00;32:*.key=00;32:*.ods=00;32:*.odt=00;32:*.pt=01;32:*.tmpl=01;32:*.in=01;32:*.ots=01;32:*.ott=01;32:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.m4a=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:*.mov=01;36:*.mpg=01;36:*.mpeg=01;36:*.m2v=01;36:*.mkv=01;36:*.ogm=01;36:*.mp4=01;36:*.m4v=01;36:*.mp4v=01;36:*.vob=01;36:*.qt=01;36:*.nuv=01;36:*.wmv=01;36:*.asf=01;36:*.rm=01;36:*.rmvb=01;36:*.flc=01;36:*.avi=01;36:*.fli=01;36:*.flv=01;36:*.gl=01;36:*.m2ts=01;36:*.divx=01;36:*.webm=01;36:*.axv=01;36:*.anx=01;36:*.ogv=01;36:*.ogx=01;36:*.conf=00;36:*.config=00;36:*.cnf=00;36:*.cfg=00;36:*.ini=00;36:*.properties=00;36:*.yaml=00;36:*.vcl=00;36:*.c=00;33:*.cpp=00;33:*.py=00;33:*.coffesscript=00;33:*.js=00;33:*.rb=00;33:*.sh=00;33:*.zsh=00;33:*.env=00;33:*.bash=00;33:*.php=00;33:*.java=00;33:*.zcml=00;33:*.pl=00;33:*.lua=00;33:*.clj=00;33:*.cs=00;33:*.fs=00;33:*.fsx=00;33:*.go=00;33:*.db=00;32:*.sql=00;32:*.json=00;32:*.plist=00;32:*.xml=00;32:*.tex=01;37:*.rdf=01;37:*.owl=01;37:*.n3=01;37:*.ttl=01;37:*.nt=01;37:*.torrent=01;37:*.xml=01;37:*Makefile=01;37:*makefile=01;37:*Rakefile=01;37:*build.xml=01;37:*rc=01;37:*.nfo=01;37:*README=01;37:*README.txt=01;37:*readme.txt=01;37:*README.markdown=01;37:*README.md=01;37:*.cc=01;37:*.log=01;30:*.bak=01;30:*.aux=01;30:*.lof=01;30:*.lol=01;30:*.lot=01;30:*.out=01;30:*.toc=01;30:*.bbl=01;30:*.blg=01;30:*~=01;30:*#=01;30:*.part=01;30:*.incomplete=01;30:*.swp=01;30:*.tmp=01;30:*.temp=01;30:*.o=01;30:*.obj=01;30:*.pyc=01;30:*.pyo=01;30:*.class=01;30:*.cache=01;30:*.egg-info=01;30:" | |
# 24-bit colors | |
# $env.LS_COLORS = (vivid generate molokai | str trim) | |
# 8-bit colors | |
# $env.LS_COLORS = "st=0:di=0;38;5;81:so=0;38;5;16;48;5;203:ln=0;38;5;203:cd=0;38;5;203;48;5;236:ex=1;38;5;203:or=0;38;5;16;48;5;203:fi=0:bd=0;38;5;81;48;5;236:ow=0:mi=0;38;5;16;48;5;203:*~=0;38;5;243:no=0:tw=0:pi=0;38;5;16;48;5;81:*.z=4;38;5;203:*.t=0;38;5;48:*.o=0;38;5;243:*.d=0;38;5;48:*.a=1;38;5;203:*.c=0;38;5;48:*.m=0;38;5;48:*.p=0;38;5;48:*.r=0;38;5;48:*.h=0;38;5;48:*.ml=0;38;5;48:*.ll=0;38;5;48:*.gv=0;38;5;48:*.cp=0;38;5;48:*.xz=4;38;5;203:*.hs=0;38;5;48:*css=0;38;5;48:*.ui=0;38;5;149:*.pl=0;38;5;48:*.ts=0;38;5;48:*.gz=4;38;5;203:*.so=1;38;5;203:*.cr=0;38;5;48:*.fs=0;38;5;48:*.bz=4;38;5;203:*.ko=1;38;5;203:*.as=0;38;5;48:*.sh=0;38;5;48:*.pp=0;38;5;48:*.el=0;38;5;48:*.py=0;38;5;48:*.lo=0;38;5;243:*.bc=0;38;5;243:*.cc=0;38;5;48:*.pm=0;38;5;48:*.rs=0;38;5;48:*.di=0;38;5;48:*.jl=0;38;5;48:*.rb=0;38;5;48:*.md=0;38;5;185:*.js=0;38;5;48:*.go=0;38;5;48:*.vb=0;38;5;48:*.hi=0;38;5;243:*.kt=0;38;5;48:*.hh=0;38;5;48:*.cs=0;38;5;48:*.mn=0;38;5;48:*.nb=0;38;5;48:*.7z=4;38;5;203:*.ex=0;38;5;48:*.rm=0;38;5;208:*.ps=0;38;5;186:*.td=0;38;5;48:*.la=0;38;5;243:*.aux=0;38;5;243:*.xmp=0;38;5;149:*.mp4=0;38;5;208:*.rpm=4;38;5;203:*.m4a=0;38;5;208:*.zip=4;38;5;203:*.dll=1;38;5;203:*.bcf=0;38;5;243:*.awk=0;38;5;48:*.aif=0;38;5;208:*.zst=4;38;5;203:*.bak=0;38;5;243:*.tgz=4;38;5;203:*.com=1;38;5;203:*.clj=0;38;5;48:*.sxw=0;38;5;186:*.vob=0;38;5;208:*.fsx=0;38;5;48:*.doc=0;38;5;186:*.mkv=0;38;5;208:*.tbz=4;38;5;203:*.ogg=0;38;5;208:*.wma=0;38;5;208:*.mid=0;38;5;208:*.kex=0;38;5;186:*.out=0;38;5;243:*.ltx=0;38;5;48:*.sql=0;38;5;48:*.ppt=0;38;5;186:*.tex=0;38;5;48:*.odp=0;38;5;186:*.log=0;38;5;243:*.arj=4;38;5;203:*.ipp=0;38;5;48:*.sbt=0;38;5;48:*.jpg=0;38;5;208:*.yml=0;38;5;149:*.txt=0;38;5;185:*.csv=0;38;5;185:*.dox=0;38;5;149:*.pro=0;38;5;149:*.bst=0;38;5;149:*TODO=1:*.mir=0;38;5;48:*.bat=1;38;5;203:*.m4v=0;38;5;208:*.pod=0;38;5;48:*.cfg=0;38;5;149:*.pas=0;38;5;48:*.tml=0;38;5;149:*.bib=0;38;5;149:*.ini=0;38;5;149:*.apk=4;38;5;203:*.h++=0;38;5;48:*.pyc=0;38;5;243:*.img=4;38;5;203:*.rst=0;38;5;185:*.swf=0;38;5;208:*.htm=0;38;5;185:*.ttf=0;38;5;208:*.elm=0;38;5;48:*hgrc=0;38;5;149:*.bmp=0;38;5;208:*.fsi=0;38;5;48:*.pgm=0;38;5;208:*.dpr=0;38;5;48:*.xls=0;38;5;186:*.tcl=0;38;5;48:*.mli=0;38;5;48:*.ppm=0;38;5;208:*.bbl=0;38;5;243:*.lua=0;38;5;48:*.asa=0;38;5;48:*.pbm=0;38;5;208:*.avi=0;38;5;208:*.def=0;38;5;48:*.mov=0;38;5;208:*.hxx=0;38;5;48:*.tif=0;38;5;208:*.fon=0;38;5;208:*.zsh=0;38;5;48:*.png=0;38;5;208:*.inc=0;38;5;48:*.jar=4;38;5;203:*.swp=0;38;5;243:*.pid=0;38;5;243:*.gif=0;38;5;208:*.ind=0;38;5;243:*.erl=0;38;5;48:*.ilg=0;38;5;243:*.eps=0;38;5;208:*.tsx=0;38;5;48:*.git=0;38;5;243:*.inl=0;38;5;48:*.rtf=0;38;5;186:*.hpp=0;38;5;48:*.kts=0;38;5;48:*.deb=4;38;5;203:*.svg=0;38;5;208:*.pps=0;38;5;186:*.ps1=0;38;5;48:*.c++=0;38;5;48:*.cpp=0;38;5;48:*.bsh=0;38;5;48:*.php=0;38;5;48:*.exs=0;38;5;48:*.toc=0;38;5;243:*.mp3=0;38;5;208:*.epp=0;38;5;48:*.rar=4;38;5;203:*.wav=0;38;5;208:*.xlr=0;38;5;186:*.tmp=0;38;5;243:*.cxx=0;38;5;48:*.iso=4;38;5;203:*.dmg=4;38;5;203:*.gvy=0;38;5;48:*.bin=4;38;5;203:*.wmv=0;38;5;208:*.blg=0;38;5;243:*.ods=0;38;5;186:*.psd=0;38;5;208:*.mpg=0;38;5;208:*.dot=0;38;5;48:*.cgi=0;38;5;48:*.xml=0;38;5;185:*.htc=0;38;5;48:*.ics=0;38;5;186:*.bz2=4;38;5;203:*.tar=4;38;5;203:*.csx=0;38;5;48:*.ico=0;38;5;208:*.sxi=0;38;5;186:*.nix=0;38;5;149:*.pkg=4;38;5;203:*.bag=4;38;5;203:*.fnt=0;38;5;208:*.idx=0;38;5;243:*.xcf=0;38;5;208:*.exe=1;38;5;203:*.flv=0;38;5;208:*.fls=0;38;5;243:*.otf=0;38;5;208:*.vcd=4;38;5;203:*.vim=0;38;5;48:*.sty=0;38;5;243:*.pdf=0;38;5;186:*.odt=0;38;5;186:*.purs=0;38;5;48:*.h264=0;38;5;208:*.jpeg=0;38;5;208:*.dart=0;38;5;48:*.pptx=0;38;5;186:*.lock=0;38;5;243:*.bash=0;38;5;48:*.rlib=0;38;5;243:*.hgrc=0;38;5;149:*.psm1=0;38;5;48:*.toml=0;38;5;149:*.tbz2=4;38;5;203:*.yaml=0;38;5;149:*.make=0;38;5;149:*.orig=0;38;5;243:*.html=0;38;5;185:*.fish=0;38;5;48:*.diff=0;38;5;48:*.xlsx=0;38;5;186:*.docx=0;38;5;186:*.json=0;38;5;149:*.psd1=0;38;5;48:*.tiff=0;38;5;208:*.flac=0;38;5;208:*.java=0;38;5;48:*.less=0;38;5;48:*.mpeg=0;38;5;208:*.conf=0;38;5;149:*.lisp=0;38;5;48:*.epub=0;38;5;186:*.cabal=0;38;5;48:*.patch=0;38;5;48:*.shtml=0;38;5;185:*.class=0;38;5;243:*.xhtml=0;38;5;185:*.mdown=0;38;5;185:*.dyn_o=0;38;5;243:*.cache=0;38;5;243:*.swift=0;38;5;48:*README=0;38;5;16;48;5;186:*passwd=0;38;5;149:*.ipynb=0;38;5;48:*shadow=0;38;5;149:*.toast=4;38;5;203:*.cmake=0;38;5;149:*.scala=0;38;5;48:*.dyn_hi=0;38;5;243:*.matlab=0;38;5;48:*.config=0;38;5;149:*.gradle=0;38;5;48:*.groovy=0;38;5;48:*.ignore=0;38;5;149:*LICENSE=0;38;5;249:*TODO.md=1:*COPYING=0;38;5;249:*.flake8=0;38;5;149:*INSTALL=0;38;5;16;48;5;186:*setup.py=0;38;5;149:*.gemspec=0;38;5;149:*.desktop=0;38;5;149:*Makefile=0;38;5;149:*Doxyfile=0;38;5;149:*TODO.txt=1:*README.md=0;38;5;16;48;5;186:*.kdevelop=0;38;5;149:*.rgignore=0;38;5;149:*configure=0;38;5;149:*.DS_Store=0;38;5;243:*.fdignore=0;38;5;149:*COPYRIGHT=0;38;5;249:*.markdown=0;38;5;185:*.cmake.in=0;38;5;149:*.gitconfig=0;38;5;149:*INSTALL.md=0;38;5;16;48;5;186:*CODEOWNERS=0;38;5;149:*.gitignore=0;38;5;149:*Dockerfile=0;38;5;149:*SConstruct=0;38;5;149:*.scons_opt=0;38;5;243:*README.txt=0;38;5;16;48;5;186:*SConscript=0;38;5;149:*.localized=0;38;5;243:*.travis.yml=0;38;5;186:*Makefile.in=0;38;5;243:*.gitmodules=0;38;5;149:*LICENSE-MIT=0;38;5;249:*Makefile.am=0;38;5;149:*INSTALL.txt=0;38;5;16;48;5;186:*MANIFEST.in=0;38;5;149:*.synctex.gz=0;38;5;243:*.fdb_latexmk=0;38;5;243:*CONTRIBUTORS=0;38;5;16;48;5;186:*configure.ac=0;38;5;149:*.applescript=0;38;5;48:*appveyor.yml=0;38;5;186:*.clang-format=0;38;5;149:*.gitattributes=0;38;5;149:*LICENSE-APACHE=0;38;5;249:*CMakeCache.txt=0;38;5;243:*CMakeLists.txt=0;38;5;149:*CONTRIBUTORS.md=0;38;5;16;48;5;186:*requirements.txt=0;38;5;149:*CONTRIBUTORS.txt=0;38;5;16;48;5;186:*.sconsign.dblite=0;38;5;243:*package-lock.json=0;38;5;243:*.CFUserTextEncoding=0;38;5;243" | |
# other vivid themes | |
# ayu, iceberg-dark, jellybeans, lava, molokai | |
# nord, one-dark, one-light, snazzy, solarized-dark | |
# solarized-light | |
# Specifies how environment variables are: | |
# - converted from a string to a value on Nushell startup (from_string) | |
# - converted from a value back to a string when running external commands (to_string) | |
# Note: The conversions happen *after* config.nu is loaded | |
# $env.ENV_CONVERSIONS = { | |
# "PATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "Path": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "LS_COLORS": { | |
# from_string: { |s| $s | split row (char esep) } | |
# # from_string: { |s| $s | split row '=' | $"(ansi -e ($in.1))m($in.0)(ansi reset) ($in.1)" } | split column ' ' | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "DYLD_FALLBACK_LIBRARY_PATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PATHEXT": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PSMODULEPATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PSModulePath": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "ZOXIDE_INITIALIZED": { | |
# from_string: { |s| $s | into bool } | |
# to_string: { |v| $v | into string } | |
# } | |
# } | |
export-env { | |
let esep_list_converter = { | |
from_string: {|s| $s | split row (char esep) } | |
to_string: {|v| $v | str join (char esep) } | |
} | |
let esep_path_converter = { | |
from_string: {|s| $s | split row (char esep) } | |
to_string: {|v| $v | path expand | str join (char esep) } | |
} | |
$env.ENV_CONVERSIONS = { | |
PATH: $esep_path_converter | |
LS_COLORS: $esep_list_converter | |
DYLD_FALLBACK_LIBRARY_PATH: $esep_path_converter | |
PATHEXT: $esep_list_converter | |
PSMODULEPATH: $esep_path_converter | |
} | |
} | |
# # Directories to search for scripts when calling source or use | |
# # | |
# # By default, <nushell-config-dir>/scripts is added | |
# $env.NU_LIB_DIRS = [ | |
# ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts | |
# 'C:\Users\us991808\source\repos\forks\nu_scripts' | |
# ($nu.config-path | path dirname) | |
# ($nu.data-dir | path join 'completions') # default home for nushell completions | |
# ] | |
# # Directories to search for plugin binaries when calling register | |
# # | |
# # By default, <nushell-config-dir>/plugins is added | |
# $env.NU_PLUGIN_DIRS = [ | |
# ($nu.config-path | path dirname | path join 'plugins') | |
# ] | |
# To add entries to PATH (on Windows you might use Path), you can use the following pattern: | |
# $env.Path = ( | |
# if "Path" in $env { | |
# $env.Path | |
# | split row (char esep) | |
# | prepend 'C:\Apps\Just' | |
# | prepend 'C:\Apps\carapace' | |
# | prepend 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin' | |
# | prepend 'C:\Users\us991808\.vscode\extensions\rust-lang.rust-analyzer-0.3.1386-win32-x64\server' | |
# } else { | |
# $env.PATH | |
# | split row (char esep) | |
# | prepend 'C:\Apps\Just' | |
# | prepend 'C:\Apps\carapace' | |
# | prepend 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin' | |
# | prepend 'C:\Users\us991808\.vscode\extensions\rust-lang.rust-analyzer-0.3.1386-win32-x64\server' | |
# } | |
# ) | |
# let pathvar = if "PATH" in $env { "PATH" } else { "Path" } | |
# load-env { | |
# $pathvar: ( | |
# $env | get $pathvar | | |
# split row (char esep) | | |
# prepend 'C:\Apps\Just' | | |
# prepend 'c:\Apps\carapace' | | |
# prepend 'C:\Users\dschroeder\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin' | | |
# prepend 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin' | |
# ) | |
# } | |
$env.Path = ( | |
$env.Path | |
| split row (char esep) | |
| prepend 'C:\Apps\Just' | |
| prepend 'C:\Apps\carapace' | |
| prepend 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin' | |
| prepend 'C:\Users\us991808\.vscode\extensions\rust-lang.rust-analyzer-0.3.1386-win32-x64\server' | |
| append 'C:\Apps\Protoc\bin' | |
) | |
# zoxide | |
# zoxide init nushell --hook prompt | save -f ~/.zoxide.nu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nushell Environment Config File | |
# Some environment variables | |
# let-env GITHUB_USERNAME = "fdncred" | |
# let-env GITHUB_PASSWORD = "12345" | |
let-env LESS = "-FRX" | |
let-env PAGER = "less" | |
let-env PATH = ($env.PATH | | |
prepend '/opt/homebrew/opt/sqlite/bin' | | |
prepend '/opt/homebrew/opt/coreutils/libexec/gnubin' | | |
prepend '/opt/homebrew/bin' | | |
prepend '/opt/homebrew/sbin' | | |
prepend '/Users/fdncred/.cargo/bin' | |
) | |
let-env HOMEBREW_PREFIX = "/opt/homebrew" | |
let-env HOMEBREW_CELLAR = "/opt/homebrew/Cellar" | |
let-env HOMEBREW_REPOSITORY = "/opt/homebrew" | |
# $env | get -i MANPATH | default '/opt/homebrew/share/man' | |
# let-env MANPATH = ($env.MANPATH | prepend "/opt/homebrew/share/man") | |
let-env MANPATH = "/opt/homebrew/share/man:/usr/share/man:/usr/local/share/man" | |
let-env INFOPATH = "/opt/homebrew/share/info" | |
let-env EDITOR = "hx" | |
# Use nushell functions to define your right and left prompt | |
# note - i put this in my config.nu so i could utilize the NU_LIB_DIRS env var | |
# use "c:\Users\dschroeder\source\repos\forks\nu_scripts\prompt\oh-my.nu" git_prompt | |
# let-env PROMPT_COMMAND = { (git_prompt).left_prompt } | |
# let-env PROMPT_COMMAND_RIGHT = { (git_prompt).right_prompt } | |
# The prompt indicators are environmental variables that represent | |
# the state of the prompt | |
let-env PROMPT_INDICATOR = { " " } | |
let-env PROMPT_INDICATOR_VI_INSERT = { ": " } | |
let-env PROMPT_INDICATOR_VI_NORMAL = { "〉" } | |
# let-env PROMPT_MULTILINE_INDICATOR = $"(ansi -e { fg: '#66cdaa'})(char -u 276f)(ansi -e { fg: '#76eec6'})(char -u 276f)(ansi -e { fg: '#7fffd4'})(char -u 276f)(ansi reset)(char space)" | |
let-env PROMPT_MULTILINE_INDICATOR = { $"(ansi -e { fg: '#CB4B16'})(char -u 276f)(ansi -e { fg: '#CACA02'})(char -u 276f)(ansi -e { fg: '#4E9A06'})(char -u 276f)(ansi reset)(char space)" } | |
# use "c:\Users\dschroeder\source\repos\forks\nu_scripts\prompt\oh-my-minimal.nu" get_prompt | |
# let-env PROMPT_COMMAND = { (get_prompt 1).left_prompt } | |
# let-env PROMPT_COMMAND_RIGHT = { (get_prompt 1).right_prompt } | |
# let-env PROMPT_INDICATOR = { " " } | |
# let-env PROMPT_INDICATOR = { "〉" } | |
# let-env PROMPT_INDICATOR_VI_INSERT = { ": " } | |
# let-env PROMPT_INDICATOR_VI_NORMAL = { "〉" } | |
# let-env PROMPT_MULTILINE_INDICATOR = { "::: " } | |
# let-env PROMPT_INDICATOR_HISTORY = { "? " } | |
# note - the string color will affect ls_colors | |
# if you make it wd, all colors for strings will | |
# be dimmed | |
# base16 | |
# https://github.com/Kirill-Bugaev/awesome-base16/blob/master/base16/apps/default_dark/dircolors | |
# let-env LS_COLORS = "no=00;37:fi=01;34:rs=00;37:di=00;34:ln=00;36:mh=00;37:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=00;05;37;41:mi=00;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=04;34:st=37;44:ex=00;32:*.cmd=00;33:*.exe=00;33:*.com=00;33:*.btm=00;33:*.bat=00;33:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz=01;31:*.bz2=01;31:*.bzip2=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.apk=01;31:*.gem=01;31:*.jpg=00;35:*.JPG=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.svg=00;35:*.svgz=00;35:*.mng=00;35:*.pcx=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.yuv=00;35:*.cgm=00;35:*.emf=00;35:*.eps=00;35:*.CR2=00;35:*.ico=00;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.html=00;32:*.css=00;32:*.rst=00;32:*.md=00;32:*.patch=00;32:*.diff=00;32:*.tex=00;32:*.xls=00;32:*.xlsx=00;32:*.doc=00;32:*.docx=00;32:*.ppt=00;32:*.pptx=00;32:*.key=00;32:*.ods=00;32:*.odt=00;32:*.pt=01;32:*.tmpl=01;32:*.in=01;32:*.ots=01;32:*.ott=01;32:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.m4a=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:*.mov=01;36:*.mpg=01;36:*.mpeg=01;36:*.m2v=01;36:*.mkv=01;36:*.ogm=01;36:*.mp4=01;36:*.m4v=01;36:*.mp4v=01;36:*.vob=01;36:*.qt=01;36:*.nuv=01;36:*.wmv=01;36:*.asf=01;36:*.rm=01;36:*.rmvb=01;36:*.flc=01;36:*.avi=01;36:*.fli=01;36:*.flv=01;36:*.gl=01;36:*.m2ts=01;36:*.divx=01;36:*.webm=01;36:*.axv=01;36:*.anx=01;36:*.ogv=01;36:*.ogx=01;36:*.conf=00;36:*.config=00;36:*.cnf=00;36:*.cfg=00;36:*.ini=00;36:*.properties=00;36:*.yaml=00;36:*.vcl=00;36:*.c=00;33:*.cpp=00;33:*.py=00;33:*.coffesscript=00;33:*.js=00;33:*.rb=00;33:*.sh=00;33:*.zsh=00;33:*.env=00;33:*.bash=00;33:*.php=00;33:*.java=00;33:*.zcml=00;33:*.pl=00;33:*.lua=00;33:*.clj=00;33:*.cs=00;33:*.fs=00;33:*.fsx=00;33:*.go=00;33:*.db=00;32:*.sql=00;32:*.json=00;32:*.plist=00;32:*.xml=00;32:*.tex=01;37:*.rdf=01;37:*.owl=01;37:*.n3=01;37:*.ttl=01;37:*.nt=01;37:*.torrent=01;37:*.xml=01;37:*Makefile=01;37:*makefile=01;37:*Rakefile=01;37:*build.xml=01;37:*rc=01;37:*.nfo=01;37:*README=01;37:*README.txt=01;37:*readme.txt=01;37:*README.markdown=01;37:*README.md=01;37:*.cc=01;37:*.log=01;30:*.bak=01;30:*.aux=01;30:*.lof=01;30:*.lol=01;30:*.lot=01;30:*.out=01;30:*.toc=01;30:*.bbl=01;30:*.blg=01;30:*~=01;30:*#=01;30:*.part=01;30:*.incomplete=01;30:*.swp=01;30:*.tmp=01;30:*.temp=01;30:*.o=01;30:*.obj=01;30:*.pyc=01;30:*.pyo=01;30:*.class=01;30:*.cache=01;30:*.egg-info=01;30:" | |
# 24-bit colors | |
# let-env LS_COLORS = (vivid generate molokai | str trim) | |
# 8-bit colors | |
# let-env LS_COLORS = "st=0:di=0;38;5;81:so=0;38;5;16;48;5;203:ln=0;38;5;203:cd=0;38;5;203;48;5;236:ex=1;38;5;203:or=0;38;5;16;48;5;203:fi=0:bd=0;38;5;81;48;5;236:ow=0:mi=0;38;5;16;48;5;203:*~=0;38;5;243:no=0:tw=0:pi=0;38;5;16;48;5;81:*.z=4;38;5;203:*.t=0;38;5;48:*.o=0;38;5;243:*.d=0;38;5;48:*.a=1;38;5;203:*.c=0;38;5;48:*.m=0;38;5;48:*.p=0;38;5;48:*.r=0;38;5;48:*.h=0;38;5;48:*.ml=0;38;5;48:*.ll=0;38;5;48:*.gv=0;38;5;48:*.cp=0;38;5;48:*.xz=4;38;5;203:*.hs=0;38;5;48:*css=0;38;5;48:*.ui=0;38;5;149:*.pl=0;38;5;48:*.ts=0;38;5;48:*.gz=4;38;5;203:*.so=1;38;5;203:*.cr=0;38;5;48:*.fs=0;38;5;48:*.bz=4;38;5;203:*.ko=1;38;5;203:*.as=0;38;5;48:*.sh=0;38;5;48:*.pp=0;38;5;48:*.el=0;38;5;48:*.py=0;38;5;48:*.lo=0;38;5;243:*.bc=0;38;5;243:*.cc=0;38;5;48:*.pm=0;38;5;48:*.rs=0;38;5;48:*.di=0;38;5;48:*.jl=0;38;5;48:*.rb=0;38;5;48:*.md=0;38;5;185:*.js=0;38;5;48:*.go=0;38;5;48:*.vb=0;38;5;48:*.hi=0;38;5;243:*.kt=0;38;5;48:*.hh=0;38;5;48:*.cs=0;38;5;48:*.mn=0;38;5;48:*.nb=0;38;5;48:*.7z=4;38;5;203:*.ex=0;38;5;48:*.rm=0;38;5;208:*.ps=0;38;5;186:*.td=0;38;5;48:*.la=0;38;5;243:*.aux=0;38;5;243:*.xmp=0;38;5;149:*.mp4=0;38;5;208:*.rpm=4;38;5;203:*.m4a=0;38;5;208:*.zip=4;38;5;203:*.dll=1;38;5;203:*.bcf=0;38;5;243:*.awk=0;38;5;48:*.aif=0;38;5;208:*.zst=4;38;5;203:*.bak=0;38;5;243:*.tgz=4;38;5;203:*.com=1;38;5;203:*.clj=0;38;5;48:*.sxw=0;38;5;186:*.vob=0;38;5;208:*.fsx=0;38;5;48:*.doc=0;38;5;186:*.mkv=0;38;5;208:*.tbz=4;38;5;203:*.ogg=0;38;5;208:*.wma=0;38;5;208:*.mid=0;38;5;208:*.kex=0;38;5;186:*.out=0;38;5;243:*.ltx=0;38;5;48:*.sql=0;38;5;48:*.ppt=0;38;5;186:*.tex=0;38;5;48:*.odp=0;38;5;186:*.log=0;38;5;243:*.arj=4;38;5;203:*.ipp=0;38;5;48:*.sbt=0;38;5;48:*.jpg=0;38;5;208:*.yml=0;38;5;149:*.txt=0;38;5;185:*.csv=0;38;5;185:*.dox=0;38;5;149:*.pro=0;38;5;149:*.bst=0;38;5;149:*TODO=1:*.mir=0;38;5;48:*.bat=1;38;5;203:*.m4v=0;38;5;208:*.pod=0;38;5;48:*.cfg=0;38;5;149:*.pas=0;38;5;48:*.tml=0;38;5;149:*.bib=0;38;5;149:*.ini=0;38;5;149:*.apk=4;38;5;203:*.h++=0;38;5;48:*.pyc=0;38;5;243:*.img=4;38;5;203:*.rst=0;38;5;185:*.swf=0;38;5;208:*.htm=0;38;5;185:*.ttf=0;38;5;208:*.elm=0;38;5;48:*hgrc=0;38;5;149:*.bmp=0;38;5;208:*.fsi=0;38;5;48:*.pgm=0;38;5;208:*.dpr=0;38;5;48:*.xls=0;38;5;186:*.tcl=0;38;5;48:*.mli=0;38;5;48:*.ppm=0;38;5;208:*.bbl=0;38;5;243:*.lua=0;38;5;48:*.asa=0;38;5;48:*.pbm=0;38;5;208:*.avi=0;38;5;208:*.def=0;38;5;48:*.mov=0;38;5;208:*.hxx=0;38;5;48:*.tif=0;38;5;208:*.fon=0;38;5;208:*.zsh=0;38;5;48:*.png=0;38;5;208:*.inc=0;38;5;48:*.jar=4;38;5;203:*.swp=0;38;5;243:*.pid=0;38;5;243:*.gif=0;38;5;208:*.ind=0;38;5;243:*.erl=0;38;5;48:*.ilg=0;38;5;243:*.eps=0;38;5;208:*.tsx=0;38;5;48:*.git=0;38;5;243:*.inl=0;38;5;48:*.rtf=0;38;5;186:*.hpp=0;38;5;48:*.kts=0;38;5;48:*.deb=4;38;5;203:*.svg=0;38;5;208:*.pps=0;38;5;186:*.ps1=0;38;5;48:*.c++=0;38;5;48:*.cpp=0;38;5;48:*.bsh=0;38;5;48:*.php=0;38;5;48:*.exs=0;38;5;48:*.toc=0;38;5;243:*.mp3=0;38;5;208:*.epp=0;38;5;48:*.rar=4;38;5;203:*.wav=0;38;5;208:*.xlr=0;38;5;186:*.tmp=0;38;5;243:*.cxx=0;38;5;48:*.iso=4;38;5;203:*.dmg=4;38;5;203:*.gvy=0;38;5;48:*.bin=4;38;5;203:*.wmv=0;38;5;208:*.blg=0;38;5;243:*.ods=0;38;5;186:*.psd=0;38;5;208:*.mpg=0;38;5;208:*.dot=0;38;5;48:*.cgi=0;38;5;48:*.xml=0;38;5;185:*.htc=0;38;5;48:*.ics=0;38;5;186:*.bz2=4;38;5;203:*.tar=4;38;5;203:*.csx=0;38;5;48:*.ico=0;38;5;208:*.sxi=0;38;5;186:*.nix=0;38;5;149:*.pkg=4;38;5;203:*.bag=4;38;5;203:*.fnt=0;38;5;208:*.idx=0;38;5;243:*.xcf=0;38;5;208:*.exe=1;38;5;203:*.flv=0;38;5;208:*.fls=0;38;5;243:*.otf=0;38;5;208:*.vcd=4;38;5;203:*.vim=0;38;5;48:*.sty=0;38;5;243:*.pdf=0;38;5;186:*.odt=0;38;5;186:*.purs=0;38;5;48:*.h264=0;38;5;208:*.jpeg=0;38;5;208:*.dart=0;38;5;48:*.pptx=0;38;5;186:*.lock=0;38;5;243:*.bash=0;38;5;48:*.rlib=0;38;5;243:*.hgrc=0;38;5;149:*.psm1=0;38;5;48:*.toml=0;38;5;149:*.tbz2=4;38;5;203:*.yaml=0;38;5;149:*.make=0;38;5;149:*.orig=0;38;5;243:*.html=0;38;5;185:*.fish=0;38;5;48:*.diff=0;38;5;48:*.xlsx=0;38;5;186:*.docx=0;38;5;186:*.json=0;38;5;149:*.psd1=0;38;5;48:*.tiff=0;38;5;208:*.flac=0;38;5;208:*.java=0;38;5;48:*.less=0;38;5;48:*.mpeg=0;38;5;208:*.conf=0;38;5;149:*.lisp=0;38;5;48:*.epub=0;38;5;186:*.cabal=0;38;5;48:*.patch=0;38;5;48:*.shtml=0;38;5;185:*.class=0;38;5;243:*.xhtml=0;38;5;185:*.mdown=0;38;5;185:*.dyn_o=0;38;5;243:*.cache=0;38;5;243:*.swift=0;38;5;48:*README=0;38;5;16;48;5;186:*passwd=0;38;5;149:*.ipynb=0;38;5;48:*shadow=0;38;5;149:*.toast=4;38;5;203:*.cmake=0;38;5;149:*.scala=0;38;5;48:*.dyn_hi=0;38;5;243:*.matlab=0;38;5;48:*.config=0;38;5;149:*.gradle=0;38;5;48:*.groovy=0;38;5;48:*.ignore=0;38;5;149:*LICENSE=0;38;5;249:*TODO.md=1:*COPYING=0;38;5;249:*.flake8=0;38;5;149:*INSTALL=0;38;5;16;48;5;186:*setup.py=0;38;5;149:*.gemspec=0;38;5;149:*.desktop=0;38;5;149:*Makefile=0;38;5;149:*Doxyfile=0;38;5;149:*TODO.txt=1:*README.md=0;38;5;16;48;5;186:*.kdevelop=0;38;5;149:*.rgignore=0;38;5;149:*configure=0;38;5;149:*.DS_Store=0;38;5;243:*.fdignore=0;38;5;149:*COPYRIGHT=0;38;5;249:*.markdown=0;38;5;185:*.cmake.in=0;38;5;149:*.gitconfig=0;38;5;149:*INSTALL.md=0;38;5;16;48;5;186:*CODEOWNERS=0;38;5;149:*.gitignore=0;38;5;149:*Dockerfile=0;38;5;149:*SConstruct=0;38;5;149:*.scons_opt=0;38;5;243:*README.txt=0;38;5;16;48;5;186:*SConscript=0;38;5;149:*.localized=0;38;5;243:*.travis.yml=0;38;5;186:*Makefile.in=0;38;5;243:*.gitmodules=0;38;5;149:*LICENSE-MIT=0;38;5;249:*Makefile.am=0;38;5;149:*INSTALL.txt=0;38;5;16;48;5;186:*MANIFEST.in=0;38;5;149:*.synctex.gz=0;38;5;243:*.fdb_latexmk=0;38;5;243:*CONTRIBUTORS=0;38;5;16;48;5;186:*configure.ac=0;38;5;149:*.applescript=0;38;5;48:*appveyor.yml=0;38;5;186:*.clang-format=0;38;5;149:*.gitattributes=0;38;5;149:*LICENSE-APACHE=0;38;5;249:*CMakeCache.txt=0;38;5;243:*CMakeLists.txt=0;38;5;149:*CONTRIBUTORS.md=0;38;5;16;48;5;186:*requirements.txt=0;38;5;149:*CONTRIBUTORS.txt=0;38;5;16;48;5;186:*.sconsign.dblite=0;38;5;243:*package-lock.json=0;38;5;243:*.CFUserTextEncoding=0;38;5;243" | |
# other vivid themes | |
# ayu, iceberg-dark, jellybeans, lava, molokai | |
# nord, one-dark, one-light, snazzy, solarized-dark | |
# solarized-light | |
# Specifies how environment variables are: | |
# - converted from a string to a value on Nushell startup (from_string) | |
# - converted from a value back to a string when running external commands (to_string) | |
# Note: The conversions happen *after* config.nu is loaded | |
let-env ENV_CONVERSIONS = { | |
"PATH": { | |
from_string: { |s| $s | split row (char esep) | path expand } | |
to_string: { |v| $v | path expand | str collect (char esep) } | |
} | |
"Path": { | |
from_string: { |s| $s | split row (char esep) | path expand } | |
to_string: { |v| $v | path expand | str collect (char esep) } | |
} | |
"LS_COLORS": { | |
from_string: { |s| $s | split row (char esep) } | |
# from_string: { |s| $s | split row '=' | $"(ansi -e ($in.1))m($in.0)(ansi reset) ($in.1)" } | split column ' ' | |
to_string: { |v| $v | str collect (char esep) } | |
} | |
"DYLD_FALLBACK_LIBRARY_PATH": { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | str collect (char esep) } | |
} | |
"PATHEXT": { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | str collect (char esep) } | |
} | |
"PSMODULEPATH": { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | str collect (char esep) } | |
} | |
} | |
# Directories to search for scripts when calling source or use | |
# | |
# By default, <nushell-config-dir>/scripts is added | |
let-env NU_LIB_DIRS = [ | |
($nu.config-path | path dirname | path join 'scripts') | |
'/Users/fdncred/src/forks/nu_scripts' | |
] | |
# Directories to search for plugin binaries when calling register | |
# | |
# By default, <nushell-config-dir>/plugins is added | |
let-env NU_PLUGIN_DIRS = [ | |
($nu.config-path | path dirname | path join 'plugins') | |
] | |
# To add entries to PATH (on Windows you might use Path), you can use the following pattern: | |
# let-env PATH = ($env.PATH | prepend '/some/path') | |
# latest zoxide | |
zoxide init nushell --hook prompt | save ~/.zoxide.nu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nushell Config File | |
# | |
# version = "0.103.1" | |
print "Hello, from config.nu" | |
# nushell version in md table | |
def nuvermd [] { version | transpose key value | to md } | |
# nushell version in table | |
def nuver [] { version | transpose key value } | |
# ls in a grid with colors and icons | |
def lsg [] { ls | sort-by type name -i | grid -c -i } | |
# For more information on defining custom themes, see | |
# https://www.nushell.sh/book/coloring_and_theming.html | |
# And here is the theme collection | |
# https://github.com/nushell/nu_scripts/tree/main/themes | |
let dark_theme = { | |
# color for nushell primitives | |
separator: white | |
leading_trailing_space_bg: {attr: n} # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
# eg) {|| if $in { 'light_cyan' } else { 'light_gray' } } | |
bool: light_cyan | |
int: white | |
filesize: cyan | |
duration: white | |
date: purple | |
range: white | |
float: white | |
string: white | |
nothing: white | |
binary: white | |
cell-path: white | |
row_index: green_bold | |
record: white | |
list: white | |
block: white | |
hints: dark_gray | |
search_result: {bg: red fg: white} | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_closure: green_bold | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: cyan | |
shape_externalarg: green_bold | |
shape_external_resolved: light_yellow_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: {fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_keyword: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: {attr: u} | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
shape_raw_string: light_purple | |
} | |
let light_theme = { | |
# color for nushell primitives | |
separator: dark_gray | |
leading_trailing_space_bg: {attr: n} # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
# eg) {|| if $in { 'dark_cyan' } else { 'dark_gray' } } | |
bool: dark_cyan | |
int: dark_gray | |
filesize: cyan_bold | |
duration: dark_gray | |
date: purple | |
range: dark_gray | |
float: dark_gray | |
string: dark_gray | |
nothing: dark_gray | |
binary: dark_gray | |
cell-path: dark_gray | |
row_index: green_bold | |
record: dark_gray | |
list: dark_gray | |
block: dark_gray | |
hints: dark_gray | |
search_result: {fg: white bg: red} | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_closure: green_bold | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: cyan | |
shape_externalarg: green_bold | |
shape_external_resolved: light_purple_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: {fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_keyword: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: {attr: u} | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
shape_raw_string: light_purple | |
} | |
let my_theme = { | |
binary: red | |
bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
cellpath: cyan | |
date: {|| | |
(date now) - $in | if $in < 1hr { | |
'red3b' #"\e[38;5;160m" #'#e61919' # 160 | |
} else if $in < 6hr { | |
'orange3' #"\e[38;5;172m" #'#e68019' # 172 | |
} else if $in < 1day { | |
'yellow3b' #"\e[38;5;184m" #'#e5e619' # 184 | |
} else if $in < 3day { | |
'chartreuse2b' #"\e[38;5;112m" #'#80e619' # 112 | |
} else if $in < 1wk { | |
'green3b' #"\e[38;5;40m" #'#19e619' # 40 | |
} else if $in < 6wk { | |
'darkturquoise' #"\e[38;5;44m" #'#19e5e6' # 44 | |
} else if $in < 52wk { | |
'deepskyblue3b' #"\e[38;5;32m" #'#197fe6' # 32 | |
} else { 'dark_gray' } | |
} | |
duration: blue_bold | |
filesize: {|e| if $e == 0b { 'black' } else if $e < 1mb { 'ub' } else { 'cyan' } } | |
float: red | |
foreground: green3b | |
glob: yellow_bold | |
header: cb | |
hints: dark_gray | |
int: green | |
leading_trailing_space_bg: {bg: dark_gray_dimmed} | |
nothing: red | |
range: purple | |
row_index: yb | |
separator: yd | |
# string: { if $in =~ '^#\w{6}$' { $in } else { 'white' } } | |
string: {|x| if $x =~ '^#[a-fA-F\d]+' { $x } else { 'white' } } | |
# search_result: {fg: white bg: blue} | |
search_result: blue_reverse | |
# shapes are used to change the cli syntax highlighting | |
# shape_and: purple_bold | |
# shape_binary: purple_bold | |
shape_block: "#33ff00" | |
# shape_bool: light_cyan | |
shape_bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
shape_closure: "#ffb000" | |
# shape_custom: green | |
# shape_datetime: cyan_bold | |
# shape_directory: cyan | |
shape_external: darkorange | |
shape_externalarg: light_purple | |
shape_external_resolved: light_yellow_bold | |
# shape_filepath: {|| if ($in | path exists) { 'light_green_underline' } else { 'light_green' } } | |
shape_filepath: cyan | |
# shape_flag: blue_bold | |
# shape_float: purple_bold | |
shape_garbage: {fg: white bg: red attr: b} | |
# shape_glob_interpolation: cyan_bold | |
# shape_globpattern: cyan_bold | |
# shape_int: purple_bold | |
shape_internallcall: cyan_bold | |
# shape_keyword: cyan_bold | |
# shape_list: cyan_bold | |
# shape_literal: blue | |
# shape_match_pattern: green | |
shape_matching_brackets: {fg: red bg: default attr: b} | |
# shape_nothing: light_cyan | |
# shape_operator: yellow | |
# shape_or: purple_bold | |
# shape_pipe: purple_bold | |
# shape_range: yellow_bold | |
# shape_raw_string: light_purple | |
# shape_record: cyan_bold | |
# shape_redirection: purple_bold | |
# shape_signature: green_bold | |
# shape_string: green | |
# shape_string: {|| if ($in | path exists) { 'bold_yellow_underline' } else { 'bold_yellow' } } | |
shape_string_interpolation: cyan_bold | |
# shape_table: blue_bold | |
# shape_variable: purple | |
# shape_vardecl: purple | |
} | |
# External completer example | |
# let carapace_completer = {|spans| | |
# carapace $spans.0 nushell ...$spans | from json | |
# } | |
# The default config record. This is where much of your global configuration is setup. | |
$env.config = { | |
show_banner: true # true or false to enable or disable the welcome banner at startup | |
ls: { | |
use_ls_colors: true # use the LS_COLORS environment variable to colorize output | |
clickable_links: true # enable or disable clickable links. Your terminal has to support links. | |
} | |
rm: { | |
always_trash: true # always act as if -t was given. Can be overridden with -p | |
} | |
table: { | |
mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other | |
index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column | |
show_empty: false # show 'empty list' and 'empty record' placeholders for command output | |
padding: {left: 1 right: 1} # a left right padding of each column in a table | |
trim: { | |
methodology: wrapping # wrapping or truncating | |
wrapping_try_keep_words: true # A strategy used by the 'wrapping' methodology | |
truncating_suffix: "…" # A suffix used by the 'truncating' methodology | |
} | |
header_on_separator: true # show header text on separator/border line | |
footer_inheritance: true # render foot in parent table if child is big enough (extended table option) | |
# abbreviated_row_count: 10 # limit data rows from top and bottom after reaching a set point | |
} | |
error_style: "fancy" # "fancy" or "plain" for screen reader-friendly error messages | |
# Whether an error message should be printed if an error of a certain kind is triggered. | |
display_errors: { | |
exit_code: false # assume the external command prints an error message | |
# Core dump errors are always printed, and SIGPIPE never triggers an error. | |
# The setting below controls message printing for termination by all other signals. | |
termination_signal: true | |
} | |
# datetime_format determines what a datetime rendered in the shell would look like. | |
# Behavior without this configuration point will be to "humanize" the datetime display, | |
# showing something like "a day ago." | |
datetime_format: { | |
# normal: '%a, %d %b %Y %H:%M:%S %z' # shows up in displays of variables or other datetime's outside of tables | |
# table: '%m/%d/%y %I:%M:%S%p' # generally shows up in tabular outputs such as ls. commenting this out will change it to the default human readable datetime format | |
} | |
explore: { | |
table: { | |
selected_cell: {bg: 'blue'} | |
show_cursor: false | |
} | |
try: { | |
reactive: true | |
} | |
} | |
history: { | |
max_size: 100_000_000 # Session has to be reloaded for this to take effect | |
sync_on_enter: true # Enable to share history between multiple sessions, else you have to close the session to write history to file | |
file_format: sqlite # "sqlite" or "plaintext" | |
isolation: true # only available with sqlite file_format. true enables history isolation, false disables it. true will allow the history to be isolated to the current session using up/down arrows. false will allow the history to be shared across all sessions. | |
} | |
completions: { | |
case_sensitive: false # set to true to enable case-sensitive completions | |
quick: true # set this to false to prevent auto-selecting completions when only one remains | |
partial: true # set this to false to prevent partial filling of the prompt | |
algorithm: "prefix" # prefix or fuzzy | |
sort: "smart" # "smart" (alphabetical for prefix matching, fuzzy score for fuzzy matching) or "alphabetical" | |
external: { | |
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up may be very slow | |
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options | |
completer: null # check 'carapace_completer' above as an example | |
} | |
use_ls_colors: true # set this to true to enable file/path/directory completions using LS_COLORS | |
} | |
filesize: { | |
# filesize.unit (string): One of either: | |
# - A filesize unit: "B", "kB", "KiB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "PB", "PiB", "EB", or "EiB". | |
# - An automatically scaled unit: "metric" or "binary". | |
# | |
# "metric" will use units with metric (SI) prefixes like kB, MB, or GB. | |
# "binary" will use units with binary prefixes like KiB, MiB, or GiB. | |
# Otherwise, setting this to one of the filesize units will use that particular unit when displaying all file sizes. | |
unit: 'B' | |
# filesize.precision (int or nothing): | |
# The number of digits to display after the decimal point for file sizes. | |
# When set to `null`, all digits after the decimal point will be displayed. | |
precision: 2 | |
# filesize.show_unit (bool): | |
# Whether to show or hide the file size unit. Useful if `$env.config.filesize.unit` is set to a fixed unit, | |
# and you don't want that same unit repeated over and over again in which case you can set this to `false`. | |
show_unit: false | |
} | |
# cursor_shape_* (string) | |
# ----------------------- | |
# The following variables accept a string from the following selections: | |
# "block", "underscore", "line", "blink_block", "blink_underscore", "blink_line", or "inherit" | |
# "inherit" skips setting cursor shape and uses the current terminal setting. | |
cursor_shape: { | |
emacs: underscore | |
vi_insert: block | |
vi_normal: line | |
} | |
color_config: $my_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record | |
# use_grid_icons: true | |
footer_mode: 5 # always, never, number_of_rows, auto | |
float_precision: 2 # the precision for displaying floats in tables | |
buffer_editor: "nvim" # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL | |
use_ansi_coloring: true | |
bracketed_paste: true # enable bracketed paste, currently useless on windows | |
edit_mode: emacs # emacs, vi | |
shell_integration: { | |
# osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title | |
osc2: true | |
# osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory | |
osc7: true | |
# osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it. show_clickable_links is deprecated in favor of osc8 | |
osc8: true | |
# osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal | |
osc9_9: true | |
# osc133 is several escapes invented by Final Term which include the supported ones below. | |
# 133;A - Mark prompt start | |
# 133;B - Mark prompt end | |
# 133;C - Mark pre-execution | |
# 133;D;exit - Mark execution finished with exit code | |
# This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is | |
osc133: true | |
# osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features | |
# 633;A - Mark prompt start | |
# 633;B - Mark prompt end | |
# 633;C - Mark pre-execution | |
# 633;D;exit - Mark execution finished with exit code | |
# 633;E - Explicitly set the command line with an optional nonce | |
# 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal | |
# and also helps with the run recent menu in vscode | |
osc633: true | |
# reset_application_mode is escape \x1b[?1l and was added to help ssh work better | |
reset_application_mode: true | |
} | |
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt. | |
use_kitty_protocol: true # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this. | |
highlight_resolved_externals: false # true enables highlighting of external commands in the repl resolved by which. | |
recursion_limit: 50 # the maximum number of times nushell allows recursion before stopping it | |
plugins: {} # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration. | |
plugin_gc: { | |
# Configuration for plugin garbage collection | |
default: { | |
enabled: true # true to enable stopping of inactive plugins | |
stop_after: 0sec # how long to wait after a plugin is inactive to stop it | |
} | |
plugins: { | |
# alternate configuration for specific plugins, by name, for example: | |
# | |
gstat: { | |
stop_after: 0sec | |
} | |
} | |
} | |
hooks: { | |
pre_prompt: [{ null }] # run before the prompt is shown | |
pre_execution: [{ null }] # run before the repl input is run | |
# env_change: { | |
# PWD: [{|before, after| null }] # run if the PWD environment is different since the last repl input | |
# } | |
env_change: { | |
# run if the PWD environment is different since the last repl input | |
PWD: [ | |
# Print lsg on each folder change | |
{|before, after| | |
print (lsg) | |
# null | |
} | |
# Print the startup time to a file but $before is null, which only happens on startup | |
{|before, _| | |
if $before == null { | |
let file = ($nu.home-path | path join ".local" "share" "nushell" "startup-times.nuon") | |
if not ($file | path exists) { | |
mkdir ($file | path dirname) | |
touch $file | |
} | |
let ver = (version) | |
open $file | append { | |
date: (date now) | |
time: $nu.startup-time | |
build: ($ver.build_rust_channel) | |
allocator: ($ver.allocator) | |
version: ($ver.version) | |
commit: ($ver.commit_hash) | |
build_time: ($ver.build_time) | |
bytes_loaded: (view files | get size | math sum) | |
} | collect { save --force $file } | |
} | |
} | |
{ | |
condition: {|_, after| not ($after | path join 'toolkit.nu' | path exists) } | |
code: "hide toolkit" | |
} | |
{ | |
condition: {|_, after| $after | path join 'toolkit.nu' | path exists } | |
code: " | |
print $'(ansi default_underline)(ansi default_bold)toolkit(ansi reset) module (ansi green_italic)detected(ansi reset)...' | |
print $'(ansi yellow_italic)activating(ansi reset) (ansi default_underline)(ansi default_bold)toolkit(ansi reset) module with `(ansi default_dimmed)(ansi default_italic)use toolkit.nu(ansi reset)`' | |
use toolkit.nu | |
" | |
} | |
] | |
} | |
# display_output: "if (term size).columns >= 100 { table -e } else { table }" # run to display the output of a pipeline | |
# display_output: table | |
display_output: { | |
metadata access {|meta| | |
match $meta.content_type? { | |
"application/x-nuscript"|"application/x-nuon"|"text/x-nushell" => { nu-highlight } | |
"application/json" => { ^bat --language=json --color=always --style=plain --paging=never } | |
"application/xml" => { ^bat -Ppf --language=xml } | |
"application/yaml" => { ^bat -Ppf --language=yaml } | |
"text/csv" => { ^bat -Ppf --language=csv } | |
"text/tab-separated-values" => { ^bat -Ppf --language=tsv } | |
"text/x-toml" => { ^bat -Ppf --language=toml } | |
"text/markdown" => { ^bat -Ppf --language=markdown } | |
_ => { } | |
} | |
} | table | |
} | |
# display_output: null | |
command_not_found: { null } # return an error message when a command is not found | |
} | |
menus: [ | |
# Configuration for default nushell menus | |
# Note the lack of source parameter | |
{ | |
name: completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
} | |
style: { | |
text: {fg: "#33ff00"} | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
selected_text: {attr: r} | |
# selected_text: { attr: r } | |
description_text: yellow | |
match_text: {attr: u} | |
selected_match_text: {attr: ur} | |
} | |
# style: { | |
# text: green | |
# selected_text: {attr: r} | |
# description_text: yellow | |
# } | |
} | |
{ | |
name: ide_completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: ide | |
min_completion_width: 0 | |
max_completion_width: 50 | |
max_completion_height: 10 # will be limited by the available lines in the terminal | |
padding: 0 | |
border: true | |
cursor_offset: 0 | |
description_mode: "prefer_right" | |
min_description_width: 0 | |
max_description_width: 50 | |
max_description_height: 10 | |
description_offset: 1 | |
# If true, the cursor pos will be corrected, so the suggestions match up with the typed text | |
# | |
# C:\> str | |
# str join | |
# str trim | |
# str split | |
correct_cursor_pos: false | |
} | |
style: { | |
# text: { fg: "#33ff00" } | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
# description_text: yellow | |
text: green | |
selected_text: {attr: r} | |
description_text: yellow | |
match_text: {fg: darkorange} | |
selected_match_text: {fg: darkorange attr: r} | |
} | |
} | |
{ | |
name: history_menu | |
only_buffer_difference: true | |
marker: $"(char -u '1f50d') " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#ffb000" | |
selected_text: {fg: "#ffb000" attr: r} | |
description_text: yellow | |
} | |
} | |
{ | |
name: help_menu | |
only_buffer_difference: true | |
marker: "? " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: "#7F00FF" | |
selected_text: {fg: "#ffff00" bg: "#7F00FF" attr: b} | |
description_text: "#ffff00" | |
} | |
} | |
# Example of extra menus created using a nushell source | |
# Use the source field to create a list of records that populates | |
# the menu | |
{ | |
name: fzf_history_fzf_ui_menu | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
open $nu.history-path | get history.command_line | |
| to text | fzf +s --tac | str trim | |
| where $it =~ $buffer | |
| each {|v| {value: ($v | str trim)} } | |
} | |
} | |
{ | |
name: fzf_nu_ui_menu | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#66ff66" | |
selected_text: {fg: "#66ff66" attr: r} | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
open $nu.history-path | get history.command_line | |
| to text | |
| fzf -f $buffer | |
| lines | |
| each {|v| {value: ($v | str trim)} } | |
} | |
} | |
{ | |
name: commands_menu | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each {|x| {value: $x.name description: $x.description} } | |
} | |
} | |
{ | |
name: vars_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope variables | |
| where name == $buffer | |
| each {|it| {value: $it.value} } | |
} | |
} | |
{ | |
name: commands_with_description_menu | |
only_buffer_difference: true | |
marker: "# " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each {|it| {value: $it.name description: $it.description} } | |
} | |
} | |
{ | |
name: abbr_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
scope aliases | |
| where name == $buffer | |
| each {|it| {value: $it.expansion} } | |
} | |
} | |
{ | |
name: grid_history_menu | |
only_buffer_difference: true | |
marker: "<?> " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: {|buffer, position| | |
history | |
| where command =~ $buffer | |
| where exit_status < 1 | |
| get command | |
| each {|it| {value: $it description: (try { help $"($it | str trim)" | lines | get 0 } catch { "" })} } | |
} | |
} | |
] | |
keybindings: [ | |
{ | |
name: paste | |
modifier: control_shift | |
keycode: char_v | |
mode: emacs | |
event: {edit: pastecutbufferbefore} | |
} | |
### Customizations | |
{ | |
name: clear | |
modifier: none | |
keycode: esc | |
mode: emacs | |
event: {edit: clear} | |
} | |
{ | |
name: fuzzy_history | |
modifier: control | |
keycode: char_r | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ | |
send: ExecuteHostCommand | |
cmd: "do { | |
$env.SHELL = 'C:\\Program Files\\Git\\bin\\bash.exe' | |
commandline edit -r ( | |
history | |
| get command | |
| reverse | |
| uniq | |
| str join (char -i 0) | |
| fzf --scheme=history --read0 --layout=reverse --height=40% --bind 'tab:change-preview-window(right,70%|right)' -q (commandline) --preview='echo -n {} | nu --stdin -c \'nu-highlight\'' | |
| decode utf-8 | |
| str trim | |
) | |
}" | |
} | |
] | |
} | |
{ | |
name: insert_newline | |
modifier: alt | |
keycode: char_i | |
mode: [emacs vi_normal vi_insert] | |
event: {edit: insertnewline} | |
} | |
{ | |
name: insert_newline | |
modifier: alt | |
keycode: enter | |
mode: [emacs vi_normal vi_insert] | |
event: {edit: insertnewline} | |
} | |
### Menus | |
{ | |
name: trigger-completion-menu | |
modifier: none | |
keycode: tab | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{send: menu name: completion_menu} | |
{send: menunext} | |
{edit: complete} | |
] | |
} | |
} | |
{ | |
name: trigger-history-menu | |
modifier: control | |
keycode: char_x | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{send: menu name: history_menu} | |
{send: menupagenext} | |
] | |
} | |
} | |
{ | |
name: trigger-help-menu | |
modifier: control | |
keycode: char_q | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{send: menu name: help_menu} | |
{send: menunext} | |
] | |
} | |
} | |
# Keybindings used to trigger the user defined menus | |
{ | |
#notworking | |
name: trigger-fzf_history_fzf_ui_menu | |
modifier: alt | |
keycode: char_e | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: fzf_history_fzf_ui_menu} | |
} | |
{ | |
name: trigger-fzf_nu_ui_menu | |
modifier: alt | |
keycode: char_w | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: fzf_nu_ui_menu} | |
} | |
{ | |
name: commands_menu | |
modifier: control | |
keycode: char_t | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: commands_menu} | |
} | |
{ | |
name: vars_menu | |
modifier: control | |
keycode: char_y | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{send: menu name: vars_menu} | |
{edit: insertchar value: ' '} | |
] | |
} | |
{ | |
name: trigger-commands_with_description_menu | |
modifier: control | |
keycode: char_u | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: commands_with_description_menu} | |
} | |
{ | |
name: trigger-grid-history-menu | |
modifier: control | |
keycode: char_i | |
mode: [emacs vi_normal vi_insert] | |
event: {send: menu name: grid_history_menu} | |
} | |
{ | |
name: trigger-abbr-menu | |
modifier: control | |
keycode: space | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{send: menu name: abbr_menu} | |
{edit: insertchar value: ' '} | |
] | |
} | |
] | |
} | |
# Directories to search for scripts when calling source or use | |
# The default for this is $nu.default-config-dir/scripts | |
const NU_LIB_DIRS = [ | |
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts | |
($nu.data-dir | path join 'completions') # default home for nushell completions | |
('~\source\repos\nu_scripts' | path expand) | |
($nu.cache-dir) | |
($nu.data-dir) | |
] | |
# Directories to search for plugin binaries when calling register | |
# The default for this is $nu.default-config-dir/plugins | |
$env.NU_PLUGIN_DIRS = [ | |
($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins | |
'C:\Users\fdncred\.cargo\bin' | |
] | |
# Custom Commands | |
source defs.nu | |
# prompt | |
use modules\prompt\oh-my.nu git_prompt | |
$env.PROMPT_COMMAND = {|| (git_prompt).left_prompt } | |
$env.PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt } | |
$env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) { $"(ansi green_bold)\n❯ (ansi reset)" } else { $"(ansi red_bold)\n❯ (ansi reset)" } } | |
$env.TRANSIENT_PROMPT_COMMAND = "" | |
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt } | |
$env.TRANSIENT_PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) { $"(ansi light_yellow_bold)❯ (ansi reset)" } else { $"(ansi light_red_bold)❯ (ansi reset)" } } | |
$env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e {fg: '#CB4B16'})(char -u '276f')(ansi -e {fg: '#CACA02'})(char -u '276f')(ansi -e {fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
# external completions | |
use custom-completions\cargo\cargo-completions.nu * | |
use aliases\git\git-aliases.nu * | |
use custom-completions\git\git-completions.nu * | |
use custom-completions\gh\gh-completions.nu * | |
use custom-completions\rustup\rustup-completions.nu * | |
# other modules | |
use std-rfc/tables aggregate | |
# weather | |
# use modules\weather\get-weather.nu get_weather | |
# Microsoft Visual Studio env vars | |
# use nu_msvs.nu | |
# nu_msvs activate # Use 'nu_msvs activate --help' to see all available options | |
# nu_msvs deactivate | |
# use modules\virtual_environments\nu_msvs\nu_msvs.nu | |
# nu_msvs activate --host x64 --target x64 | |
# temperature | |
# source sourced\temp.nu | |
# zoxide | |
source ~/.zoxide.nu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Hello, from defs.nu" | |
# check for env var exists | |
# "FOO" | env exists? | |
def "env exists?" [] { | |
each {|s| $s in (env).name } | |
} | |
let bn = (ansi {fg: '#ffffff' bg: '#000000'}) | |
let bb = (ansi {fg: '#ffffff' bg: '#555555'}) | |
let rn = (ansi {fg: '#ffffff' bg: '#AA0000'}) | |
let rb = (ansi {fg: '#ffffff' bg: '#FF5555'}) | |
let gn = (ansi {fg: '#000000' bg: '#00AA00'}) | |
let gb = (ansi {fg: '#000000' bg: '#55FF55'}) | |
let yn = (ansi {fg: '#000000' bg: '#AAAA00'}) | |
let yb = (ansi {fg: '#000000' bg: '#FFFF55'}) | |
let un = (ansi {fg: '#ffffff' bg: '#0000AA'}) | |
let ub = (ansi {fg: '#ffffff' bg: '#5555FF'}) | |
let mn = (ansi {fg: '#ffffff' bg: '#AA00AA'}) | |
let mb = (ansi {fg: '#ffffff' bg: '#FF55FF'}) | |
let cn = (ansi {fg: '#000000' bg: '#00AAAA'}) | |
let cb = (ansi {fg: '#000000' bg: '#55FFFF'}) | |
let wn = (ansi {fg: '#000000' bg: '#AAAAAA'}) | |
let wb = (ansi {fg: '#000000' bg: '#FFFFFF'}) | |
let s = 'XXXXXX' | |
let r = (ansi reset) | |
def standard-colors [] { | |
[ | |
[color normal bold]; | |
[Black $"($bn)($s)($r)" $"($bb)($s)($r)"] | |
[Red $"($rn)($s)($r)" $"($rb)($s)($r)"] | |
[Green $"($gn)($s)($r)" $"($gb)($s)($r)"] | |
[Yellow $"($yn)($s)($r)" $"($yb)($s)($r)"] | |
[Blue $"($un)($s)($r)" $"($ub)($s)($r)"] | |
[Magenta $"($mn)($s)($r)" $"($mb)($s)($r)"] | |
[Cyan $"($cn)($s)($r)" $"($cb)($s)($r)"] | |
[White $"($wn)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# https://www.ditig.com/256-colors-cheat-sheet | |
# 38;5;<num> for these palleted index numbers | |
# Xterm 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #800000 #008000 #808000 #000080 #800080 #008080 #C0C0C0 | |
# Xterm 8 9 10 11 12 13 14 15 | |
# Bold #808080 #FF0000 #00FF00 #FFFF00 #0000FF #FF00FF #00FFFF #FFFFFF | |
def wide-colors [] { | |
# Code 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #AA0000 #00AA00 #AAAA00 #0000AA #AA00AA #00AAAA #AAAAAA | |
# Bold #555555 #FF5555 #55FF55 #FFFF55 #5555FF #FF55FF #55FFFF #FFFFFF | |
# [code '0' '1' '2' '3' '4' '5' '6' '7']; | |
[ | |
[name black red green yellow blue magenta cyan white]; | |
[normal $"($bn)($s)($r)" $"($rn)($s)($r)" $"($gn)($s)($r)" $"($yn)($s)($r)" $"($un)($s)($r)" $"($mn)($s)($r)" $"($cn)($s)($r)" $"($wn)($s)($r)"] | |
[bold $"($bb)($s)($r)" $"($rb)($s)($r)" $"($gb)($s)($r)" $"($yb)($s)($r)" $"($ub)($s)($r)" $"($mb)($s)($r)" $"($cb)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# get the terminal size with ansi escape codes | |
def terminal-size [] { | |
let sz = (input (ansi size) --bytes-until-any 'R' --suppress-output) | |
# $sz should look like this | |
# Length: 9 (0x9) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5b 33 38 3b 31 35 30 52 •[38;150R | |
# let sz_len = ($sz | size).bytes | |
let sz_len = ($sz | str length) | |
# so let's skip the esc[ and R | |
# let r = (for x in 2..($sz_len - 2) { | |
# # This substring removes the 0x added by format number | |
# char -u (($sz | get $x | into int | format number).lowerhex | str substring '2,') | |
# } | str join) | |
let r = ($sz | str substring 1..($sz_len - 1)) | |
# $r should look like 38;150 | |
let size = ($r | split row ';') | |
# output in record syntax | |
{ | |
columns: ($size | get 1 | into int) | |
rows: ($size | get 0 | into int) | |
} | |
} | |
# get background color with x11 ansi escapes | |
# have to hit ctrl+g after the statement to get the value in $x | |
# let x = input $"(ansi -o '11;?')(char bel)" --bytes-until (char bel) | |
# when input = rgb:4_numbers/4_numbers/4_numbers like rgb:1919/1313/2323 | |
# this means 16-bit rgb components. 16^4 means four hex digits. FFFF is 65535 | |
# 48-bit color. it could be 1 number 4-bits, 2 8-bits, 3 12-bits, 4 16-bits | |
# #3a7 is the same as #3000a0007000. | |
# refernce https://www.x.org/releases/X11R7.7/doc/man/man7/X.7.xhtml#heading11 | |
# mine was rgb:1919/1313/2323 | |
# (('1919' | into int -r 16) / 256 | math round | format number).lowerhex | |
# (('1313' | into int -r 16) / 256 | math round | format number).lowerhex | |
# (('2323' | into int -r 16) / 256 | math round | format number).lowerhex | |
# or | |
# 0x1919 / 0x100 | math round | |
# 0x1313 / 0x100 | math round | |
# 0x2323 / 0x100 | math round | |
# Get the background color through ansi escape sequences | |
def get-bg [] { | |
# get the response from the ansi escape sequence from the terminal | |
# have to hit control+g in kitty to get value in $bg | |
let bg = (input $"(ansi -o '11;?')(ansi st)" --bytes-until-any (ansi st) --suppress-output) | |
# $bg should look like this | |
# assumes output of the form ":0000/0000/0000" | |
# it should really look like "esc]11;rgb:0000/0000/0000esc\", not sure why it doesn't | |
# Length: 26 (0x1a) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 31 39 31 39 2f 31 33 •]11;rgb:1919/13 | |
# 00000010: 31 33 2f 32 33 32 33 1b 5c 07 13/2323•\• | |
# jt's output | |
# Length: 24 (0x18) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 33 66 33 66 2f 33 66 •]11;rgb:3f3f/3f | |
# 00000010: 33 66 2f 33 66 33 66 07 3f/3f3f• | |
# so let's skip the prefix and suffix and just get | |
# 1919/1313/2323 | |
# let rgb_string = ($bg | split chars | range 9..22 | str join) | |
# TODO figure how other ways that string can start so we can programmatically | |
# calculate the start_index better. It's probably not always \x1b]11;rgb: | |
# let start_index = 9 | |
# let end_index = ($bg | bytes index-of 0x[1b 5c]) | |
# get the rgb values | |
let start_index = ($bg | str index-of ':' | into int) + 1 | |
let end_index = $bg | str length | |
# let term_data = $bg | into binary | bytes at $start_index..$end_index | |
# let rgb_string = ($term_data | decode utf-8) | |
let rgb_string = $bg | str substring $start_index..$end_index | |
# let bg_len = ($bg | size).bytes | |
# # so let's skip the prefix and suffix and just get | |
# # 1919/1313/2323 | |
# let rgb_string = (for x in 9..($bg_len - 4) { | |
# # This substring removes the 0x added by format number after conversion to char | |
# char -u (($bg | get $x | into int | format number).lowerhex | str substring '2,') | |
# } | str join) | |
# split the rgb string into the individual values | |
let rgb = $rgb_string | split row '/' | |
let r = $rgb | get 0 | |
let g = $rgb | get 1 | |
let b = $rgb | get 2 | |
# ('1313' | into int -r 16) / 256 | math round | format number).lowerhex | |
# convert the rgb values to hex | |
let red = (($r | into int -r 16) / 256 | math round | format number).lowerhex | |
let green = (($g | into int -r 16) / 256 | math round | format number).lowerhex | |
let blue = (($b | into int -r 16) / 256 | math round | format number).lowerhex | |
# output in record syntax | |
{ | |
red: $red | |
green: $green | |
blue: $blue | |
hex: $"(ansi default)#($red | str substring 2.. | fill -a r -c 0 -w 2)($green | str substring 2.. | fill -a r -c 0 -w 2)($blue | str substring 2.. | fill -a r -c 0 -w 2)(ansi reset)" | |
rgb: $"RGB(char lp)(($red | into int | format number).display), (($green | into int | format number).display), (($blue | into int | format number).display)(char rp)" | |
} | |
} | |
# Clear the screen with ansi escapes | |
def cls [] { | |
ansi cls | |
} | |
# Full term reset, cls, clear buffer, attributes off, | |
def clsterm [] { | |
$"(ansi esc)c(ansi clsb)(ansi cls)(ansi reset)(ansi home)" | |
} | |
# good for things like this | |
# ps | where name =~ Firefox | get mem | sum | |
def sum [] { | |
reduce {|acc, item| $acc + $item } | |
} | |
# written by Kubouch for virtualenv | |
def is-string [ | |
x # value to check to see if it's a string | |
] { | |
($x | describe) == "string" | |
} | |
def has-env [name: string] { | |
$name in (env).name | |
} | |
def --env goto [] { | |
let input = $in | |
cd ( | |
if ($input | path type) == file { | |
($input | path dirname) | |
} else { | |
$input | |
} | |
) | |
} | |
def cargo_tests [] { | |
cargo nextest run --all --all-features | |
} | |
def cargo_clippy [] { | |
cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err | |
} | |
# alias the built-in ls command to ls-builtin | |
alias ls-builtin = ls | |
# List the filenames, sizes, and modification times of items in a directory. | |
def ls [ | |
--all (-a), # Show hidden files | |
--long (-l), # Get all available columns for each entry (slower; columns are platform-dependent) | |
--short-names (-s), # Only print the file names, and not the path | |
--full-paths (-f), # display paths as absolute paths | |
--du (-d), # Display the apparent directory size ("disk usage") in place of the directory metadata size | |
--directory (-D), # List the specified directory itself instead of its contents | |
--mime-type (-m), # Show mime-type in type column instead of 'file' (based on filenames only; files' contents are not examined) | |
--threads (-t), # Use multiple threads to list contents. Output will be non-deterministic. | |
...pattern: glob, # The glob pattern to use. | |
]: [nothing -> table] { | |
let pattern = if ($pattern | is-empty) { ['.'] } else { $pattern } | |
( | |
ls-builtin | |
--all=$all | |
--long=$long | |
--short-names=$short_names | |
--full-paths=$full_paths | |
--du=$du | |
--directory=$directory | |
--mime-type=$mime_type | |
--threads=$threads | |
...$pattern | |
) | sort-by type name -i | |
} | |
def stars [] { | |
http get https://api.github.com/repos/nushell/nushell | get stargazers_count | |
} | |
def --env hide_prompt [] { | |
hide-env PROMPT_COMMAND | |
hide-env PROMPT_COMMAND_RIGHT | |
hide-env PROMPT_INDICATOR | |
} | |
def show_banner [] { | |
let ellie = [ | |
" __ ," | |
" .--()°'.'" | |
"'|, . ,' " | |
' !_-(_\ ' | |
] | |
let s = (sys) | |
print $"(ansi reset)(ansi green)($ellie.0)" | |
print $"(ansi green)($ellie.1) (ansi yellow) (ansi yellow_bold)Nushell (ansi reset)(ansi yellow)v(version | get version)(ansi reset)" | |
print $"(ansi green)($ellie.2) (ansi light_blue) (ansi light_blue_bold)RAM (ansi reset)(ansi light_blue)($s.mem.used) / ($s.mem.total)(ansi reset)" | |
print $"(ansi green)($ellie.3) (ansi light_purple)ﮫ (ansi light_purple_bold)Uptime (ansi reset)(ansi light_purple)($s.host.uptime)(ansi reset)" | |
} | |
# load visual studio environment | |
def --env vsenv [] { | |
print "Loading Visual Studio Environment" | |
let vsdev = (cmd /c "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 &set) | |
let vars = $vsdev | decode utf8 | lines -s | each {|var| parse "{KEY}={VAL}" } | flatten | where KEY != PWD | |
$vars | reduce -f {} {|i, acc| $acc | upsert $i.KEY $i.VAL } | load-env | |
print "Completed loading VS environment" | |
} | |
# get the environment details | |
def "env details" [] { | |
let e = ($env | reject config | transpose key value) | |
$e | each {|r| | |
let is_envc = ($r.key == ENV_CONVERSIONS) | |
let is_closure = ($r.value | describe | str contains 'closure') | |
let is_list = ($r.value | describe | str contains 'list') | |
if $is_envc { | |
echo [ | |
[key value]; | |
[ | |
($r.key) | |
( | |
$r.value | transpose key value | each {|ec| | |
let to_string = ($ec.value | get to_string | view source $in | nu-highlight) | |
let from_string = ($ec.value | get from_string | view source $in | nu-highlight) | |
echo ({'ENV_CONVERSIONS': {($ec.key): {'to_string': ($to_string) 'from_string': ($from_string)}}}) | |
} | |
) | |
] | |
] | |
} else if $is_closure { | |
let closure_value = (view source ($env | get $r.key) | nu-highlight) | |
echo [[key value]; [($r.key) ($closure_value)]] | |
} else if $is_list { | |
let list_value = ($env | get $r.key | split row (char esep)) | |
echo [[key value]; [($r.key) ($list_value)]] | |
} else { | |
echo [[key value]; [($r.key) ($r.value)]] | |
} | |
} | |
} | |
def env [] { env details | flatten | table -e } | |
# get windows service status | |
def get-win-svc [] { | |
sc queryex type=service state=all | collect {|x| | |
$x | parse -r '(?m)SERVICE_NAME:\s*(?<svc>\w*)\s*DISPLAY_NAME:\s*(?<dsp>.*)\s*TYPE\s*:\s*(?<type>[\da-f]*)\s*(?<typename>\w*)?\s*\s*STATE\s*:\s*(?<state>\d)\s*(?<status>\w*)\s*(?<state_opts>\(.*\))?\s*?WIN32_EXIT_CODE\s*:\s*(?<exit>\d*).*\s*SERVICE_EXIT_CODE\s*:\s*(?<svc_exit>\d)\s*.*\s*CHECKPOINT\s*:\s*(?<chkpt>.*)\s*WAIT_HINT\s*:\s(?<wait>.*)\s*PID\s*:\s*(?<pid>\d*)\s*FLAGS\s*:\s(?<flags>.*)?' | upsert status {|s| | |
if $s.status == RUNNING { | |
$"(ansi green)●(ansi reset)" | |
} else { | |
$"(ansi red)●(ansi reset)" | |
} | |
} | into int state exit svc_exit chkpt wait pid | |
} | |
} | |
# Only list the nushell environment variables | |
def env-nu [] { | |
$env | transpose key value | each {|r| | |
if ($r.value | describe) != string { | |
$r | |
} | |
} | transpose -ird | |
} | |
# Show a summarized table of nushell startup times | |
def startup-stats [] { | |
open ~/.local/share/nushell/startup-times.nuon | where build == release | group-by commit --to-table | rename commit data | update commit {|c| | |
$c.commit | str substring 0..7 | |
} | upsert perf {|r| | |
if ($r.data | length) > 3 { | |
# This throws out outliers by removing the top 3 times | |
$r.data.time | sort | slice 0..(-3) | math avg | |
} else { | |
$r.data.time | math avg | |
} | |
} | upsert start_date {|s| | |
$s.data.date | sort | math min | format date '%Y-%m-%d' | |
} | upsert end_date {|e| | |
$e.data.date | sort | math max | format date '%Y-%m-%d' | |
} | upsert num_startups {|n| | |
$n.data | length | |
} | upsert bytes_loaded {|b| | |
$b.data.bytes_loaded | math avg | |
} | upsert perf_per_byte {|s| | |
# This throws out outliers by removing the top 3 times | |
# sum_of_time / sum_of_bytes_loaded | |
if ($s.data.time | length) > 3 { | |
($s.data.time | sort | slice 0..(-3) | math sum) / ($s.data.bytes_loaded | math sum) | |
} else { | |
($s.data.time | math sum) / ($s.data.bytes_loaded | math sum) | |
} | |
} | sort-by start_date | |
} | |
# fzf with help commands | |
def helps [] { | |
help commands | get name | str join "\n" | fzf --preview-window 'up,60%,border-bottom,+{2}+3/3,~1' --preview 'nu -l -c "help {1} {2}"' | |
# https://github.com/junegunn/fzf/blob/master/ADVANCED.md | |
# The value of --preview-window option consists of 5 components delimited by , | |
# up — Position of the preview window | |
# 60% — Size of the preview window | |
# border-bottom — Preview window border only on the bottom side | |
# +{2}+3/3 — Scroll offset of the preview contents | |
# ~3 — Fixed header | |
# Let's break down the latter two. We want to display the bat output in the preview window with a certain scroll offset so that the matching line is positioned near the center of the preview window. | |
# +{2} — The base offset is extracted from the second token | |
# +3 — We add 3 lines to the base offset to compensate for the header part of bat output | |
# ───────┬────────────────────────────────────────────────────────── | |
# │ File: CHANGELOG.md | |
# ───────┼────────────────────────────────────────────────────────── | |
# 1 │ CHANGELOG | |
# 2 │ ========= | |
# 3 │ | |
# 4 │ 0.26.0 | |
# 5 │ ------ | |
# /3 adjusts the offset so that the matching line is shown at a third position in the window | |
# ~3 makes the top three lines fixed header so that they are always visible regardless of the scroll offset | |
# help commands | |
# | get name | |
# | str join "\n" | |
# | fzf --preview $"nu --config ($nu.config-path) --env-config ($nu.env-path) -c 'help {}'" | |
} | |
# Check how many downloads nushell has had | |
def nudown [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | get assets | flatten | select name download_count created_at | update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S' } | |
} | |
# Check how many downloads nushell has had | |
def get_github_downloads [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | get assets | flatten | select name download_count created_at | update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S' } | |
} | |
# Get brew downloads for the past 30 days | |
def get_brew_downloads [] { | |
let brew_dl = (http get https://formulae.brew.sh/api/formula/nushell.json) | |
let macos_dl = ($brew_dl | get analytics.install.30d.nushell) | |
# let linux_dl = ($brew_dl | get analytics-linux.install.30d.nushell) | |
# [[os downloads]; [macos $macos_dl] [linux $linux_dl]] | |
[[os downloads]; [macos $macos_dl]] | |
} | |
# Get cargo downloads for crate | |
def "get_cargo_downloads" [crate: string, version: string] { | |
# alternatively scrape this | |
# http get https://crates.io/api/v1/crates/nu | |
# http get https://crates.io/api/v1/crates/nu/0.76.0 | get version | |
# cargo info $crate | |
# | lines | |
# | parse "{key}: {value}" | |
# | str trim | |
# | transpose -r | |
# | into record | |
# | merge ({ | |
# versions: ( | |
# cargo info $crate -VV | |
# | lines -s | |
# | skip 1 | |
# | parse --regex '(?<version>\d+\.\d+\.\d+)\s+(?<released>.* ago)\s+(?<downloads>\d+)' | |
# | into int downloads | |
# ) | |
# }) | |
http get $'https://crates.io/api/v1/crates/($crate)/($version)' | get version | get downloads | |
} | |
# Get all the downloads for nushell | |
def get_all_nu_downloads [version = "0.76.0"] { | |
let github_dl = (get_github_downloads | where name =~ $version | get download_count | math sum) | |
let brew_dl = (get_brew_downloads | get downloads | math sum) | |
let cargo_dl = (get_cargo_downloads nu $version) | |
[[source downloads]; [github $github_dl] [brew $brew_dl] [cargo $cargo_dl] [sum ($github_dl + $brew_dl + $cargo_dl)]] | |
} | |
# get the system uptime | |
def uptime [] { | |
# sys | get host | get uptime | |
(sys).host.uptime | |
} | |
# get the terminals default 16 colors. not supported on all terminals. | |
def get-terminal-colors [] { | |
let color_00 = (input $"(ansi -o '4;0;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_01 = (input $"(ansi -o '4;1;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_02 = (input $"(ansi -o '4;2;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_03 = (input $"(ansi -o '4;3;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_04 = (input $"(ansi -o '4;4;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_05 = (input $"(ansi -o '4;5;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_06 = (input $"(ansi -o '4;6;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_07 = (input $"(ansi -o '4;7;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_08 = (input $"(ansi -o '4;8;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_09 = (input $"(ansi -o '4;9;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_10 = (input $"(ansi -o '4;10;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_11 = (input $"(ansi -o '4;11;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_12 = (input $"(ansi -o '4;12;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_13 = (input $"(ansi -o '4;13;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_14 = (input $"(ansi -o '4;14;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
let color_15 = (input $"(ansi -o '4;15;?')(ansi st)" --bytes-until-any "\e\\" -s) | |
# goes through 4;255;? | |
[ | |
$color_00 | |
$color_01 | |
$color_02 | |
$color_03 | |
$color_04 | |
$color_05 | |
$color_06 | |
$color_07 | |
$color_08 | |
$color_09 | |
$color_10 | |
$color_11 | |
$color_12 | |
$color_13 | |
$color_14 | |
$color_15 | |
] | each {|col| | |
let rgb = $col | split row : | get 1 | split row / | |
# 16bit rgb to 8bit = 0xe7e7 | bits and 0x00ff | |
let red = ($"0x($rgb | get 0)" | into int | bits and 0x00ff) | |
let green = ($"0x($rgb | get 1)" | into int | bits and 0x00ff) | |
let blue = ($"0x($rgb | get 2)" | into int | bits and 0x00ff) | |
let red_hx = ($red | format number).lowerhex | str substring 2.. | |
let green_hx = ($green | format number).lowerhex | str substring 2.. | |
let blue_hx = ($blue | format number).lowerhex | str substring 2.. | |
{ | |
red: $red_hx | |
green: $green_hx | |
blue: $blue_hx | |
hex: $"#($red_hx)($green_hx)($blue_hx)" | |
rgb: $"RGB(char lp)($red), ($green), ($blue)(char rp)" | |
} | |
} | |
} | |
# Deletes a history entry. | |
def 'history remove-item' [ | |
id: int = 0 # the id of the history entry to delete | |
--last # delete the last entry, ignore the id, if passed | |
] { | |
if $last { | |
open $nu.history-path | query db $"delete from history where id = \(select id from \(select id from history where session_id = (history session) order by id desc LIMIT 2) order by id asc LIMIT 1)" | |
} else { | |
if $id == 0 { | |
echo "You must pass an id or use --last" | |
exit 1 | |
} | |
open $nu.history-path | query db $"delete from history where id = ($id)" | |
} | |
null | |
} | |
# Find files using ripgrep (CDNcred from Discord) | |
def rgfind [file] { rg --files - . --no-messages | rg -S $file } | |
# Get my external ip address information (CDNcred + NotThe Dr01ds from Discord) | |
def whatsmyip [] { http get -H {User-agent: "curl"} http://ipinfo.io/what-is-my-ip } | |
# Return a list of indexes for the pattern provided. | |
def "str indices-of" [pattern: string]: string -> list<int> { | |
let searchString = $in | |
let parsePattern = ['(?P<matches>' $pattern ')'] | str join | |
let matches = ($searchString | parse -r $parsePattern | get matches) | |
$matches | reduce -f [] {|it, acc| | |
let match = $it | |
let startSearchFrom = ( | |
if $acc == [] { 0 } else { $acc | last | get end } | |
) | |
let begin = ($searchString | str index-of $match --range ($startSearchFrom)..) | |
let end = $begin + ($match | str length) | |
[ | |
...$acc | |
{ | |
match: $match | |
begin: $begin | |
end: $end | |
} | |
] | |
} | |
} | |
def "get help" [] { | |
do { | |
$env.SHELL = 'c:\Users\fdncred\.cargo\bin\nu.exe' | |
help commands | where command_type == built-in | |
| each {|c| | |
let search_terms = if ($c.search_terms == "") { "" } else { $"\(($c.search_terms))" } | |
let category = if ($c.category == "") { "" } else { $"\(Category: ($c.category))" } | |
$"(ansi white)($c.name?):(ansi light_blue) ($c.usage?) (ansi blue)($search_terms) ($category)(ansi reset)" | |
} | |
| to text | |
| fzf --ansi --tiebreak=begin,end,chunk --bind 'tab:change-preview-window(right,70%|right)' --preview="^echo {+1} {+2} {+3} | nu --stdin -c 'help ($in | parse `{c}:{u}` | get c.0) | nu-highlight'" --exact | |
} | |
} | |
# diff two tables (by devyn) | |
def table-diff [ | |
$left: list<any>, | |
$right: list<any>, | |
--keys (-k): list<string> = [], | |
] { | |
let left = if ($left | describe) !~ '^table' { $left | wrap value } else { $left } | |
let right = if ($right | describe) !~ '^table' { $right | wrap value } else { $right } | |
let left_selected = ($left | select ...$keys) | |
let right_selected = ($right | select ...$keys) | |
let left_not_in_right = ( | |
$left | filter {|row| not (($row | select ...$keys) in $right_selected) } | |
) | |
let right_not_in_left = ( | |
$right | filter {|row| not (($row | select ...$keys) in $left_selected) } | |
) | |
( | |
$left_not_in_right | insert side '<=' | |
) ++ ( | |
$right_not_in_left | insert side '=>' | |
) | |
} | |
# Wrapper for the pspg pager | |
def --wrapped pspg [...args] { | |
let input = $in | |
$env.config.ls.clickable_links = false | |
$env.config.table.mode = 'rounded' | |
$env.config.table.header_on_separator = false | |
$env.config.footer_mode = 'never' | |
$input | ^pspg ...$args | |
} | |
# get the list of plugins without all the extra columns | |
def plugins [] { | |
plugin list | update commands { str join ', ' } | reject shell | update filename { path parse | get stem } | table --index 1 | |
} | |
# get the version information formatting the plugins differently | |
def ver [ --markdown (-m)] { | |
let plugin_modified = plugin list | insert last_modified {|plug| | |
ls $plug.filename | get 0?.modified? | |
} | select name last_modified | |
let ver = version | upsert build_time { into datetime } | upsert installed_plugins {|v| | |
$v | get installed_plugins | split row ', ' | parse '{name} {version}' | join $plugin_modified name | |
} | |
if $markdown { | |
$ver | to md | |
} else { | |
$ver | table -e | |
} | |
} | |
# show the nushell version in markdown with nested table for plugins | |
def ver2md [] { | |
let plugin_modified = plugin list | insert last_modified {|plug| | |
ls $plug.filename | get 0?.modified? | |
} | select name last_modified | update last_modified { format date %FT%T } | |
let plugin_version = version | get installed_plugins | split row ', ' | parse '{name} {version}' | |
let plugin_details_html = $plugin_version | join $plugin_modified name | to html --dark | |
let table_begin = $plugin_details_html | str index-of '<table>' | |
let table_end = $plugin_details_html | str index-of '</table>' | $in + 7 | |
let version_details_md = version | update build_time { | |
$in | into datetime | format date %FT%T | |
} | reject installed_plugins | transpose key value | to md | |
print $version_details_md | |
print $"|installed_plugins|($plugin_details_html | str substring $table_begin..$table_end)|" | |
} | |
# show the table output with alternating colors per row | |
# example: ls | table alternate | |
def "table alternate" [ | |
style: string = "reinforced" | |
even_color: string = "blue_reverse" | |
odd_color: string = "cyan_reverse" | |
header_color: string = "blue" | |
]: table -> string { | |
$in | table -t $style | ansi strip | lines | |
| each { | |
let row_num = ( | |
$in | ansi strip | parse -r '.*?(\d+).*' | |
| get capture0?.0? | |
| try { into int } catch { null } | |
) | |
let row_type = match $row_num { | |
null => 'other' | |
_ => ( | |
match ($row_num mod 2) { | |
0 => 'even' | |
_ => 'odd' | |
} | |
) | |
} | |
match $row_type { | |
odd => $"(ansi $odd_color)($in)(ansi reset)" | |
even => $"(ansi $even_color)($in)(ansi reset)" | |
_ => $"(ansi $header_color)($in)(ansi reset)" | |
} | |
} | |
| to text | |
} | |
# Delete all branches that are not in the excepts list | |
# Usage: del-branches [main] | |
def del-branches [ | |
excepts: list # don't delete branch in the list | |
--dry-run (-d) # do a dry-run | |
] { | |
let branches = (git branch | lines | str trim) | |
let remote_branches = (git branch -r | lines | str replace -r '^.+?/' '' | uniq) | |
if $dry_run { | |
print "Starting Dry-Run" | |
} else { | |
print "Deleting for real" | |
} | |
$branches | each {|it| | |
if ($it not-in $excepts) and ($it not-in $remote_branches) and (not ($it | str starts-with "*")) { | |
# git branch -D $it | |
if $dry_run { | |
print $"git branch -D ($it)" | |
} else { | |
print $"Deleting ($it) for real" | |
git branch -D $it | |
} | |
} | |
} | |
} | |
# emulate split-by command | |
def split-by2 [splitter: string]: record -> record { | |
transpose -d record_split_keys values | |
| flatten --all | |
| group-by --to-table ([$splitter] | into cell-path) | |
| update items { | |
group-by --to-table record_split_keys | |
| update items { reject record_split_keys } | |
| transpose -dr | |
} | |
| transpose -dr | |
} | |
# rg wrapper that returns a table | |
def --wrapped rgn [pattern: string, ...rest] { | |
rg --json $pattern ...$rest | |
| lines | |
| each { from json } | |
| where type == 'match' | |
| get data | |
| select path lines | |
| update cells { get text } | |
| update lines { find $pattern } | |
| rename name | |
} | |
# Avoid duplicating values in a list with prepend | |
@example "Avoid prepending duplicates in $env.PATH" { | |
$env.PATH = ( | |
$env.PATH | split row (char esep) | |
| prepend-if-not-in ($env.HOME | path join ".local" "bin") | |
| prepend-if-not-in ($env.CARGO_HOME | path join "bin") | |
) | |
} | |
def prepend-if-not-in [ | |
value: string | |
] { | |
let list = $in | |
$list | if ($value in $list) { $in } else { $in | prepend $value } | |
} | |
# Avoid duplicating values in a list with append | |
@example "Avoid appending duplicates in $env.PATH" { | |
$env.PATH = ( | |
$env.PATH | split row (char esep) | |
| append-if-not-in ($env.HOME | path join ".local" "bin") | |
| append-if-not-in ($env.CARGO_HOME | path join "bin") | |
) | |
} | |
def append-if-not-in [ | |
value: string | |
] { | |
let list = $in | |
$list | if ($value in $list) { $in } else { $in | append $value } | |
} | |
# See what files are in your autoload directories | |
def ls-autoload-dirs [] { | |
print $"(ansi light_green)checking user autoload dirs...(ansi reset)" | |
$nu.user-autoload-dirs | each {|dir| | |
print $"(ansi yellow_bold)checking ($dir | path expand)(ansi reset)" | |
if ($dir | path expand | path exists) { | |
print (ls -a ($dir | path expand)) | |
} else { | |
print $"(ansi red_bold)($dir | path expand) does not exist(ansi reset)" | |
} | |
} | |
print $"(ansi light_green)checking system autoload dirs...(ansi reset)" | |
$nu.vendor-autoload-dirs | each {|dir| | |
print $"(ansi yellow_bold)checking ($dir | path expand)(ansi reset)" | |
if ($dir | path expand | path exists) { | |
print (ls -a ($dir | path expand)) | |
} else { | |
print $"(ansi red_bold)($dir | path expand) does not exist(ansi reset)" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nushell Environment Config File | |
# | |
# version = "0.103.1" | |
print "Hello, from env.nu" | |
$env.LESS = "-FRXS" | |
$env.PAGER = "less" | |
$env.GIT_REPOS_HOME = 'C:\Users\fdncred\source\repos' | |
$env.EDITOR = "nvim" | |
$env.VISUAL = "nvim" | |
$env.LIBCLANG_PATH = 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\' | |
# $env.TOPIARY_CONFIG_FILE = ($nu.default-config-dir | path join topiary languages.ncl) | |
# $env.TOPIARY_LANGUAGE_DIR = ($nu.default-config-dir | path join topiary languages) | |
$env.TOPIARY_CONFIG_FILE = "C:/Users/fdncred/source/repos/topiary-nushell/languages.ncl" | |
$env.TOPIARY_LANGUAGE_DIR = "C:/Users/fdncred/source/repos/topiary-nushell/languages" | |
# def create_left_prompt [] { | |
# let dir = match (do --ignore-errors { $env.PWD | path relative-to $nu.home-path }) { | |
# null => $env.PWD | |
# '' => '~' | |
# $relative_pwd => ([~ $relative_pwd] | path join) | |
# } | |
# let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold }) | |
# let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold }) | |
# let path_segment = $"($path_color)($dir)" | |
# $path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)" | |
# } | |
# def create_right_prompt [] { | |
# # create a right prompt in magenta with green separators and am/pm underlined | |
# let time_segment = ([ | |
# (ansi reset) | |
# (ansi magenta) | |
# (date now | format date '%x %X') # try to respect user's locale | |
# ] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" | | |
# str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}") | |
# let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([ | |
# (ansi rb) | |
# ($env.LAST_EXIT_CODE) | |
# ] | str join) | |
# } else { "" } | |
# ([$last_exit_code, (char space), $time_segment] | str join) | |
# } | |
# Use nushell functions to define your right and left prompt | |
# $env.PROMPT_COMMAND = {|| create_left_prompt } | |
# FIXME: This default is not implemented in rust code as of 2023-09-08. | |
# $env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt } | |
# The prompt indicators are environmental variables that represent | |
# the state of the prompt | |
# $env.PROMPT_INDICATOR = {|| "> " } | |
# $env.PROMPT_INDICATOR_VI_INSERT = {|| ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " } | |
# $env.PROMPT_MULTILINE_INDICATOR = {|| "::: " } | |
# $env.PROMPT_INDICATOR = {|| " " } | |
# $env.PROMPT_INDICATOR_VI_INSERT = {|| ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = {|| "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = $"(ansi -e { fg: '#66cdaa'})(char -u 276f)(ansi -e { fg: '#76eec6'})(char -u 276f)(ansi -e { fg: '#7fffd4'})(char -u 276f)(ansi reset)(char space)" | |
# $env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e { fg: '#CB4B16'})(char -u '276f')(ansi -e { fg: '#CACA02'})(char -u '276f')(ansi -e { fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
# If you want previously entered commands to have a different prompt from the usual one, | |
# you can uncomment one or more of the following lines. | |
# This can be useful if you have a 2-line prompt and it's taking up a lot of space | |
# because every command entered takes up 2 lines instead of 1. You can then uncomment | |
# the line below so that previously entered commands show with a single `🚀`. | |
# $env.TRANSIENT_PROMPT_COMMAND = {|| "🚀 " } | |
# $env.TRANSIENT_PROMPT_INDICATOR = {|| "" } | |
# $env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT = {|| "" } | |
# $env.TRANSIENT_PROMPT_INDICATOR_VI_NORMAL = {|| "" } | |
# $env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = {|| "" } | |
# $env.TRANSIENT_PROMPT_COMMAND_RIGHT = {|| "" } | |
# Specifies how environment variables are: | |
# - converted from a string to a value on Nushell startup (from_string) | |
# - converted from a value back to a string when running external commands (to_string) | |
# Note: The conversions happen *after* config.nu is loaded | |
# $env.ENV_CONVERSIONS = { | |
# "PATH": { | |
# from_string: { |s| $s | split row (char esep) | path expand --no-symlink } | |
# to_string: { |v| $v | path expand --no-symlink | str join (char esep) } | |
# } | |
# "Path": { | |
# from_string: { |s| $s | split row (char esep) | path expand --no-symlink } | |
# to_string: { |v| $v | path expand --no-symlink | str join (char esep) } | |
# } | |
# } | |
export-env { | |
let esep_list_converter = { | |
from_string: {|s| $s | split row (char esep) } | |
to_string: {|v| $v | str join (char esep) } | |
} | |
let esep_path_converter = { | |
from_string: {|s| $s | split row (char esep) } | |
to_string: {|v| $v | path expand | str join (char esep) } | |
} | |
$env.ENV_CONVERSIONS = { | |
Path: $esep_path_converter | |
LS_COLORS: $esep_list_converter | |
DYLD_FALLBACK_LIBRARY_PATH: $esep_path_converter | |
PATHEXT: $esep_list_converter | |
PSModulePath: $esep_path_converter | |
} | |
} | |
# # Directories to search for scripts when calling source or use | |
# # The default for this is $nu.default-config-dir/scripts | |
# $env.NU_LIB_DIRS = [ | |
# ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts | |
# ($nu.data-dir | path join 'completions') # default home for nushell completions | |
# ('~\source\repos\nu_scripts' | path expand) | |
# ($nu.cache-dir) | |
# ($nu.data-dir) | |
# ] | |
# # Directories to search for plugin binaries when calling register | |
# # The default for this is $nu.default-config-dir/plugins | |
# $env.NU_PLUGIN_DIRS = [ | |
# ($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins | |
# ] | |
# To add entries to PATH (on Windows you might use Path), you can use the following pattern: | |
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path') | |
# An alternate way to add entries to $env.PATH is to use the custom command `path add` | |
# which is built into the nushell stdlib: | |
# use std "path add" | |
# $env.PATH = ($env.PATH | split row (char esep)) | |
# path add /some/path | |
# path add ($env.CARGO_HOME | path join "bin") | |
# path add ($env.HOME | path join ".local" "bin") | |
# $env.PATH = ($env.PATH | uniq) | |
# To load from a custom file you can use: | |
# source ($nu.default-config-dir | path join 'custom.nu') | |
$env.Path = ($env.Path | split row (char esep) | prepend 'C:\Program Files\Neovim\bin') | |
# def --env do_shlvl [] { | |
# $env.SHLVL = $env.SHLVL? | default 0 | into int | $in + 1 | |
# } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const const_config = path self | |
print -e $"Hello, from ($const_config)!" | |
# version output to markdown | |
def nuvermd [] { version | transpose key value | to md } | |
# version output to nushell table | |
def nuver [] { version | transpose key value } | |
# use pbcopy on macos to copy to clipboard | |
alias clip = do { ansi strip | pbcopy } | |
# ls with colors, icons and grid | |
def lsg [] { ls | sort-by type name -i | grid -c -i } | |
# figure out how many lines are in code with tokei | |
def tok [] { | |
tokei | lines | skip 1 | str join "\n" | detect columns | | |
where Language !~ "=" and Language !~ "-" and Language !~ '\(' | | |
into int Files Lines Code Comments Blanks | |
} | |
#alias for lazygit | |
alias lg = lazygit | |
# alias for git switch main | |
alias gsm = git switch main | |
# alias lvim = ^/Users/fdncred/.local/bin/lvim | |
# exec -a "$NVIM_APPNAME" nvim -u "$LUNARVIM_BASE_DIR/init.lua" "$@" | |
# # abbreviation for git status | |
# alias gst = git status | |
# # List all local branches | |
# alias gb = git branch | |
# Fix vi mistakes | |
alias vi = nvim | |
# Fix vim mistakes | |
alias vim = nvim | |
# alias gfu = git fetch upstream | |
# alias gmum = git merge upstream/main | |
# alias gpom = git push origin main | |
# alias gcom = git checkout main | |
# long listing | |
# alias ll = ls -l | |
# region: Themes | |
# attributes | |
# code meaning | |
# l blink | |
# b bold | |
# d dimmed | |
# h hidden | |
# i italic | |
# r reverse | |
# s strikethrough | |
# u underline | |
# n nothing | |
# defaults to nothing | |
# let base00 = "#181818" # Default Background | |
# let base01 = "#282828" # Lighter Background (Used for status bars, line number and folding marks) | |
# let base02 = "#383838" # Selection Background | |
# let base03 = "#585858" # Comments, Invisibles, Line Highlighting | |
# let base04 = "#b8b8b8" # Dark Foreground (Used for status bars) | |
# let base05 = "#d8d8d8" # Default Foreground, Caret, Delimiters, Operators | |
# let base06 = "#e8e8e8" # Light Foreground (Not often used) | |
# let base07 = "#f8f8f8" # Light Background (Not often used) | |
# let base08 = "#ab4642" # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted | |
# let base09 = "#dc9656" # Integers, Boolean, Constants, XML Attributes, Markup Link Url | |
# let base0a = "#f7ca88" # Classes, Markup Bold, Search Text Background | |
# let base0b = "#a1b56c" # Strings, Inherited Class, Markup Code, Diff Inserted | |
# let base0c = "#86c1b9" # Support, Regular Expressions, Escape Characters, Markup Quotes | |
# let base0d = "#7cafc2" # Functions, Methods, Attribute IDs, Headings | |
# let base0e = "#ba8baf" # Keywords, Storage, Selector, Markup Italic, Diff Changed | |
# let base0f = "#a16946" # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?> | |
# let base16_theme = { | |
# separator: $base03 | |
# leading_trailing_space_bg: $base04 | |
# header: $base0b | |
# date: $base0e | |
# filesize: $base0d | |
# row_index: $base0c | |
# bool: $base08 | |
# int: $base0b | |
# duration: $base08 | |
# range: $base08 | |
# float: $base08 | |
# string: $base04 | |
# nothing: $base08 | |
# binary: $base08 | |
# cellpath: $base08 | |
# # shape_garbage: { fg: $base07 bg: $base08 attr: b} # base16 white on red | |
# # but i like the regular white on red for parse errors | |
# shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b} | |
# shape_bool: $base0d | |
# shape_int: { fg: $base0e attr: b} | |
# shape_float: { fg: $base0e attr: b} | |
# shape_range: { fg: $base0a attr: b} | |
# shape_internalcall: { fg: $base0c attr: b} | |
# shape_external: $base0c | |
# shape_externalarg: { fg: $base0b attr: b} | |
# shape_literal: $base0d | |
# shape_operator: $base0a | |
# shape_signature: { fg: $base0b attr: b} | |
# shape_string: $base0b | |
# shape_filepath: $base0d | |
# shape_globpattern: { fg: $base0d attr: b} | |
# shape_variable: $base0e | |
# shape_flag: { fg: $base0d attr: b} | |
# shape_custom: {attr: b} | |
# shape_matching_brackets: { attr: u } | |
# } | |
let light_theme = { | |
# color for nushell primitives | |
separator: dark_gray | |
leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
# eg) {|| if $in { 'dark_cyan' } else { 'dark_gray' } } | |
bool: dark_cyan | |
int: dark_gray | |
filesize: cyan_bold | |
duration: dark_gray | |
datetime: purple | |
range: dark_gray | |
float: dark_gray | |
string: dark_gray | |
nothing: dark_gray | |
binary: dark_gray | |
cell-path: dark_gray | |
row_index: green_bold | |
record: dark_gray | |
list: dark_gray | |
block: dark_gray | |
hints: dark_gray | |
search_result: { fg: white bg: red } | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_closure: green_bold | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: cyan | |
shape_externalarg: green_bold | |
shape_external_resolved: light_purple_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: { fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_keyword: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: { attr: u } | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
} | |
let my_theme = { | |
binary: red | |
bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
cellpath: cyan | |
datetime: {|| (date now) - $in | | |
if $in < 1hr { | |
'red3b' #"\e[38;5;160m" #'#e61919' # 160 | |
} else if $in < 6hr { | |
'orange3' #"\e[38;5;172m" #'#e68019' # 172 | |
} else if $in < 1day { | |
'yellow3b' #"\e[38;5;184m" #'#e5e619' # 184 | |
} else if $in < 3day { | |
'chartreuse2b' #"\e[38;5;112m" #'#80e619' # 112 | |
} else if $in < 1wk { | |
'green3b' #"\e[38;5;40m" #'#19e619' # 40 | |
} else if $in < 6wk { | |
'darkturquoise' #"\e[38;5;44m" #'#19e5e6' # 44 | |
} else if $in < 52wk { | |
'deepskyblue3b' #"\e[38;5;32m" #'#197fe6' # 32 | |
} else { 'dark_gray' } | |
} | |
duration: blue_bold | |
filesize: {|e| if $e == 0b { 'black' } else if $e < 1mb { 'blue' } else { 'cyan' } } | |
float: red | |
header: gb | |
hints: dark_gray | |
int: green | |
leading_trailing_space_bg: {bg: dark_gray_dimmed} | |
nothing: red | |
range: purple | |
row_index: cb | |
separator: purple | |
# string: { if $in =~ '^#\w{6}$' { $in } else { 'white' } } | |
# string: {|| if $in =~ '^#[a-fA-F\d]+' { $in } else { 'default' } } | |
string: {|| | |
if $in =~ '^#[a-fA-F\d]{6}' { | |
$in | |
} else if $in =~ '^#[a-fA-F\d]{3}' { | |
$in | split chars | skip 1 | each { $in + $in } | prepend '#' | str join | |
} else { | |
'default' | |
} | |
} | |
# search_result: {bg: red fg: white} | |
search_result: {bg: deepskyblue1 fg: black} | |
# search_result: blue_reverse | |
closure: yellow_bold | |
glob:yellow_bold | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: "#33ff00" | |
shape_bool: light_cyan | |
shape_closure: "#ffb000" | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: darkorange | |
shape_externalarg: green_bold | |
shape_external_resolved: light_yellow_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: { fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_keyword: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: { attr: u } | |
# shape_matching_brackets: { fg: red bg: default attr: b } | |
shape_nothing: light_cyan | |
shape_operator: yellow_bold | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
shape_raw_string: light_purple | |
shape_glob_interpolation: orange | |
} | |
# For more information on themes, see | |
# https://www.nushell.sh/book/coloring_and_theming.html | |
let dark_theme = { | |
# color for nushell primitives | |
separator: white | |
leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
int: white | |
filesize: {|e| | |
if $e == 0b { | |
'white' | |
} else if $e < 1mb { | |
'cyan' | |
} else { 'blue' } | |
} | |
duration: white | |
datetime: {|| (date now) - $in | | |
if $in < 1hr { | |
'red3b' | |
} else if $in < 6hr { | |
'orange3' | |
} else if $in < 1day { | |
'yellow3b' | |
} else if $in < 3day { | |
'chartreuse2b' | |
} else if $in < 1wk { | |
'green3b' | |
} else if $in < 6wk { | |
'darkturquoise' | |
} else if $in < 52wk { | |
'deepskyblue3b' | |
} else { 'dark_gray' } | |
} | |
range: dark_gray | |
float: dark_gray | |
string: dark_gray | |
nothing: dark_gray | |
binary: dark_gray | |
cell-path: dark_gray | |
row_index: green_bold | |
record: dark_gray | |
list: dark_gray | |
block: dark_gray | |
hints: dark_gray | |
search_result: { fg: white bg: red } | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_closure: green_bold | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: cyan | |
shape_externalarg: green_bold | |
shape_external_resolved: light_purple_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_keyword: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: { attr: u } | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
shape_raw_string: light_purple | |
} | |
# endregion | |
# region: External Completers | |
# let external_completer = {|spans| | |
# { | |
# $spans.0: {carapace $spans.0 nushell $spans | from json } # default | |
# } | get $spans.0 | each {|it| do $it} | |
# } | |
# let external_completer = {|spans| | |
# { | |
# $spans.0: {carapace $spans.0 nushell $spans | from json } # default | |
# "empty": { "[]" | from json } # no result (valid json) | |
# "unknown": { "" | from json } # default file completion (invalid json) | |
# "vals": { '["a", "b", "c"]' | from json } # external completion (valid json) | |
# } | get $spans.0 | each {|it| do $it} | |
# } | |
# let fish_completer = {|spans| | |
# fish --command $'complete "--do-complete=($spans | str join " ")"' | |
# | str trim | split row "\n" | each { |line| $line | split column "\t" value description } | flatten | |
# } | |
# latest external completers from the cookbook 7/18/2023 | |
# let carapace_completer = {|spans| | |
# carapace $spans.0 nushell ...$spans | from json | |
# } | |
# let fish_completer = {|spans| | |
# fish --command $'complete "--do-complete=($spans | str join " ")"' | |
# | $"value(char tab)description(char newline)" + $in | |
# | from tsv --flexible --no-infer | |
# } | |
# let zoxide_completer = {|spans| | |
# $spans | skip 1 | zoxide query -l $in | lines | where {|x| $x != $env.PWD} | |
# } | |
# let carapace_completer = {|spans: list<string>| | |
# carapace $spans.0 nushell $spans | |
# | from json | |
# | if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null } | |
# } | |
# let multiple_completers = {|spans| | |
# let expanded_alias = (scope aliases | where name == $spans.0 | get -o 0 | get -o expansion) | |
# let spans = (if $expanded_alias != null { | |
# $spans | skip 1 | prepend ($expanded_alias | split words) | |
# } else { $spans }) | |
# # match spans.0 { | |
# # "z" | "zi" => $zoxide_completer | |
# # "nu" => $fish_completer | |
# # "git" => $carapace_completer | |
# # _ => $carapace_completer | |
# # } | |
# { | |
# # zoxide alias | |
# z: $zoxide_completer | |
# # zoxide alias | |
# zi: $zoxide_completer | |
# # carapace completions are incorrect for nu | |
# nu: $fish_completer | |
# # fish completes commits and branch names in a nicer way | |
# git: $fish_completer | |
# } | get -o $spans.0 | default $carapace_completer | do $in $spans # use carapace as default | |
# } | |
let external_completer = {|spans| | |
let carapace_completer = {|spans| | |
carapace $spans.0 nushell ...$spans | |
| from json | |
| if ($in | default [] | where value == $"($spans | last)ERR" | is-empty) { $in } else { null } | |
} | |
let zoxide_completer = {|spans| | |
$spans | skip 1 | zoxide query -l $in | lines | where {|x| $x != $env.PWD} | |
} | |
let expanded_alias = scope aliases | where name == $spans.0 | get -o 0 | get -o expansion | |
let spans = if $expanded_alias != null { | |
$spans | skip 1 | prepend ($expanded_alias | split row " " | take 1) | |
} else { | |
$spans | |
} | |
match $spans.0 { | |
__zoxide_z | __zoxide_zi => $zoxide_completer, | |
_ => $carapace_completer | |
} | do $in $spans | |
} | |
# endregion | |
# region: Config | |
$env.config = { | |
show_banner: true # true or false to enable or disable the banner | |
ls: { | |
use_ls_colors: true # use the LS_COLORS environment variable to colorize output | |
clickable_links: true # true or false to enable or disable clickable links in the ls listing. your terminal has to support links. | |
} | |
rm: { | |
always_trash: true # always act as if -t was given. Can be overridden with -p | |
} | |
table: { | |
mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other | |
index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column | |
show_empty: false # show 'empty list' and 'empty record' placeholders for command output | |
padding: {left: 1, right: 1} # int or record {left: 0 right: 0} | |
trim: { # A strategy of managing table view in case of limited space. | |
methodology: wrapping # truncating or wrapping | |
wrapping_try_keep_words: true | |
# A suffix which will be used with 'truncating' methodology | |
truncating_suffix: "…" # "⋯" "︙" | |
} | |
header_on_separator: true # show header text on separator/border line | |
footer_inheritance: true # render footer in parent table if child is big enough (extended table option) | |
# abbreviated_row_count: 10 # limit data rows from top and bottom after reaching a set point | |
missing_value_symbol: "❎" # symbol shown for missing values | |
} | |
error_style: "fancy" # "fancy" or "plain" for screen reader-friendly error messages | |
# Whether an error message should be printed if an error of a certain kind is triggered. | |
display_errors: { | |
exit_code: false # assume the external command prints an error message | |
# Core dump errors are always printed, and SIGPIPE never triggers an error. | |
# The setting below controls message printing for termination by all other signals. | |
termination_signal: true | |
} | |
# datetime_format: { | |
# # normal: "%Y-%m-%d %H:%M:%S" | |
# normal: "%F %r" | |
# # table: "%Y-%m-%d %H:%M:%S" | |
# # table: "%b %d %Y %I:%M:%S %p" | |
# # table: "%s" | |
# # table: "%F %r" | |
# table: "%x %r" | |
# } | |
datetime_format: { | |
# normal: '%a, %d %b %Y %H:%M:%S %z' # shows up in displays of variables or other datetime's outside of tables | |
# table: '%m/%d/%y %I:%M:%S%p' # generally shows up in tabular outputs such as ls | |
} | |
explore: { | |
config: { | |
cursor_color: 'red' | |
} | |
table: { | |
selected_cell: { bg: 'blue'} | |
show_cursor: false | |
} | |
try: { | |
reactive: true | |
} | |
} | |
history: { | |
max_size: 1_000_000 # Session has to be reloaded for this to take effect | |
sync_on_enter: true # Enable to share the history between multiple sessions, else you have to close the session to persist history to file | |
file_format: sqlite # "sqlite" or "plaintext" | |
isolation: true # true enables history isolation, false disables it. history_isolation is a unique history per session. | |
} | |
completions: { | |
case_sensitive: false # set to true to enable case-sensitive completions | |
quick: true # set this to false to prevent auto-selecting completions when only one remains | |
partial: true # set this to false to prevent partial filling of the prompt | |
algorithm: "fuzzy" # prefix, fuzzy | |
sort: "smart" # "smart" (alphabetical for prefix matching, fuzzy score for fuzzy matching) or "alphabetical" | |
external: { | |
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow | |
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options | |
completer: null | |
} | |
use_ls_colors: true # set this to true to enable file/path/directory completions using LS_COLORS | |
} | |
# filesize: { | |
# metric: true # true => KB, MB, GB (ISO standard), false => KiB, MiB, GiB (Windows standard) | |
# format: "b" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto | |
# } | |
filesize: { | |
# filesize.unit (string): One of either: | |
# - A filesize unit: "B", "kB", "KiB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "PB", "PiB", "EB", or "EiB". | |
# - An automatically scaled unit: "metric" or "binary". | |
# | |
# "metric" will use units with metric (SI) prefixes like kB, MB, or GB. | |
# "binary" will use units with binary prefixes like KiB, MiB, or GiB. | |
# Otherwise, setting this to one of the filesize units will use that particular unit when displaying all file sizes. | |
unit: 'B' | |
# filesize.precision (int or nothing): | |
# The number of digits to display after the decimal point for file sizes. | |
# When set to `null`, all digits after the decimal point will be displayed. | |
precision: 2 | |
# filesize.show_unit (bool): | |
# Whether to show or hide the file size unit. Useful if `$env.config.filesize.unit` is set to a fixed unit, | |
# and you don't want that same unit repeated over and over again in which case you can set this to `false`. | |
show_unit: false | |
} | |
cursor_shape: { # line, block, underscore, blink_line, blink_block, blink_underscore, inherit | |
emacs: line | |
vi_insert: block | |
vi_normal: underscore | |
} | |
color_config: $my_theme | |
# use_grid_icons: true | |
footer_mode: 5 #always, never, number_of_rows, auto | |
float_precision: 2 | |
buffer_editor: "nvim" # command that will be used to edit the current line buffer with ctr+e | |
use_ansi_coloring: "auto" # enabled, disabled or auto | |
bracketed_paste: true # enable bracketed paste, currently useless on windows | |
edit_mode: emacs # emacs, vi | |
shell_integration: { | |
# osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title | |
osc2: true | |
# osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory | |
osc7: true | |
# osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it. show_clickable_links is deprecated in favor of osc8 | |
osc8: true | |
# osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal | |
osc9_9: false | |
# osc133 is several escapes invented by Final Term which include the supported ones below. | |
# 133;A - Mark prompt start | |
# 133;B - Mark prompt end | |
# 133;C - Mark pre-execution | |
# 133;D;exit - Mark execution finished with exit code | |
# This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is | |
osc133: true | |
# osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features | |
# 633;A - Mark prompt start | |
# 633;B - Mark prompt end | |
# 633;C - Mark pre-execution | |
# 633;D;exit - Mark execution finished with exit code | |
# 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce | |
# 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal | |
# and also helps with the run recent menu in vscode | |
osc633: true | |
# reset_application_mode is escape \x1b[?1l and was added to help ssh work better | |
reset_application_mode: true | |
} | |
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt. | |
use_kitty_protocol: true # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this | |
highlight_resolved_externals: true | |
recursion_limit: 50 # the maximum number of times nushell allows recursion before stopping it | |
# check_for_new_version: true # true or false to enable or disable the check for new version of nushell | |
plugins: { # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration. | |
example: {a: 1, b: 2} | |
} | |
# Configuration for plugin garbage collection | |
plugin_gc: { | |
default: { | |
enabled: true # true to enable stopping of inactive plugins | |
stop_after: 1sec # how long to wait after a plugin is inactive to stop it | |
} | |
plugins: { | |
# alternate configuration for specific plugins, by name, for example: | |
# | |
gstat: { | |
enabled: true | |
stop_after: 1sec # stop as soon as possible | |
} | |
emoji: { | |
enabled: true | |
stop_after: 1sec # stop as soon as possible | |
} | |
} | |
} | |
hooks: { | |
pre_prompt: [{|| | |
#if (shells | length) > 1 { tabline-hook } | |
null | |
#print -n "pre_p " (date now | format date "%Y-%m-%d %H:%M:%S.%f") (char nl) | |
#if "LAST_CMD" in $env { | |
# print $"(ansi title)(pwd | str replace "/Users/fdncred" "~") > ($env.LAST_CMD)(ansi st)" | |
#} else { | |
# print $"(ansi title)(pwd | str replace "/Users/fdncred" "~")(ansi st)" | |
#} | |
}] | |
pre_execution: [{|| | |
null | |
# $env.LAST_CMD = (commandline) | |
#print -n "pre_e " (date now | format date "%Y-%m-%d %H:%M:%S.%f") (char nl) | |
}] | |
env_change: { | |
PWD: [ | |
{ |before, after| | |
#print $"before: [($before)], after: [($after)]" | |
# print ($env.LS_COLORS) | |
print (lsg) | |
# null | |
}, | |
{ | |
condition: {|_, after| not ($after | path join 'toolkit.nu' | path exists)} | |
code: "hide toolkit" | |
# code: "overlay hide --keep-env [ PWD ] toolkit" | |
}, | |
{ | |
condition: {|_, after| $after | path join 'toolkit.nu' | path exists} | |
code: " | |
let use_coloring = (config use-colors) | |
let banner1 = $'(ansi default_underline)(ansi default_bold)toolkit(ansi reset) module (ansi green_italic)detected(ansi reset)...' | |
let banner2 = $'(ansi yellow_italic)activating(ansi reset) (ansi default_underline)(ansi default_bold)toolkit(ansi reset) module with `(ansi default_dimmed)(ansi default_italic)use toolkit.nu(ansi reset)`' | |
if $use_coloring { | |
print $banner1 | |
print $banner2 | |
} else { | |
print ($banner1 | ansi strip) | |
print ($banner2 | ansi strip) | |
} | |
use toolkit.nu | |
# overlay use --prefix toolkit.nu | |
" | |
}, | |
{|before, _| | |
if $before == null { | |
let file = ($nu.home-path | path join ".local" "share" "nushell" "startup-times.nuon") | |
if not ($file | path exists) { | |
mkdir ($file | path dirname) | |
touch $file | |
} | |
let ver = (version) | |
open $file | append { | |
date: (date now) | |
time: $nu.startup-time | |
build: ($ver.build_rust_channel) | |
allocator: ($ver.allocator) | |
version: ($ver.version) | |
commit: ($ver.commit_hash) | |
build_time: ($ver.build_time) | |
bytes_loaded: (view files | get size | math sum) | |
} | collect { save --force $file } | |
} | |
} | |
] | |
} | |
# display_output: { | |
# if (term size).columns > 100 { table -e } else { table } | |
# # table | |
# } | |
display_output: { | |
metadata access {|meta| match $meta.content_type? { | |
"application/x-nuscript" | "application/x-nuon" | "text/x-nushell" => { if (config use-colors) {nu-highlight} else {$in}}, | |
"application/json" => { ^bat --language=json --color=always --style=plain --paging=never }, | |
"application/xml" => { ^bat -Ppf --language=xml }, | |
"application/yaml" => { ^bat -Ppf --language=yaml }, | |
"text/csv" => { ^bat -Ppf --language=csv }, | |
"text/tab-separated-values" => { ^bat -Ppf --language=tsv }, | |
"text/x-toml" => { ^bat -Ppf --language=toml }, | |
"text/markdown" => { ^bat -Ppf --language=markdown }, | |
_ => {}, | |
} | |
} | table | |
} | |
# display_output: {|| table } | |
# display_output: "table -e" | |
# display_output: "if (term size).columns >= 10 { table -e } else { table }" | |
# display_output: { | |
# $env.__ = $in; | |
# print $env.__; | |
# } | |
# display_output: { table } # run before the output of a command is drawn, example: `{ if (term size).columns >= 100 { table -e } else { table } }` | |
command_not_found: {|| | |
null # replace with source code to return an error message when a command is not found | |
} | |
# command_not_found: {|cmd_name| ( | |
# try { | |
# # let pkgs = (pkgfile --binaries --verbose $cmd_name) | |
# # ( | |
# # $"(ansi $env.config.color_config.shape_external)($cmd_name)(ansi reset) " + | |
# # $"may be found in the following packages:\n($pkgs)" | |
# # ) | |
# print $"Didn't find command: ($cmd_name). Try again." | |
# } catch { | |
# null | |
# }) | |
# } | |
} | |
# old timey crt colors | |
# #ffb000 <- 600nm P3 <--history_menu | |
# #ffcc00 <- 593nm | |
# #33ff00 <- 524nm <-- completion_menu | |
# #33ff33 <- P1 | |
# #00ff33 <- 506nm | |
# #66ff66 <- P24 | |
# #00ff66 <- 502nm | |
# #282828 <- background | |
# log_level: trace | |
# region: Menus | |
menus: [ | |
# Configuration for default nushell menus | |
# Note the lack of souce parameter | |
{ | |
name: completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
} | |
style: { | |
text: { fg: "#33ff00" } | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
selected_text: {attr: r} | |
# selected_text: { attr: r } | |
description_text: yellow | |
match_text: {attr: u} | |
selected_match_text: {attr: ur} | |
} | |
# style: { | |
# text: green | |
# selected_text: {attr: r} | |
# description_text: yellow | |
# } | |
} | |
{ | |
name: ide_completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: ide | |
min_completion_width: 0, | |
max_completion_width: 50, | |
max_completion_height: 10, # will be limited by the available lines in the terminal | |
padding: 0, | |
border: true, | |
cursor_offset: 0, | |
description_mode: "prefer_right" | |
min_description_width: 0 | |
max_description_width: 50 | |
max_description_height: 10 | |
description_offset: 1 | |
# If true, the cursor pos will be corrected, so the suggestions match up with the typed text | |
# | |
# C:\> str | |
# str join | |
# str trim | |
# str split | |
correct_cursor_pos: false | |
} | |
style: { | |
# text: { fg: "#33ff00" } | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
# description_text: yellow | |
text: green | |
selected_text: {attr: r} | |
description_text: yellow | |
match_text: {fg: darkorange} | |
selected_match_text: {fg: darkorange attr: r} | |
} | |
} | |
{ | |
name: history_menu | |
only_buffer_difference: true | |
marker: $"(char -u '1f50d') " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#ffb000" | |
selected_text: { fg: "#ffb000" attr: r } | |
description_text: yellow | |
} | |
} | |
{ | |
name: help_menu | |
only_buffer_difference: true | |
marker: "? " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: "#7F00FF" | |
selected_text: { fg: "#ffff00" bg: "#7F00FF" attr: b } | |
description_text: "#ffff00" | |
} | |
} | |
# Example of extra menus created using a nushell source | |
# Use the source field to create a list of records that populates | |
# the menu | |
{ | |
name: fzf_history_menu_fzf_ui | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
open $nu.history-path | get history.command_line | |
| to text | fzf +s --tac | str trim | |
| where $it =~ $buffer | |
| each { |v| {value: ($v | str trim) } } | |
} | |
} | |
{ | |
name: fzf_menu_nu_ui | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#66ff66" | |
selected_text: { fg: "#66ff66" attr: r } | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
open $nu.history-path | get history.command_line | |
| to text | |
| fzf -f $buffer | |
| lines | |
| each { |v| {value: ($v | str trim) } } | |
} | |
} | |
{ | |
name: commands_menu | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each { |x| {value: $x.name description: $x.description} } | |
} | |
} | |
{ | |
name: vars_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope variables | |
| where name == $buffer | |
| each { |it| {value: $it.value }} | |
} | |
} | |
{ | |
name: commands_with_description | |
only_buffer_difference: true | |
marker: "# " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each { |it| {value: $it.name description: $it.description} } | |
} | |
} | |
{ | |
name: abbr_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope aliases | |
| where name == $buffer | |
| each { |it| {value: $it.expansion }} | |
} | |
} | |
{ | |
name: grid_history_menu | |
only_buffer_difference: true | |
marker: "<?> " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
history | |
| where command =~ $buffer | |
| where exit_status < 1 | |
| get command | |
| each { |it| {value: $it description: (try {help $"($it | str trim)"| lines | get 0} catch { "" }) } } | |
} | |
} | |
] | |
# endregion | |
# region: Keybindings | |
# mac keyboard | |
# home = fn + left | |
# end = fn + right | |
# pageup = fn + up | |
# pagedown = fn + down | |
# backspace = delete | |
# delete = fn + delete | |
keybindings: [ | |
{ | |
name: insert_newline | |
modifier: alt | |
keycode: char_i | |
mode: [emacs vi_normal vi_insert] | |
event: { edit: insertnewline } | |
} | |
{ | |
name: insert_newline | |
modifier: alt | |
keycode: enter | |
mode: [emacs vi_normal vi_insert] | |
event: { edit: insertnewline } | |
} | |
# { | |
# name: insert_newline | |
# modifier: shift | |
# keycode: (char cr) | |
# mode: [emacs vi_normal vi_insert] | |
# event: { edit: insertnewline } | |
# } | |
{ | |
name: trigger-completion-menu | |
modifier: none | |
keycode: tab | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: completion_menu } | |
{ send: menunext } | |
{ edit: complete } | |
] | |
} | |
} | |
{ | |
name: completion_previous | |
modifier: shift | |
keycode: backtab | |
mode: [emacs vi_normal vi_insert] | |
event: { send: menuprevious } | |
} | |
{ | |
name: clear | |
modifier: none | |
keycode: esc | |
mode: [emacs vi_normal vi_insert] | |
event: { edit: clear } | |
} | |
{ | |
name: complete_hint_chunk | |
modifier: alt | |
keycode: right | |
mode: [emacs vi_normal vi_insert] | |
event: { until: [ | |
{ send: historyhintwordcomplete } | |
{ edit: movewordright } | |
] | |
} | |
} | |
{ | |
name: un_complete_hint_chunk | |
modifier: alt | |
keycode: left | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: backspaceword } | |
] | |
} | |
{ | |
name: trigger-history-menu | |
modifier: control | |
keycode: char_x | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: history_menu } | |
{ send: menupagenext } | |
] | |
} | |
} | |
{ | |
name: trigger-history-previous | |
modifier: control | |
keycode: char_z | |
mode: [emacs vi_normal vi_insert] | |
event: { until: [ | |
{ send: menupageprevious } | |
{ edit: undo } | |
] | |
} | |
} | |
{ | |
name: trigger-help-menu | |
modifier: control | |
keycode: char_q | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: help_menu } | |
{ send: menunext } | |
] | |
} | |
} | |
# { | |
# name: prev_shell | |
# modifier: control | |
# keycode: char_p | |
# mode: [emacs vi_normal vi_insert] | |
# event: [ | |
# { edit: clear } | |
# { edit: insertchar value: p } | |
# { send: enter } | |
# ] | |
# } | |
# { | |
# name: next_shell | |
# modifier: control | |
# keycode: char_n | |
# mode: [emacs vi_normal vi_insert] | |
# event: [ | |
# { edit: clear } | |
# { edit: insertchar value: n } | |
# { send: enter } | |
# ] | |
# } | |
# { | |
# name: change_dir_with_fzf | |
# modifier: control | |
# keycode: char_f | |
# mode: [emacs vi_normal vi_insert] | |
# event: { | |
# send: executehostcommand, | |
# cmd: "cd (ls | where type == dir | each { |it| $it.name} | str join (char nl) | fzf | decode utf-8 | str trim)" | |
# } | |
# } | |
{ | |
name: complete_in_cd | |
modifier: none | |
keycode: f2 | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: clear } | |
{ edit: insertString value: "./" } | |
{ send: Menu name: completion_menu } | |
] | |
} | |
{ | |
name: reload_config | |
modifier: none | |
keycode: f5 | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
send: executehostcommand, | |
cmd: $"source '($nu.env-path)';source '($nu.config-path)'" | |
} | |
} | |
{ | |
name: clear_backbuffer | |
modifier: control | |
keycode: char_l | |
mode: [emacs vi_normal vi_insert] | |
event: { send: ClearScrollback } | |
} | |
# { | |
# name: edit_buffer | |
# modifier: control | |
# keycode: char_i | |
# mode: [emacs vi_normal vi_insert] | |
# event: { send: OpenEditor } | |
# } | |
{ | |
name: insert_last_token | |
modifier: alt | |
keycode: char_. | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: InsertString, value: " !$" } | |
{ send: Enter } | |
] | |
} | |
# Keybindings used to trigger the user defined menus | |
{ #notworking | |
name: fzf_history_menu_fzf_ui | |
modifier: alt | |
keycode: char_e | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: fzf_history_menu_fzf_ui } | |
} | |
{ | |
name: fzf_menu_nu_ui | |
modifier: alt | |
keycode: char_w | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: fzf_menu_nu_ui } | |
} | |
{ | |
name: commands_menu | |
modifier: control | |
keycode: char_t | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: commands_menu } | |
} | |
{ | |
name: vars_menu | |
modifier: control | |
keycode: char_y | |
mode: [emacs, vi_normal, vi_insert] | |
event:[ | |
{ send: menu name: vars_menu } | |
{ edit: insertchar, value: ' '} | |
] | |
} | |
{ | |
name: commands_with_description | |
modifier: control | |
keycode: char_u | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: commands_with_description } | |
} | |
# { | |
# name: alias_menu | |
# modifier: control | |
# keycode: char_a | |
# mode: [emacs, vi_normal, vi_insert] | |
# event: { send: menu name: alias_menu } | |
# } | |
# { | |
# name: abbr | |
# modifier: control | |
# keycode: space | |
# mode: [emacs, vi_normal, vi_insert] | |
# event: [ | |
# { send: menu name: abbr_menu } | |
# { edit: insertchar, value: ' '} | |
# ] | |
# } | |
# { | |
# name: fuzzy_history_skim | |
# modifier: control | |
# keycode: char_r | |
# mode: [emacs vi_normal vi_insert] | |
# event: { | |
# send: executehostcommand | |
# cmd: "commandline edit --replace (history | each { |it| $it.command } | uniq | reverse | str join (char nl) | sk --layout=reverse --height=40% -q (commandline) | decode utf-8 | str trim)" | |
# } | |
# } | |
{ | |
name: insert_last_arg_from_prev_cmd | |
modifier: alt | |
keycode: char_. | |
mode: [emacs, vi_normal, vi_insert] | |
event: { | |
send: executeHostCommand | |
cmd: "commandline edit --insert (history | last | get command | parse --regex '(?P<arg>[^ ]+)$' | get arg | first)" | |
} | |
} | |
{ | |
name: fuzzy_history_fzf | |
modifier: control | |
keycode: char_r | |
mode: [emacs , vi_normal, vi_insert] | |
event: { | |
send: executehostcommand | |
cmd: "commandline edit --replace ( | |
history | |
| where exit_status == 0 | |
| get command | |
| reverse | |
| uniq | |
| str join (char -i 0) | |
| fzf --scheme=history --read0 --tiebreak=chunk --layout=reverse --preview='echo {..}' --preview-window='bottom:3:wrap' --bind alt-up:preview-up,alt-down:preview-down --height=70% -q (commandline) --preview='echo -n {} | nu --stdin -c \'nu-highlight\'' | |
| decode utf-8 | |
| str trim | |
)" | |
} | |
} | |
# { | |
# name: fuzzy_history | |
# modifier: control | |
# keycode: char_r | |
# mode: [emacs, vi_normal, vi_insert] | |
# event: [ | |
# { | |
# send: ExecuteHostCommand | |
# cmd: "commandline edit --replace ( | |
# history | |
# | each { |it| $it.command } | |
# | uniq | |
# | reverse | |
# | str join (char -i 0) | |
# | fzf --read0 --layout=reverse --height=40% -q (commandline) | |
# | decode utf-8 | |
# | str trim | |
# )" | |
# } | |
# ] | |
# } | |
{ | |
name: insert_file | |
modifier: alt | |
keycode: char_y | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
send: executehostcommand | |
cmd: "commandline edit --insert (fzf --tiebreak=chunk --layout=reverse --multi --preview='echo {..}' --preview-window='bottom:3:wrap' --height=70% | decode utf-8 | str trim)" | |
} | |
} | |
{ | |
name: insert_sudo | |
modifier: alt | |
keycode: char_s | |
mode: [emacs, vi_insert, vi_normal] | |
event: [ | |
{ edit: MoveToStart } | |
{ send: ExecuteHostCommand, | |
cmd: 'if (commandline | split row -r '\s+' | first) != `sudo` { commandline edit --insert `sudo `;commandline set-cursor --end; }' | |
} | |
] | |
} | |
{ | |
name: fzf_files | |
modifier: alt | |
keycode: char_t | |
mode: [emacs, vi_normal, vi_insert] | |
event: [ | |
{ | |
send: executehostcommand | |
cmd: " | |
let fzf_ctrl_t_command = $'($env.FZF_CTRL_T_COMMAND) | fzf ($env.FZF_CTRL_T_OPTS)' | |
let result = nu -c $fzf_ctrl_t_command | |
commandline edit --append $result | |
commandline set-cursor --end | |
" | |
} | |
] | |
} | |
{ | |
name: fzf_dirs | |
modifier: alt | |
keycode: char_c | |
mode: [emacs, vi_normal, vi_insert] | |
event: [ | |
{ | |
send: executehostcommand | |
cmd: " | |
let fzf_alt_c_command = $'($env.FZF_ALT_C_COMMAND) | fzf ($env.FZF_ALT_C_OPTS)' | |
let result = nu -c $fzf_alt_c_command | |
cd $result | |
" | |
} | |
] | |
} | |
{ | |
name: copy_selection | |
modifier: control_shift | |
keycode: char_c | |
mode: emacs | |
event: { edit: copyselection } | |
} | |
{ | |
name: cut_selection | |
modifier: control_shift | |
keycode: char_x | |
mode: emacs | |
event: { edit: cutselection } | |
} | |
{ | |
name: select_all | |
modifier: control_shift | |
keycode: char_a | |
mode: emacs | |
event: { edit: selectall } | |
} | |
{ | |
name: paste | |
modifier: control_shift | |
keycode: char_v | |
mode: emacs | |
event: { edit: pastecutbufferbefore } | |
} | |
{ | |
name: ide_completion_menu | |
modifier: control | |
keycode: char_p | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: ide_completion_menu } | |
{ send: menuprevious } | |
{ edit: complete } | |
{ send: up } | |
] | |
} | |
} | |
{ | |
name: ide_completion_menu | |
modifier: control | |
keycode: char_n | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: ide_completion_menu } | |
{ send: menunext } | |
{ edit: complete } | |
{ send: down } | |
] | |
} | |
} | |
] | |
# endregion | |
} | |
# endregion | |
# Directories to search for scripts when calling source or use | |
# | |
# By default, <nushell-config-dir>/scripts is added | |
const NU_LIB_DIRS = [ | |
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts | |
'/Users/fdncred/src/nu_scripts' | |
($nu.config-path | path dirname) | |
($nu.data-dir | path join 'completions') # default home for nushell completions | |
] | |
# Directories to search for plugin binaries when calling register | |
# | |
# By default, <nushell-config-dir>/plugins is added | |
# const NU_PLUGIN_DIRS = [ | |
# ($nu.config-path | path dirname | path join 'plugins') | |
# '/Users/fdncred/.cargo/bin' | |
# ] | |
# Custom Commands | |
source defs.nu | |
# region: prompts | |
# prompt | |
def get_prompt_stuff [] { | |
let use_coloring = (config use-colors) | |
let prompt_indicator = (if ($env.LAST_EXIT_CODE == 0) {$"(ansi green_bold)\n❯ (ansi reset)"} else {$"(ansi red_bold)\n❯ (ansi reset)"}) | |
let transient_prompt_indicator = (if ($env.LAST_EXIT_CODE == 0) {$"(ansi light_yellow_bold)❯ (ansi reset)"} else {$"(ansi light_red_bold)❯ (ansi reset)"}) | |
let prompt_multiline_indicator = $"(ansi -e { fg: '#CB4B16'})(char -u '276f')(ansi -e { fg: '#CACA02'})(char -u '276f')(ansi -e { fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" | |
{ | |
prompt_indicator: (if $use_coloring { $prompt_indicator } else { " \n❯ " }) | |
transient_prompt_indicator: (if $use_coloring { $transient_prompt_indicator } else { $transient_prompt_indicator | ansi strip }) | |
prompt_multiline_indicator: (if $use_coloring { $prompt_multiline_indicator } else { $prompt_multiline_indicator | ansi strip }) | |
} | |
} | |
use "modules/prompt/oh-my.nu" git_prompt | |
$env.PROMPT_COMMAND = {|| (git_prompt).left_prompt } | |
$env.PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt } | |
# $env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) {$"(ansi green_bold)\n❯ (ansi reset)"} else {$"(ansi red_bold)\n❯ (ansi reset)"}} | |
$env.PROMPT_INDICATOR = {|| (get_prompt_stuff).prompt_indicator } | |
$env.TRANSIENT_PROMPT_COMMAND = { "" } | |
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = { || (git_prompt).right_prompt } | |
# $env.TRANSIENT_PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) {$"(ansi light_yellow_bold)❯ (ansi reset)"} else {$"(ansi light_red_bold)❯ (ansi reset)"}} | |
$env.TRANSIENT_PROMPT_INDICATOR = {|| (get_prompt_stuff).transient_prompt_indicator } | |
# $env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e { fg: '#CB4B16'})(char -u '276f')(ansi -e { fg: '#CACA02'})(char -u '276f')(ansi -e { fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
$env.PROMPT_MULTILINE_INDICATOR = {|| (get_prompt_stuff).prompt_multiline_indicator } | |
# use "modules/prompt/full-line.nu" | |
# $env.PROMPT_COMMAND = {|| full-line } | |
# $env.PROMPT_COMMAND_RIGHT = "" | |
# $env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) {$"(ansi green_bold)\n❯ (ansi reset)"} else {$"(ansi red_bold)\n❯ (ansi reset)"}} | |
# setup for starship | |
# $env.STARSHIP_SHELL = "nu" | |
# $env.PROMPT_INDICATOR = "" | |
# $env.PROMPT_INDICATOR_VI_INSERT = "" | |
# $env.PROMPT_INDICATOR_VI_NORMAL = "" | |
# $env.PROMPT_MULTILINE_INDICATOR = "" | |
# $env.PROMPT_COMMAND = "" | |
# $env.PROMPT_COMMAND_RIGHT = "" | |
# $env.TRANSIENT_PROMPT_COMMAND = "" | |
# $env.TRANSIENT_PROMPT_COMMAND_RIGHT = "" | |
# $env.TRANSIENT_PROMPT_INDICATOR = "" | |
# use ~/.cache/starship/init.nu | |
# source "modules/prompt/oh-my-v2.nu" | |
# $env.PROMPT_COMMAND = { (get_prompt 8bit).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 8bit).right_prompt } | |
# experiment with panache-git | |
# use "modules/prompt/panache-git.nu" main | |
# $env.PROMPT_COMMAND = { panache-git } | |
# endregions | |
# cargo completions | |
# use "custom-completions/cargo/cargo-completions.nu" * | |
# use "custom-completions/winget/winget-completions.nu" * | |
use "custom-completions/rustup/rustup-completions.nu" * | |
# git/gh completions and aliases | |
use aliases/git/git-aliases.nu * | |
use custom-completions/git/git-completions.nu * | |
use custom-completions/gh/gh-completions.nu * | |
# jc wrapper | |
use modules/jc | |
# stdlib candidates | |
use std-rfc/tables aggregate | |
# broot completions | |
# use '/Users/fdncred/.config/broot/launcher/nushell/br' * | |
# temperature converter | |
# now loaded from vendor autoload dirs | |
# use "sourced/temp.nu" * | |
# get_weather | |
# now loaded from vendor autoload dirs | |
# use "modules/weather/get-weather.nu" get_weather | |
# zoxide | |
source ~/.zoxide.nu | |
# if LS_COLORS exists, hide it | |
if 'LS_COLORS' in ($env | columns) { | |
hide-env LS_COLORS | |
} | |
# make sure my PATH is unique | |
$env.PATH = ($env.PATH | par-each {|r| $r | split row (char esep)} | flatten | uniq) | |
# source /Users/fdncred/.config/broot/launcher/nushell/br | |
# alias ls = eza -lhA --color=always --group-directories-first --color-scale-mode=gradient --grid --icons --git --git-repos --color-scale all --no-user --no-permissions | |
# source ~/src/nushell/test.nu | |
#~/.config/nushell/config.nu | |
# source ~/.cache/carapace/init.nu | |
# print (fastfetch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print -e $"Hello, from ($env.CURRENT_FILE?)!" | |
# print $"$env.CURRENT_FILE = ($env.CURRENT_FILE?)" | |
# print $"$env.FILE_PWD = ($env.FILE_PWD?)" | |
# print $"$env.PROCES_PATH = ($env.PROCESS_PATH?)" | |
# check for env var exists | |
# "FOO" | env exists? | |
def "env exists" [] { | |
# each {|s| $s in (env).name } | |
$in in $env | |
} | |
# Xterm Xterm | |
# Num Name HEX RGB HSL | |
# 0 Black (SYSTEM) #000000 rgb(0,0,0) hsl(0,0%,0%) | |
# 1 Maroon (SYSTEM) #800000 rgb(128,0,0) hsl(0,100%,25%) | |
# 2 Green (SYSTEM) #008000 rgb(0,128,0) hsl(120,100%,25%) | |
# 3 Olive (SYSTEM) #808000 rgb(128,128,0) hsl(60,100%,25%) | |
# 4 Navy (SYSTEM) #000080 rgb(0,0,128) hsl(240,100%,25%) | |
# 5 Purple (SYSTEM) #800080 rgb(128,0,128) hsl(300,100%,25%) | |
# 6 Teal (SYSTEM) #008080 rgb(0,128,128) hsl(180,100%,25%) | |
# 7 Silver (SYSTEM) #c0c0c0 rgb(192,192,192) hsl(0,0%,75%) | |
# 8 Grey (SYSTEM) #808080 rgb(128,128,128) hsl(0,0%,50%) | |
# 9 Red (SYSTEM) #ff0000 rgb(255,0,0) hsl(0,100%,50%) | |
# 10 Lime (SYSTEM) #00ff00 rgb(0,255,0) hsl(120,100%,50%) | |
# 11 Yellow (SYSTEM) #ffff00 rgb(255,255,0) hsl(60,100%,50%) | |
# 12 Blue (SYSTEM) #0000ff rgb(0,0,255) hsl(240,100%,50%) | |
# 13 Fuchsia (SYSTEM) #ff00ff rgb(255,0,255) hsl(300,100%,50%) | |
# 14 Aqua (SYSTEM) #00ffff rgb(0,255,255) hsl(180,100%,50%) | |
# 15 White (SYSTEM) #ffffff rgb(255,255,255) hsl(0,0%,100%) | |
let bn = (ansi {fg: '#ffffff' bg: '#000000'}) | |
let bb = (ansi {fg: '#ffffff' bg: '#555555'}) | |
let rn = (ansi {fg: '#ffffff' bg: '#AA0000'}) | |
let rb = (ansi {fg: '#ffffff' bg: '#FF5555'}) | |
let gn = (ansi {fg: '#000000' bg: '#00AA00'}) | |
let gb = (ansi {fg: '#000000' bg: '#55FF55'}) | |
let yn = (ansi {fg: '#000000' bg: '#AAAA00'}) | |
let yb = (ansi {fg: '#000000' bg: '#FFFF55'}) | |
let un = (ansi {fg: '#ffffff' bg: '#0000AA'}) | |
let ub = (ansi {fg: '#ffffff' bg: '#5555FF'}) | |
let mn = (ansi {fg: '#ffffff' bg: '#AA00AA'}) | |
let mb = (ansi {fg: '#ffffff' bg: '#FF55FF'}) | |
let cn = (ansi {fg: '#000000' bg: '#00AAAA'}) | |
let cb = (ansi {fg: '#000000' bg: '#55FFFF'}) | |
let wn = (ansi {fg: '#000000' bg: '#AAAAAA'}) | |
let wb = (ansi {fg: '#000000' bg: '#FFFFFF'}) | |
let s = 'XXXXXX' | |
let r = (ansi reset) | |
def standard-colors-rgb [] { | |
[ | |
[color normal bold]; | |
[Black $"($bn)($s)($r)" $"($bb)($s)($r)"] | |
[Red $"($rn)($s)($r)" $"($rb)($s)($r)"] | |
[Green $"($gn)($s)($r)" $"($gb)($s)($r)"] | |
[Yellow $"($yn)($s)($r)" $"($yb)($s)($r)"] | |
[Blue $"($un)($s)($r)" $"($ub)($s)($r)"] | |
[Magenta $"($mn)($s)($r)" $"($mb)($s)($r)"] | |
[Cyan $"($cn)($s)($r)" $"($cb)($s)($r)"] | |
[White $"($wn)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
def standard-colors-name [] { | |
[ | |
[color normal light]; | |
[Black $"(ansi black)ansi black 30" $"(ansi dark_gray)ansi dark_gray 90"] | |
[Red $"(ansi red)ansi red 31" $"(ansi light_red)ansi light_red 91"] | |
[Green $"(ansi green)ansi green 32" $"(ansi light_green)ansi light_green 92"] | |
[Yellow $"(ansi yellow)ansi yellow 33" $"(ansi light_yellow)ansi light_yellow 93"] | |
[Blue $"(ansi blue)ansi blue 34" $"(ansi light_blue)ansi light_blue 94"] | |
[Magenta $"(ansi magenta)ansi magenta 35" $"(ansi light_magenta)ansi light_magenta 95"] | |
[Purple $"(ansi purple)ansi purple 35" $"(ansi light_purple)ansi light_purple 95"] | |
[Cyan $"(ansi cyan)ansi cyan 36" $"(ansi light_cyan)ansi light_cyan 96"] | |
[White $"(ansi white)ansi white 37" $"(ansi light_gray)ansi light_gray 97"] | |
] | |
} | |
# https://www.ditig.com/256-colors-cheat-sheet | |
# 38;5;<num> for these palleted index numbers | |
# Xterm 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #800000 #008000 #808000 #000080 #800080 #008080 #C0C0C0 | |
# Xterm 8 9 10 11 12 13 14 15 | |
# Bold #808080 #FF0000 #00FF00 #FFFF00 #0000FF #FF00FF #00FFFF #FFFFFF | |
def wide-colors [] { | |
# Code 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #AA0000 #00AA00 #AAAA00 #0000AA #AA00AA #00AAAA #AAAAAA | |
# Bold #555555 #FF5555 #55FF55 #FFFF55 #5555FF #FF55FF #55FFFF #FFFFFF | |
# [code '0' '1' '2' '3' '4' '5' '6' '7']; | |
[ | |
[name black red green yellow blue magenta cyan white]; | |
[normal $"($bn)($s)($r)" $"($rn)($s)($r)" $"($gn)($s)($r)" $"($yn)($s)($r)" $"($un)($s)($r)" $"($mn)($s)($r)" $"($cn)($s)($r)" $"($wn)($s)($r)"] | |
[bold $"($bb)($s)($r)" $"($rb)($s)($r)" $"($gb)($s)($r)" $"($yb)($s)($r)" $"($ub)($s)($r)" $"($mb)($s)($r)" $"($cb)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# Clear the screen with ansi escapes | |
def cls [] { | |
ansi cls | |
} | |
# Full term reset, cls, clear buffer, attributes off, | |
def clsterm [] { | |
print -n $"(ansi esc)c(ansi clsb)(ansi cls)(ansi reset)(ansi home)" | |
} | |
# Easily sum up a column | |
@search-terms "math" | |
@example "Sum memory of all Firefox instances" { | |
ps | where name =~ Firefox | get mem | sum | |
} | |
def sum [] { | |
reduce {|acc, item| $acc + $item } | |
} | |
# written by Kubouch for virtualenv | |
def is-string [ | |
x # value to check to see if it's a string | |
] { | |
($x | describe) == "string" | |
} | |
def has-env [name: string] { | |
$name in $env | |
} | |
# go to a folder like $nu.config-path | goto | |
def --env goto [] { | |
let input = $in | |
cd ( | |
if ($input | path type) == file { | |
($input | path dirname) | |
} else { | |
$input | |
} | |
) | |
} | |
# Run the cargo nextest tests for nushell | |
def cargo_tests [] { | |
cargo nextest run --all | |
} | |
# Run the nushell cargo clippy lint | |
def cargo_clippy [] { | |
cargo clippy --workspace --all -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect | |
} | |
# Get column # | |
def column [n] { transpose | select $n | transpose | select column1 | headers } | |
# How many stars does nushell have | |
def stars [] { | |
http get https://api.github.com/repos/nushell/nushell | get stargazers_count | |
} | |
# Hide all the prompt variables | |
def --env hide_prompt [] { | |
hide-env PROMPT_COMMAND | |
hide-env PROMPT_COMMAND_RIGHT | |
hide-env PROMPT_INDICATOR | |
} | |
# Easy way to get a short working directory | |
def pwd-short [] { | |
$env.PWD | str replace $nu.home-path '~' | |
} | |
# Check how many downloads nushell has had | |
def nudown [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | get assets | flatten | select name download_count created_at | update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S' } | |
} | |
# Ye old start command | |
def start2 [path] { | |
if $nu.os-info.name == "windows" { | |
^start $path | |
} else if $nu.os-info.name == "macos" { | |
^open $path | |
} else { | |
xdg-open $path | |
} | |
} | |
# reject a column from a deeply nested json | |
def reject_deep [p: cell-path, f: cell-path] { | |
update $p {|x| $x | get $p | reject $f } | |
} | |
# convert int input to hex | |
def "into hex" [] { | |
format number | get lowerhex | |
} | |
# convert input to octal | |
def "into octal" [] { | |
format number | get octal | |
} | |
def "nu-complete help categories" [] { | |
help commands | get category | uniq | |
} | |
def hc [cat?: string@"nu-complete help categories"] { | |
help commands | select name category usage | move usage --after name | where category == $cat | |
} | |
# Move up $nb directories | |
def --env up [nb: int = 1] { | |
let path = (1..($nb) | each {|_| ".." } | reduce {|it, acc| $acc + "/" + $it }) | |
cd $path | |
} | |
# # make and cd to a folder | |
# def --env mkcd [name: path] { | |
# cd (mkdir $name -v | into string) | |
# } | |
# show a slightly different banner | |
def show_banner [] { | |
let ellie = [ | |
" __ ," | |
" .--()°'.'" | |
"'|, . ,' " | |
' !_-(_\ ' | |
] | |
let s_mem = (sys mem) | |
let s_ho = (sys host) | |
print $"(ansi reset)(ansi green)($ellie.0)" | |
print $"(ansi green)($ellie.1) (ansi yellow) (ansi yellow_bold)Nushell (ansi reset)(ansi yellow)v(version | get version)(ansi reset)" | |
print $"(ansi green)($ellie.2) (ansi light_blue) (ansi light_blue_bold)RAM (ansi reset)(ansi light_blue)($s_mem.used) / ($s_mem.total)(ansi reset)" | |
print $"(ansi green)($ellie.3) (ansi light_purple)ﮫ (ansi light_purple_bold)Uptime (ansi reset)(ansi light_purple)($s_ho.uptime)(ansi reset)" | |
print $"(ansi green)Startup Time: (ansi light_cyan)($nu.startup-time)(ansi reset)" | |
} | |
# Returns a filtered table that has distinct values in the specified column | |
@example "Filter table to have distinct values in the specified column" { | |
[ | |
{name: 'A' email: '[email protected]'} | |
{name: 'a' email: '[email protected]'} | |
{name: 'b' email: '[email protected]'} | |
] | uniq-by email | |
} --result [[name email]; [A "[email protected]"] [b "[email protected]"]] | |
def uniq-by2 [ | |
column: string # The column to scan for duplicate values | |
] { | |
reduce {|item, acc| | |
if ( | |
$acc | any {|storedItem| | |
($storedItem | get $column) == ($item | get $column) | |
} | |
) { | |
$acc | |
} else { | |
$acc | append $item | |
} | |
} | |
} | |
# Get values from simple key-value object | |
def get-values [] { | |
let subject = $in | |
let keys = ($subject | columns) | |
$keys | each {|it| $subject | get $it } | |
} | |
# Get an abbreviated path | |
def spwd [] { | |
let home = (if ($nu.os-info.name == windows) { $env.USERPROFILE } else { $env.HOME }) | |
let sep = (if ($nu.os-info.name == windows) { "\\" } else { "/" }) | |
let spwd_paths = ( | |
$"!/($env.PWD)" | str replace $"!/($home)" ~ | split row $sep | |
) | |
# Darren's hack to make all slashes point to the right | |
let sep = '/' | |
# end hack | |
let spwd_len = (($spwd_paths | length) - 1) | |
for i in ($spwd_paths | enumerate) { | |
let spwd_src = ($i.item | split chars) | |
if ($i.index == $spwd_len) { | |
print -n $i.item | |
} else if ($spwd_src.0 == ".") { | |
print -n $".($spwd_src.1)($sep)" | |
} else { | |
print -n $"($spwd_src.0)($sep)" | |
} | |
} | |
} | |
def get-monday [] { | |
( | |
seq date -r --days 7 | into datetime | where {|e| | |
($e | format date %u) == "1" | |
} | |
).0 | format date "%Y-%m-%d" | |
} | |
# Delete all branches that are not in the excepts list | |
@example "Delete all branches except main" { | |
del-branches [main] | |
} | |
def del-branches [ | |
excepts: list # don't delete branch in the list | |
--dry-run (-d) # do a dry-run | |
] { | |
let branches = (git branch | lines | str trim) | |
let remote_branches = (git branch -r | lines | str replace -r '^.+?/' '' | uniq) | |
if $dry_run { | |
print "Starting Dry-Run" | |
} else { | |
print "Deleting for real" | |
} | |
$branches | each {|it| | |
if ($it not-in $excepts) and ($it not-in $remote_branches) and (not ($it | str starts-with "*")) { | |
# git branch -D $it | |
if $dry_run { | |
print $"git branch -D ($it)" | |
} else { | |
print $"Deleting ($it) for real" | |
git branch -D $it | |
} | |
} | |
} | |
} | |
# Avoid duplicating values in a list | |
@example "Avoid putting duplicates in $env.PATH" { | |
$env.PATH = ( | |
$env.PATH | split row (char esep) | |
| prepend-if-not-in ($env.HOME | path join ".local" "bin") | |
| prepend-if-not-in ($env.EMACS_HOME | path join "bin") | |
| prepend-if-not-in ($env.CARGO_HOME | path join "bin") | |
| prepend-if-not-in ($env.XDG_DATA_HOME | path join "clang-15" "bin") | |
| prepend-if-not-in ($env.XDG_DATA_HOME | path join "gem" "ruby" $env.GEM_VERSION "bin") | |
) | |
} | |
def prepend-if-not-in [ | |
value: string | |
] { | |
let list = $in | |
$list | if ($value in $list) { $in } else { $in | prepend $value } | |
} | |
def inspect2 [ | |
callback?: closure | |
] { | |
# Examples: | |
# 123 | inspect | echo ($in * 2) | |
# 123 | inspect { |num| print $"num is ($num)" } | echo ($in * 2) | |
let input = $in | |
if $callback == null { | |
print $input | |
} else { | |
do $callback $input | |
} | |
$input | |
} | |
# Show some history stats similar to how atuin does it | |
def history-stats [ | |
--summary (-s): int = 10 # How many top commands to show | |
--last-cmds (-l): int # If provided, only use the last x commands from the history | |
] { | |
let top_commands = ( | |
history | |
| if ($last_cmds != null) { last $last_cmds } else { $in } | |
| get command | |
| split column ' ' command | |
| uniq -c | |
| flatten | |
| sort-by --reverse count | |
| first $summary | |
) | |
let total_cmds = (history | length) | |
let unique_cmds = (history | get command | uniq | length) | |
print $"Top (ansi green)($summary)(ansi reset) most used commands:" | |
let max = ($top_commands | get count | math max) | |
$top_commands | each {|cmd| | |
let in_ten = 10 * ($cmd.count / $max) | |
print -n "[" | |
print -n (ansi red) | |
for i in 0..<$in_ten { | |
if $i == 2 { | |
print -n (ansi yellow) | |
} else if $i == 5 { | |
print -n (ansi green) | |
} | |
if $i != 10 { | |
print -n "▮" | |
} | |
} | |
for x in $in_ten..<10 { | |
if $x < 9 { | |
print -n " " | |
} | |
} | |
print $"(ansi reset)] (ansi xterm_grey)($cmd.count | fill -a r -c ' ' -w 4)(ansi reset) (ansi default_bold)($cmd.command)(ansi reset)" | |
} | |
print $"(ansi green)Total commands:(ansi reset) ($total_cmds)" | |
print $"(ansi green)Unique commands:(ansi reset) ($unique_cmds)" | |
} | |
# use std repeat | |
use std/util repeat | |
const BAR_CHAR = "▮" | |
# Show some history stats similar to how atuin does it but structured | |
def history-stats-structured [ | |
--summary (-s): int = 10 | |
]: nothing -> record<histogram: table<bar: string, count: int, perc: float, cmd: string>, total: int, uniq: int> { | |
let history = history | |
let commands = $history | |
| get command | |
| split column ' ' command | |
| uniq --count | |
| flatten | |
| sort-by --reverse count | |
| if $summary != null { first $summary } else { $in } | |
let total = $history | length | |
let max = $commands | get count | math max | |
let histogram = $commands | each {|cmd| | |
let in_ten = 10 * ($cmd.count / $max) + 1 | into int | |
let w = if $in_ten <= 2 { | |
[$in_ten 0 0] | |
} else if $in_ten <= 5 { | |
[2 ($in_ten - 2) 0] | |
} else { | |
[2 3 ($in_ten - 5)] | |
} | |
{ | |
bar: ( | |
$"(ansi red)($BAR_CHAR | repeat $w.0 | str join)" | |
+ $"(ansi yellow)($BAR_CHAR | repeat $w.1 | str join)" | |
+ $"(ansi green)($BAR_CHAR | repeat $w.2 | str join)" | |
+ (ansi reset) | |
) | |
count: $cmd.count | |
perc: ($cmd.count / $total * 100) | |
cmd: $cmd.command | |
} | |
} | |
{ | |
histogram: $histogram | |
total: $total | |
uniq: ($history | get command | uniq | length) | |
} | |
} | |
def "history search" [ | |
str: string = '' # search string | |
--cwd (-c) # Filter search result by directory | |
--exit (-e): int = 0 # Filter search result by exit code | |
--before (-b): datetime = 2100-01-01 # Only include results added before this date | |
--after (-a): datetime = 1970-01-01 # Only include results after this date | |
--limit (-l): int = 25 # How many entries to return at most | |
] { | |
if $cwd == false { | |
history --long | |
| where start_timestamp != "" | |
| update start_timestamp {|r| $r.start_timestamp | into datetime } | |
| where command =~ $str and exit_status == $exit and start_timestamp > $after and start_timestamp < $before | |
| first $limit | |
| select item_id command start_timestamp cwd duration exit_status | |
} else { | |
history --long | |
| where start_timestamp != "" | |
| update start_timestamp {|r| $r.start_timestamp | into datetime } | |
| where command =~ $str and cwd == $env.PWD and exit_status == $exit and start_timestamp > $after and start_timestamp < $before | |
| first $limit | |
| select item_id command start_timestamp cwd duration exit_status | |
} | |
} | |
# Show the items in list1 that are also in list2 | |
def sorted_list_intersect [xs1: list, xs2: list] { | |
let len1 = ($xs1 | length) | |
let len2 = ($xs2 | length) | |
mut i = 0 | |
mut j = 0 | |
while ($i < $len1 and $j < $len2) { | |
if ($xs1 | get $i) < ($xs2 | get $j) { | |
$i = $i + 1 | |
} else if ($xs2 | get $j) < ($xs1 | get $i) { | |
$j = $j + 1 | |
} else { | |
echo ($xs2 | get $j) | |
$i = $i + 1 | |
$j = $j + 1 | |
} | |
} | |
} | |
# Show information about the crates that are installed via cargo | |
def "cargo list" [] { | |
cargo install --list | |
| lines | |
| str replace -r '^(\w)' "\n${1}" | |
| str join | |
| lines | skip 1 | |
| parse --regex '(?<pkg>.*) v(?<version>\d+\.\d+\.\d+)(?<path>.*):(?<bins>.*)' | |
| str trim | |
| update bins {|it| $it.bins | str replace -r '\s+' ' ' | split row ' ' } | |
| update path {|it| $it.path | str replace '(' '' | str replace ')' '' } | |
| update bins {|r| $r.bins | str join (char nl) } | |
} | |
# create a nanosecond duration from a number piped in | |
def "from ns" [] { | |
[$in "ns"] | str join | into duration | |
} | |
# Check how many downloads nushell has had | |
def get_github_downloads [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | get assets | flatten | select name download_count created_at | update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S' } | |
} | |
# Get brew downloads for the past 30 days | |
def get_brew_downloads [] { | |
let brew_dl = (http get https://formulae.brew.sh/api/formula/nushell.json) | |
let macos_dl = ($brew_dl | get analytics.install.30d.nushell) | |
# let linux_dl = ($brew_dl | get analytics-linux.install.30d.nushell) | |
# [[os downloads]; [macos $macos_dl] [linux $linux_dl]] | |
[[os downloads]; [macos $macos_dl]] | |
} | |
# Get cargo downloads for crate | |
def "get_cargo_downloads" [crate: string, version: string] { | |
# alternatively scrape this | |
# http get https://crates.io/api/v1/crates/nu | |
# http get https://crates.io/api/v1/crates/nu/0.76.0 | get version | |
# cargo info $crate | |
# | lines | |
# | parse "{key}: {value}" | |
# | str trim | |
# | transpose -r | |
# | into record | |
# | merge ({ | |
# versions: ( | |
# cargo info $crate -VV | |
# | lines -s | |
# | skip 1 | |
# | parse --regex '(?<version>\d+\.\d+\.\d+)\s+(?<released>.* ago)\s+(?<downloads>\d+)' | |
# | into int downloads | |
# ) | |
# }) | |
http get $'https://crates.io/api/v1/crates/($crate)/($version)' | get version | get downloads | |
} | |
# Get all the downloads for nushell | |
def get_all_nu_downloads [version = "0.76.0"] { | |
let github_dl = (get_github_downloads | where name =~ $version | get download_count | math sum) | |
let brew_dl = (get_brew_downloads | get downloads | math sum) | |
let cargo_dl = (get_cargo_downloads nu $version) | |
[[source downloads]; [github $github_dl] [brew $brew_dl] [cargo $cargo_dl] [sum ($github_dl + $brew_dl + $cargo_dl)]] | |
} | |
def helps [] { | |
help commands | where command_type == built-in | get name | str join "\n" | fzf --preview-window 'up,60%,border-bottom,+{2}+3/3,~1' --preview $"nu -l -c 'help {1} {2} {3} {4} {5}'" --exact | |
# fzf --preview-window 'up,60%,border-bottom,+{2}+3/3,~1' --preview $"nu --config '($nu.config-path)' --env-config '($nu.env-path)' -c 'help {1} {2} {3} {4} {5}'" --exact | |
# fzf --preview $"nu --config ($nu.config-path) --env-config ($nu.env-path) -c 'help {}'" | |
} | |
# get the environment details | |
def "env details" [] { | |
let e = ($env | reject config | transpose key value) | |
$e | each {|r| | |
let is_envc = ($r.key == ENV_CONVERSIONS) | |
let is_closure = ($r.value | describe | str contains 'closure') | |
let is_list = ($r.value | describe | str contains 'list') | |
if $is_envc { | |
echo [ | |
[key value]; | |
[ | |
($r.key) | |
( | |
$r.value | transpose key value | each {|ec| | |
let to_string = ($ec.value | get to_string | view source $in | nu-highlight) | |
let from_string = ($ec.value | get from_string | view source $in | nu-highlight) | |
echo ({'ENV_CONVERSIONS': {($ec.key): {'to_string': ($to_string) 'from_string': ($from_string)}}}) | |
} | |
) | |
] | |
] | |
} else if $is_closure { | |
let closure_value = (view source ($env | get $r.key) | nu-highlight) | |
echo [[key value]; [($r.key) ($closure_value)]] | |
} else if $is_list { | |
let list_value = ($env | get $r.key | split row (char esep)) | |
echo [[key value]; [($r.key) ($list_value)]] | |
} else { | |
echo [[key value]; [($r.key) ($r.value)]] | |
} | |
} | |
} | |
def env [] { env details | flatten | table -e } | |
# Get the type of a value | |
def get-type [value] { | |
$value | describe | |
} | |
# Check if a value is of a certain type | |
def is-type [type] { | |
($in | describe) == $type | |
} | |
# brew upgrade everything | |
def brewup [] { | |
print $"(ansi {fg: white bg: blue attr: n}) ============== MAINTAIN BREW =============== (ansi reset)" | |
print $"(ansi purple)Updating brew...(ansi reset)" | |
brew update | |
print $"(ansi purple)Upgrading brew...(ansi reset)" | |
brew upgrade --greedy | |
print $"(ansi purple)Cleaning up brew (char lp)keep only last(char rp)...(ansi reset)" | |
brew cleanup -s | |
print $"(ansi purple)Calling the DOCTOR! What is missing?...(ansi reset)" | |
try { brew doctor } catch { |err| print $"(ansi red)'brew doctor' Error: ($err.msg)(ansi reset)" } | |
brew missing | |
print $"(ansi purple)Updating brew casks and cleaning up...(ansi reset)" | |
brew cu --all --yes --cleanup | |
print $"(ansi {fg: white bg: blue attr: n}) ============ MAINTAIN COMPLETE ============= (ansi reset)" | |
} | |
# Only list the nushell environment variables | |
def env-nu [] { | |
$env | transpose key value | each {|r| | |
if ($r.value | describe) != string { | |
$r | |
} | |
} | transpose -ird | |
} | |
# Show a summarized table of nushell startup times | |
def startup-stats [] { | |
open ~/.local/share/nushell/startup-times.nuon | where build == release | group-by commit --to-table | rename commit data | update commit {|c| | |
$c.commit | str substring 0..7 | |
} | upsert perf {|r| | |
if ($r.data | length) > 3 { | |
# This throws out outliers by removing the top 3 times | |
$r.data.time | sort | slice 0..(-3) | math avg | |
} else { | |
$r.data.time | math avg | |
} | |
} | upsert start_date {|s| | |
$s.data.date | sort | math min | format date '%Y-%m-%d' | |
} | upsert end_date {|e| | |
$e.data.date | sort | math max | format date '%Y-%m-%d' | |
} | upsert num_startups {|n| | |
$n.data | length | |
} | upsert bytes_loaded {|b| | |
$b.data.bytes_loaded | math avg | |
} | upsert perf_per_byte {|s| | |
# This throws out outliers by removing the top 3 times | |
# sum_of_time / sum_of_bytes_loaded | |
if ($s.data.time | length) > 3 { | |
($s.data.time | sort | slice 0..(-3) | math sum) / ($s.data.bytes_loaded | math sum) | |
} else { | |
($s.data.time | math sum) / ($s.data.bytes_loaded | math sum) | |
} | |
} | sort-by start_date | |
} | |
# Example of how to use generate to grab paginated data from github | |
def gen_gh [] { | |
let PAGE_SIZE = 10 | |
generate {|page = 1| | |
let resp = http get --headers [Authorization <gh pat>] ( | |
{ | |
scheme: https | |
host: "api.github.com" | |
path: "/repos/nushell/nushell/issues" | |
params: { | |
page: $page | |
per_page: $PAGE_SIZE | |
} | |
} | url join | |
) | |
if ($resp | length) < $PAGE_SIZE { | |
{out: $resp} | |
} else { | |
{out: $resp next: ($page + 1)} | |
} | |
} | |
} | |
# create a list from a range | |
@example "Convert a range to a list" { | |
0..5 | into list | |
} --result [0 1 2 3 4 5] | |
def "into list" []: any -> list<any> { | |
each {} | |
} | |
# Use tokei to gather info about repo | |
def get-tokei-info [] { | |
tokei --output json | from json | transpose lang stats | select lang stats.reports stats.code stats.comments stats.blanks | update "stats.reports" {|r| | |
$r."stats.reports" | length | |
} | upsert lines {|r| | |
$r."stats.code" + $r."stats.comments" + $r."stats.blanks" | |
} | move lines --after "stats.reports" | rename lang files lines code comments blanks | update lang {|r| | |
if $r.lang == Total { | |
"(Total)" | |
} else { | |
$in | |
} | |
} | sort-by lines | |
} | |
# Find files using ripgrep (from CDNcred on discord) | |
def rgfind [file] { rg --files - . --no-messages | rg -S $file } | |
# Get IP information (from CDNcred on discord) | |
def whatismyip [] { curl -s ipinfo.io/what-is-my-ip | from json } | |
# Get help on commands using fzf | |
def "get help" [] { | |
do { | |
# doesn't work well with nushell due to escaping issues. if you use nushell | |
# as your login shell, you can set SHELL env var to an alternative shell | |
# temporarily like zsh below and it will still work. | |
$env.SHELL = '/bin/zsh' | |
help commands | where command_type == built-in | |
| each {|c| | |
let search_terms = if ($c.search_terms == "") { "" } else { $"\(($c.search_terms))" } | |
let category = if ($c.category == "") { "" } else { $"\(Category: ($c.category))" } | |
$"(ansi default)($c.name?):(ansi light_blue) ($c.usage?) (ansi cyan)($search_terms) ($category)(ansi reset)" | |
} | |
| to text | |
| fzf --ansi --tiebreak=begin,end,chunk --exact --preview="echo -n {} | nu --stdin -c 'help ($in | split row : | get 0)'" --bind 'ctrl-/:change-preview-window(right,70%|right)' | |
} | |
} | |
# interactively select columns from a table | |
# def select-i [] { | |
# let tgt = $in | |
# let cols = ($tgt | columns) | |
# let $choices = ($cols | input list -m "Pick columns to get: ") | |
# history | |
# | last | |
# | get command | |
# | str replace 'select-i' $'select ($choices | str join " ")' | |
# | commandline edit $in | |
# } | |
# clean out history of failed commands | |
# def purge_history [] { open $nu.history-path | query db "select * from history where exit_status != 0" } | |
# Wrapper for the pspg pager | |
def --wrapped pspg [...args] { | |
let input = $in | |
$env.config.ls.clickable_links = false | |
$env.config.table.mode = 'rounded' | |
$env.config.table.header_on_separator = false | |
$env.config.footer_mode = 'never' | |
$input | ^pspg ...$args | |
} | |
# check if something is an alias | |
def is_alias [cmd: string] { | |
$cmd in (scope aliases | get name) | |
} | |
def plugins [] { | |
plugin list | update commands { str join ', ' } | reject shell | update filename { path parse | get stem } | table --index 1 | |
} | |
# create a grouping from a list | |
@example "Group a list of numbers by even and odd" { | |
[1 1 2 2 3 4] | group list { $in mod 2 == 0 } | to nuon | |
} --result [[1 1] [2 2] [3] [4]] | |
@example "Group a range with less than 3" { | |
0..8 | group list { $in < 3 } | to nuon | |
} --result [[0 1 2] [3 4 5 6 7 8]] | |
def "group list" [cond: closure] { | |
zip ($in | each $cond) | |
| prepend [null] | |
| window 2 | |
| each {|i| | |
let prev = ($i.0 | default $i.1) | |
let next = $i.1 | |
if $prev.1 != $next.1 { | |
[null $next.0] | |
} else { | |
$next.0 | |
} | |
} | |
| flatten | |
| split list null | |
} | |
# show the nushell version in markdown with nested table for plugins | |
def ver2md [] { | |
let plugin_modified = plugin list | insert last_modified {|plug| | |
ls $plug.filename | get 0?.modified? | |
} | select name last_modified | update last_modified { format date %FT%T } | |
let plugin_version = version | get installed_plugins | split row ', ' | parse '{name} {version}' | |
let plugin_details_html = $plugin_version | join $plugin_modified name | to html --dark | |
let table_begin = $plugin_details_html | str index-of '<table>' | |
let table_end = $plugin_details_html | str index-of '</table>' | $in + 7 | |
let version_details_md = version | update build_time { | |
$in | into datetime | format date %FT%T | |
} | reject installed_plugins | transpose key value | to md | |
print $version_details_md | |
print $"|installed_plugins|($plugin_details_html | str substring $table_begin..$table_end)|" | |
} | |
# get the version information formatting the plugins differently | |
def ver [ --markdown (-m)] { | |
let plugin_modified = plugin list | insert last_modified {|plug| | |
ls $plug.filename | get 0?.modified? | |
} | select name last_modified | |
let ver = version | upsert build_time { $in | into datetime } | upsert installed_plugins {|v| | |
$v.installed_plugins | split row ', ' | parse '{name} {version}' | join $plugin_modified name | |
} | |
if $markdown { | |
ver2md | |
} else { | |
$ver | table -e | |
} | |
} | |
# a way to iterate multiple ranges together at once | |
@example "Iterate through multiple ranges doing math" { | |
chain 40..47 100..107 49..51 | each {|x| $x / 10 } | |
} | |
@example "Iterate through multiple ranges" { | |
chain 40..47 100..107 49..51 | |
} --result [40 41 42 43 44 45 46 47 100 101 102 103 104 105 106 107 49 50 51] | |
def chain [...iters] { | |
$iters | reduce {|it, acc| $acc | append $it } | |
} | |
# head replacement | |
@example "Look at the first 200 bytes of a file" { | |
heady -f ~/desktop/wiztree.csv -b 200 | |
} | |
def heady [ --file (-f): path, --bytes (-b): int = 100, --binary]: [nothing -> string nothing -> binary] { | |
if $binary { | |
open -r $file | first $bytes | |
} else { | |
open -r $file | first $bytes | decode utf8 | |
} | |
} | |
# Creates a tree of processes from the ps command. | |
# | |
# Any table can be piped in, so long as every row has a `pid` and `ppid` column. | |
# If there is no input, then the standard `ps` is invoked. | |
def "ps tree" [ | |
--root-pids (-p): list<int> # root of process tree | |
]: table -> table { | |
mut procs = $in | |
# get a snapshot to use to build the whole tree as it was at the time of this call | |
if $procs == null { | |
$procs = ps | |
} | |
let procs = $procs | |
let roots = if $root_pids == null { | |
$procs | where ppid? == null or ppid not-in $procs.pid | |
} else { | |
$procs | where pid in $root_pids | |
} | |
$roots | |
| insert children {|proc| | |
$procs | |
| where ppid == $proc.pid | |
| each {|child| | |
$procs | |
| ps tree -p [$child.pid] | |
| get 0 | |
} | |
} | |
} | |
def "seq char2" [start: string, end: string] { | |
let error_start_too_long = ($start | str length) > 1 | |
let error_end_too_long = ($end | str length) > 1 | |
let is_start_int = (try { $start | into int } | describe) == 'int' | |
let is_end_int = (try { $end | into int } | describe) == 'int' | |
if ($is_start_int and $is_end_int and $error_start_too_long) { | |
error make { | |
msg: $'Did you mean `seq ($start) ($end)`?' | |
label: { | |
text: 'should be 1 character long' | |
span: (metadata $start).span | |
} | |
} | |
} | |
if ($is_start_int and $is_end_int and $error_end_too_long) { | |
error make { | |
msg: $'Did you mean `seq ($start) ($end)`?' | |
label: { | |
text: 'should be 1 character long' | |
span: (metadata $end).span | |
} | |
} | |
} | |
if ($start | str length) != 1 { | |
error make { | |
msg: 'seq char only accepts individual ASCII characters as parameters' | |
label: { | |
text: 'should be 1 character long' | |
span: (metadata $start).span | |
} | |
} | |
} | |
if ($end | str length) != 1 { | |
error make { | |
msg: 'seq char only accepts individual ASCII characters as parameters' | |
label: { | |
text: 'should be 1 character long' | |
span: (metadata $end).span | |
} | |
} | |
} | |
let start_code = $start | into binary | into int | |
let end_code = $end | into binary | into int | |
if ($start_code not-in 32..126) { | |
error make { | |
msg: 'Start value must be a printable ASCII character' | |
label: { | |
text: 'should be a printable ASCII character' | |
span: (metadata $start).span | |
} | |
} | |
} | |
if ($end_code not-in 32..126) { | |
error make { | |
msg: 'End value must be a printable ASCII character' | |
label: { | |
text: 'should be printable ASCII character' | |
span: (metadata $end).span | |
} | |
} | |
} | |
($start_code)..($end_code) | each { char -i $in } | |
} | |
# part of psub | |
def run-cmd-array [...cmd_arr: list] { | |
run-external ($cmd_arr | first) ...($cmd_arr | skip 1) | |
} | |
# proces substitution | |
@example "Process substitution" { | |
psub [cat] { echo "hi there\n" } { echo "bye now\n" } | |
} --result "hi there\nbye now\n" | |
@example "Process substitution with alacritty" { | |
psub [alacritty --config-file] { "" } | |
} | |
@example "Diff two text files from online" { | |
( | |
psub [diff --side-by-side] | |
{ curl -L https://www.gnu.org/licenses/gpl-2.0.txt } | |
{ curl -L https://www.gnu.org/licenses/gpl-3.0.txt } | |
) | |
} | |
@example "Use just one process substitution or many" { | |
psub [paste -d +] { echo 1 2 3 } { echo a b c } { sudo dmesg | lines | first 10 | last 3 } | |
} | |
def psub [cmd: list, ...sub_cmds: closure] { | |
let tmpdir = (mktemp -d) | |
let index = ($sub_cmds | enumerate | select index) | |
let out_paths = ( | |
$index.index | each {|i| [$tmpdir $i] | path join | wrap out_path } | |
) | |
let sub_cmds_table = ( | |
$sub_cmds | wrap cmd | merge $index | merge $out_paths | |
) | |
for it in $sub_cmds_table { | |
do $it.cmd | save $it.out_path | |
} | |
run-cmd-array ...$cmd ...$sub_cmds_table.out_path | |
^rm -fr $tmpdir | ignore | |
} | |
# alias the built in ls command so we don't shadow it | |
alias ls-builtin = ls | |
# List the filenames, sizes, and modification times of items in a directory. | |
@category filesystem | |
@search-terms dir | |
@example "List the files in the current directory" { ls } | |
@example "List visible files in a subdirectory" { ls subdir } | |
@example "List visible files with full path in the parent directory" { ls -f .. } | |
@example "List Rust files" { ls *.rs } | |
@example "List files and directories whose name do not contain 'bar'" { ls | where name !~ bar } | |
@example "List the full path of all dirs in your home directory" { ls -a ~ | where type == dir } | |
@example "List only the names (not paths) of all dirs in your home directory which have not been modified in 7 days" { ls -as ~ | where type == dir and modified < ((date now) - 7day) } | |
@example "Recursively list all files and subdirectories under the current directory using a glob pattern" { ls -a **/* } | |
@example "Recursively list *.rs and *.toml files using the glob command" { ls ...(glob **/*.{rs,toml}) } | |
@example "List given paths and show directories themselves" { ['/path/to/directory' '/path/to/file'] | each {|| ls -D $in } | flatten } | |
def ls [ | |
--all (-a), # Show hidden files | |
--long (-l), # Get all available columns for each entry (slower; columns are platform-dependent) | |
--short-names (-s), # Only print the file names, and not the path | |
--full-paths (-f), # display paths as absolute paths | |
--du (-d), # Display the apparent directory size ("disk usage") in place of the directory metadata size | |
--directory (-D), # List the specified directory itself instead of its contents | |
--mime-type (-m), # Show mime-type in type column instead of 'file' (based on filenames only; files' contents are not examined) | |
--threads (-t), # Use multiple threads to list contents. Output will be non-deterministic. | |
...pattern: glob, # The glob pattern to use. | |
]: [nothing -> table] { | |
let pattern = if ($pattern | is-empty) { ['.'] } else { $pattern } | |
( | |
ls-builtin | |
--all=$all | |
--long=$long | |
--short-names=$short_names | |
--full-paths=$full_paths | |
--du=$du | |
--directory=$directory | |
--mime-type=$mime_type | |
--threads=$threads | |
...$pattern | |
) | sort-by type name -i | |
} | |
def cargo-clean-all [] { | |
let dirs = ls | where type == dir | get name | |
$dirs | each {|dir| | |
print $"(ansi yellow_bold)checking ($dir)(ansi reset)" | |
cd $dir | |
if ('./cargo.toml' | path expand | path exists) { | |
print $"(ansi purple_bold)cleaning ($dir)(ansi reset)" | |
print $"(ansi cyan_bold)working in (pwd)(ansi reset)" | |
try { cargo clean } catch {|err| print $"(ansi red_bold)($err.msg)(ansi reset)" } | |
} | |
} | |
} | |
# Just run @search to search with rg and fzf | |
def "@search" [] { | |
let RELOAD = 'reload:rg --column --color=always --smart-case {q}' | |
try { | |
fzf --disabled --ansi --bind $"start:($RELOAD)" --bind $"change:($RELOAD)" --bind 'enter:become:nvim {1} +{2}' --delimiter : --preview 'bat --style=full --color=always --highlight-line {2} {1}' --preview-window '~4,+{2}+4/3,<80(up)' | |
} catch {|e| | |
# ctrlc | |
ignore | |
} | |
} | |
# conditionally update a table, from weirdan | |
def "update if" [ | |
field: cell-path, | |
condition: closure, | |
value: closure | |
]: [ | |
list -> list record -> record table -> table | |
] { | |
update $field {|r| if (do $condition $r) { do $value $r } else { } } | |
} | |
# from devyn | |
def "str replace-env" [ --overlay: record] { | |
# Replace PATH first, from overlay if it exists | |
let in_string = $in | str replace --all --regex '\$PATH|\$\{PATH\}' ( | |
$overlay.PATH? | default $env.PATH | str join (char esep) | |
) | |
# Parse env variables and look them up in $env | |
( | |
$in_string | parse --regex '(?<match>\$(?<var0>\w+)|\$\{(?<var1>\w+)\})' | uniq | reduce --fold $in_string {|var, s| | |
# Env key has been parsed into either the var0 group or the var1 group | |
let env_key = [$var.var0 $var.var1] | where { not ($in | is-empty) } | first | |
# Get from either the overlay or $env | |
let replacement = $overlay | get -o $env_key | default ($env | get $env_key) | |
$s | str replace --all $var.match $replacement | |
} | |
) | |
} | |
# Parse environment variables from a string containing bash-style env var statements | |
def "from env" [] { | |
lines | | |
parse -r `^(?:export )?(?<name>\w+) *= *(?<quote>['"]?)(?<value>.*)\k<quote>$` | | |
# Handle environment variables that update previously set ones, and env substitutions | |
reduce --fold {} { |var, out| | |
$out | upsert $var.name ($var.value | str replace-env --overlay=$out) | |
} | |
} | |
def today [] { | |
date now | format date "%Y-%m-%d" | |
} | |
# See what files are in your autoload directories | |
def ls-autoload-dirs [] { | |
print $"(ansi light_green)checking user autoload dirs...(ansi reset)" | |
$nu.user-autoload-dirs | each {|dir| | |
print $"(ansi yellow_bold)checking ($dir | path expand)(ansi reset)" | |
if ($dir | path expand | path exists) { | |
print (ls -a ($dir | path expand)) | |
} else { | |
print $"(ansi red_bold)($dir | path expand) does not exist(ansi reset)" | |
} | |
} | |
print $"(ansi light_green)checking system autoload dirs...(ansi reset)" | |
$nu.vendor-autoload-dirs | each {|dir| | |
print $"(ansi yellow_bold)checking ($dir | path expand)(ansi reset)" | |
if ($dir | path expand | path exists) { | |
print (ls -a ($dir | path expand)) | |
} else { | |
print $"(ansi red_bold)($dir | path expand) does not exist(ansi reset)" | |
} | |
} | |
} | |
######################################### | |
## Ansi Escape Custom Commands below | |
######################################### | |
# get the terminal name using ansi escapes | |
def get-terminal-name []: [nothing -> string] { | |
term query $'(ansi csi)>0q' -t (ansi st) | |
| bytes at 4..<-2 | |
| decode | |
} | |
# Copy input to system clipboard using ansi escapes | |
def "clip copy" []: [string -> nothing] { | |
print -n $'(ansi osc)52;c;($in | encode base64)(ansi st)' | |
} | |
# Paste contenst of system clipboard using ansi escapes | |
def "clip paste" []: [nothing -> string] { | |
try { | |
term query $'(ansi osc)52;c;?(ansi st)' -t (ansi st) | |
} catch { | |
error make -u { | |
msg: "Terminal did not responds to OSC 52 paste request." | |
help: $"Check if your terminal supports OSC 52." | |
} | |
} | |
| bytes at 7..<-2 | |
| decode | |
| decode base64 | |
| decode | |
} | |
# helper function to parse 16bit color | |
def parse_16bit_color [color: string] { | |
let rgb = $color | split row / | |
let red = ($"0x($rgb | get 0)" | into int | bits and 0x00ff) | |
let green = ($"0x($rgb | get 1)" | into int | bits and 0x00ff) | |
let blue = ($"0x($rgb | get 2)" | into int | bits and 0x00ff) | |
let red_hx = ($red | format number).lowerhex | str substring 2.. | fill --alignment right --character '0' --width 2 | |
let green_hx = ($green | format number).lowerhex | str substring 2.. | fill --alignment right --character '0' --width 2 | |
let blue_hx = ($blue | format number).lowerhex | str substring 2.. | fill --alignment right --character '0' --width 2 | |
{ | |
red: $red_hx | |
green: $green_hx | |
blue: $blue_hx | |
hex: $"#($red_hx)($green_hx)($blue_hx)" | |
rgb: $"RGB(char lp)($red), ($green), ($blue)(char rp)" | |
} | |
} | |
# get all colors in the terminal with ansi escapes | |
def get-terminal-colors [] { | |
let responses = ( | |
(10..=11 | each { $"($in);?" }) # fg & bg | |
| append (0..=15 | each { $"4;($in);?" }) # colors | |
| each { term query $"(ansi osc)($in)(ansi st)" --prefix $'(ansi osc)($in | str substring 0..-2)' --terminator (ansi st) | decode } | |
| parse '{rgb}:{color}' | |
| each { parse_16bit_color $in.color } | |
) | |
{ | |
fg: ($responses.0) | |
bg: ($responses.1) | |
colors: ($responses | skip 2) | |
} | |
} | |
# get the terminal size with ansi escape codes | |
def get-terminal-size [] { | |
let sz = term query (ansi size) --terminator 'R' | |
let size = bytes at 2..<-1 | decode | split row ';' | |
# output in record syntax | |
{ | |
rows: ($size | get 0) | |
columns: ($size | get 1) | |
} | |
} | |
# get background color with x11 ansi escapes | |
# have to hit ctrl+g after the statement to get the value in $x | |
# let x = input $"(ansi -o '11;?')(char bel)" --bytes-until (char bel) | |
# | |
# when input = rgb:4_numbers/4_numbers/4_numbers like rgb:1919/1313/2323 | |
# this means 16-bit rgb components. 16^4 means four hex digits. FFFF is 65535 | |
# 48-bit color. it could be 1 number 4-bits, 2 8-bits, 3 12-bits, 4 16-bits | |
# #3a7 is the same as #3000a0007000. | |
# refernce https://www.x.org/releases/X11R7.7/doc/man/man7/X.7.xhtml#heading11 | |
# mine was rgb:1919/1313/2323 | |
# (('1919' | into int -r 16) / 256 | math round | format number).lowerhex | |
# (('1313' | into int -r 16) / 256 | math round | format number).lowerhex | |
# (('2323' | into int -r 16) / 256 | math round | format number).lowerhex | |
# or | |
# 0x1919 / 0x100 | math round | |
# 0x1313 / 0x100 | math round | |
# 0x2323 / 0x100 | math round | |
# | |
# Get the background color through ansi escape sequences | |
def get-bg [] { | |
let bg = term query $"(ansi -o '11;?')(ansi st)" --terminator (ansi st) --prefix (ansi osc) | |
# let start_index = ($bg | str index-of ':' | into int) + 1 | |
# let end_index = $bg | str length | |
let rgb_string = $bg | bytes at 7.. | decode | |
parse_16bit_color $rgb_string | |
# # split the rgb string into the individual values | |
# let rgb = $rgb_string | split row '/' | |
# let r = $rgb | get 0 | |
# let g = $rgb | get 1 | |
# let b = $rgb | get 2 | |
# # convert the rgb values to hex | |
# let red = (($r | into int -r 16) / 256 | math round | format number).lowerhex | |
# let green = (($g | into int -r 16) / 256 | math round | format number).lowerhex | |
# let blue = (($b | into int -r 16) / 256 | math round | format number).lowerhex | |
# # output in record syntax | |
# { | |
# red: $red | |
# green: $green | |
# blue: $blue | |
# hex: $"(ansi default)#($red | str substring 2.. | fill -a r -c 0 -w 2)($green | str substring 2.. | fill -a r -c 0 -w 2)($blue | str substring 2.. | fill -a r -c 0 -w 2)(ansi reset)" | |
# rgb: $"RGB(char lp)(($red | into int | format number).display), (($green | into int | format number).display), (($blue | into int | format number).display)(char rp)" | |
# } | |
} | |
module color { | |
def parse_channel_scaled []: string -> float { | |
let input = $in | |
let scale = 2 ** (($input | str length) * 4) | |
($input | into int --radix 16) / $scale | |
} | |
def gamma [v: float]: nothing -> float { | |
if $v <= 0 { | |
0 | |
} else if $v <= 0.04045 { | |
$v / 12.92 | |
} else { | |
(($v + 0.055) / 1.055) ** 2.4 | |
} | |
} | |
def luminance []: record<r: float, g: float, b: float> -> float { | |
let c = $in | |
0.2126 * (gamma $c.r) + 0.7152 * (gamma $c.g) + 0.0722 * (gamma $c.b) | |
} | |
def luminance_to_perceived_lightness []: float -> float { | |
let luminance = $in | |
if $luminance <= 216. / 24389. { | |
$luminance * (24389. / 27.) | |
} else { | |
($luminance ** (1 / 3)) * 116. - 16. | |
} | |
} | |
def perceived_lightness []: record<r: float, g: float, b: float> -> float { | |
($in | luminance | luminance_to_perceived_lightness) / 100 | |
} | |
def query_bg_color []: nothing -> record<r: string, g: string, b: string> { | |
term query $'(ansi osc)11;?(ansi st)' --prefix $'(ansi osc)11;' --terminator (ansi st) | |
| decode | |
| parse 'rgb:{r}/{g}/{b}' | |
| get 0 | |
} | |
def get_bg_color []: nothing -> record<r: float, g: float, b: float> { | |
query_bg_color | |
| update r { parse_channel_scaled } | |
| update g { parse_channel_scaled } | |
| update b { parse_channel_scaled } | |
} | |
export def get_theme []: nothing -> string { | |
let luminance = get_bg_color | perceived_lightness | |
if $luminance <= 0.5 { | |
"dark" | |
} else { | |
"light" | |
} | |
} | |
} | |
# # Dark theme | |
# use themes/nu-themes/catppuccin-mocha.nu | |
# # Light theme | |
# use themes/nu-themes/catppuccin-latte.nu | |
# def --env _theme_pre_prompt [] { | |
# use color get_theme | |
# let current_theme = $env | get -o theme | default "" | |
# let theme = get_theme | |
# if $current_theme != $theme { | |
# # Theme has changed | |
# $env.theme = $theme | |
# match $theme { | |
# "dark" => { | |
# catppuccin-mocha set color_config | |
# $env.LS_COLORS = (vivid generate catppuccin-mocha) | |
# } | |
# "light" => { | |
# print "light" | |
# catppuccin-latte set color_config | |
# $env.LS_COLORS = (vivid generate catppuccin-latte) | |
# } | |
# } | |
# } | |
# } | |
# $env.config = ($env | default {} config).config | |
# $env.config = ($env.config | default {} hooks) | |
# $env.config = ( | |
# $env.config | upsert hooks ( | |
# $env.config.hooks | |
# | upsert pre_prompt ($env.config.hooks | get -o pre_prompt | default [] | append _theme_pre_prompt) | |
# ) | |
# ) | |
# From Bahex https://github.com/nushell/nushell/issues/15805#issuecomment-2986832138 | |
# Continue that works for _each | |
def _continue [] { | |
error make -u {msg: __continue__} | |
} | |
# Break that works for _each | |
def _break [] { | |
error make -u {msg: __break__} | |
} | |
# A version of each that can break and continue | |
def _each [fn: closure] { | |
each {|e| | |
try { | |
$e | do $fn $e | wrap item | |
} catch {|e| | |
match $e.msg { | |
__continue__ => null | |
__break__ => { break: true } | |
_ => $e.raw | |
} | |
} | |
} | |
| take until { $in.break? == true } | |
| get item | |
} | |
# View the std library files in a table | |
# from Cheer on discord | |
def "view std" []: nothing -> table { | |
view files | |
| where filename like '^std(?:-rfc)?/' | |
| insert content { | |
view span $in.start $in.end | |
| ast $in --flatten | get content | window 3 | |
| where { $in.0 starts-with 'export ' or $in.0 == 'const' } | |
| each {|lst| | |
{type: $lst.0} | |
| if $lst.1 == '--env' { | |
merge {name: $lst.2, env: true} | |
} else { | |
merge {name: $lst.1, env: false} | |
} | |
} | |
| flatten | |
| update type { str replace 'export ' '' } | |
| update name { str trim -c '"' } | |
} | |
| select filename content | |
| rename module | update module { path dirname } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const const_env = path self | |
print -e $"Hello, from ($const_env)!" | |
# Nushell Environment Config File | |
# use cargo's sparse protocol (after 1.68.0) | |
# $env.CARGO_REGISTRIES_CRATES_IO_PROTOCOL = 'sparse' | |
# nushell is automatically appended | |
# $env.XDG_CONFIG_HOME = '/Users/fdncred/.config' | |
$env.GIT_REPOS_HOME = '/Users/fdncred/src' | |
# $env.VIMRUNTIME = '/opt/homebrew/Cellar/neovim/0.9.5/share/nvim/runtime' | |
# $env.NVIM_APPNAME = "my-nvim" | |
# $env.LUNARVIM_RUNTIME_DIR = "/Users/fdncred/.local/share/lunarvim" | |
# $env.LUNARVIM_CONFIG_DIR = "/Users/fdncred/.config/lvim" | |
# $env.LUNARVIM_CACHE_DIR = "/Users/fdncred/.cache/lvim" | |
# $env.LUNARVIM_BASE_DIR = "/Users/fdncred/.local/share/lunarvim/lvim" | |
$env.TOPIARY_CONFIG_FILE = "/Users/fdncred/src/topiary-nushell/languages.ncl" | |
$env.TOPIARY_LANGUAGE_DIR = "/Users/fdncred/src/topiary-nushell/languages" | |
# Some environment variables | |
# $env.GITHUB_USERNAME = "fdncred" | |
# $env.GITHUB_PASSWORD = "12345" | |
$env.LESS = "-FRXS" | |
$env.PAGER = "less" | |
$env.PATH = ($env.PATH | | |
split row (char esep) | | |
prepend /opt/homebrew/opt/sqlite/bin | | |
# prepend /opt/homebrew/opt/coreutils/libexec/gnubin | | |
prepend /opt/homebrew/opt/uutils-coreutils/libexec/uubin | | |
prepend /opt/homebrew/bin | | |
prepend /opt/homebrew/sbin | | |
prepend /Users/fdncred/.cargo/bin | | |
prepend /opt/homebrew/opt/python/libexec/bin | | |
prepend /usr/local/bin | | |
prepend /Users/fdncred/.local/bin | |
# prepend /Users/fdncred/src/zig | |
# append /Applications/CrystalFetch.app/Contents/MacOS | |
) | |
$env.HOMEBREW_PREFIX = "/opt/homebrew" | |
$env.HOMEBREW_CELLAR = "/opt/homebrew/Cellar" | |
$env.HOMEBREW_REPOSITORY = "/opt/homebrew" | |
# $env | get -i MANPATH | default '/opt/homebrew/share/man' | |
# $env.MANPATH = ($env.MANPATH | prepend "/opt/homebrew/share/man") | |
$env.MANPATH = "/opt/homebrew/share/man:/usr/share/man:/usr/local/share/man" | |
$env.MANPAGER = "sh -c 'col -bx | bat -l man -p'" | |
$env.INFOPATH = "/opt/homebrew/share/info" | |
$env.EDITOR = "nvim" | |
$env.FZF_CTRL_T_COMMAND = "fd --type=file" | |
$env.FZF_CTRL_T_OPTS = "--preview 'bat --color=always --style=full --line-range=:500 {}'" | |
$env.FZF_ALT_C_COMMAND = "fd --type=directory" | |
$env.FZF_ALT_C_OPTS = "--preview 'tree -C {} | head -n 300'" | |
# For Microsoft's Edit finding the ICU libs | |
$env.LDFLAGS = "-L/opt/homebrew/Cellar/icu4c@77/77.1/lib" | |
$env.CPPFLAGS = "-I/opt/homebrew/Cellar/icu4c@77/77.1/include" | |
$env.PKG_CONFIG_PATH = "/opt/homebrew/Cellar/icu4c@77/77.1/lib/pkgconfig" | |
# Use nushell functions to define your right and left prompt | |
# note - i put this in my config.nu so i could utilize the NU_LIB_DIRS env var | |
# use "c:\Users\dschroeder\source\repos\forks\nu_scripts\prompt\oh-my.nu" git_prompt | |
# $env.PROMPT_COMMAND = { (git_prompt).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (git_prompt).right_prompt } | |
# The prompt indicators are environmental variables that represent | |
# the state of the prompt | |
# $env.PROMPT_INDICATOR = {|| " " } | |
# $env.PROMPT_INDICATOR_VI_INSERT = {|| ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = {|| "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = $"(ansi -e { fg: '#66cdaa'})(char -u 276f)(ansi -e { fg: '#76eec6'})(char -u 276f)(ansi -e { fg: '#7fffd4'})(char -u 276f)(ansi reset)(char space)" | |
# $env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e { fg: '#CB4B16'})(char -u '276f')(ansi -e { fg: '#CACA02'})(char -u '276f')(ansi -e { fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
# use "c:\Users\dschroeder\source\repos\forks\nu_scripts\prompt\oh-my-minimal.nu" get_prompt | |
# $env.PROMPT_COMMAND = { (get_prompt 1).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 1).right_prompt } | |
# $env.PROMPT_INDICATOR = { " " } | |
# $env.PROMPT_INDICATOR = { "〉" } | |
# $env.PROMPT_INDICATOR_VI_INSERT = { ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = { "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = { "::: " } | |
# $env.PROMPT_INDICATOR_HISTORY = { "? " } | |
# note - the string color will affect ls_colors | |
# if you make it wd, all colors for strings will | |
# be dimmed | |
# base16 | |
# https://github.com/Kirill-Bugaev/awesome-base16/blob/master/base16/apps/default_dark/dircolors | |
# $env.LS_COLORS = "no=00;37:fi=01;34:rs=00;37:di=00;34:ln=00;36:mh=00;37:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=00;05;37;41:mi=00;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=04;34:st=37;44:ex=00;32:*.cmd=00;33:*.exe=00;33:*.com=00;33:*.btm=00;33:*.bat=00;33:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz=01;31:*.bz2=01;31:*.bzip2=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.apk=01;31:*.gem=01;31:*.jpg=00;35:*.JPG=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.svg=00;35:*.svgz=00;35:*.mng=00;35:*.pcx=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.yuv=00;35:*.cgm=00;35:*.emf=00;35:*.eps=00;35:*.CR2=00;35:*.ico=00;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.html=00;32:*.css=00;32:*.rst=00;32:*.md=00;32:*.patch=00;32:*.diff=00;32:*.tex=00;32:*.xls=00;32:*.xlsx=00;32:*.doc=00;32:*.docx=00;32:*.ppt=00;32:*.pptx=00;32:*.key=00;32:*.ods=00;32:*.odt=00;32:*.pt=01;32:*.tmpl=01;32:*.in=01;32:*.ots=01;32:*.ott=01;32:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.m4a=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:*.mov=01;36:*.mpg=01;36:*.mpeg=01;36:*.m2v=01;36:*.mkv=01;36:*.ogm=01;36:*.mp4=01;36:*.m4v=01;36:*.mp4v=01;36:*.vob=01;36:*.qt=01;36:*.nuv=01;36:*.wmv=01;36:*.asf=01;36:*.rm=01;36:*.rmvb=01;36:*.flc=01;36:*.avi=01;36:*.fli=01;36:*.flv=01;36:*.gl=01;36:*.m2ts=01;36:*.divx=01;36:*.webm=01;36:*.axv=01;36:*.anx=01;36:*.ogv=01;36:*.ogx=01;36:*.conf=00;36:*.config=00;36:*.cnf=00;36:*.cfg=00;36:*.ini=00;36:*.properties=00;36:*.yaml=00;36:*.vcl=00;36:*.c=00;33:*.cpp=00;33:*.py=00;33:*.coffesscript=00;33:*.js=00;33:*.rb=00;33:*.sh=00;33:*.zsh=00;33:*.env=00;33:*.bash=00;33:*.php=00;33:*.java=00;33:*.zcml=00;33:*.pl=00;33:*.lua=00;33:*.clj=00;33:*.cs=00;33:*.fs=00;33:*.fsx=00;33:*.go=00;33:*.db=00;32:*.sql=00;32:*.json=00;32:*.plist=00;32:*.xml=00;32:*.tex=01;37:*.rdf=01;37:*.owl=01;37:*.n3=01;37:*.ttl=01;37:*.nt=01;37:*.torrent=01;37:*.xml=01;37:*Makefile=01;37:*makefile=01;37:*Rakefile=01;37:*build.xml=01;37:*rc=01;37:*.nfo=01;37:*README=01;37:*README.txt=01;37:*readme.txt=01;37:*README.markdown=01;37:*README.md=01;37:*.cc=01;37:*.log=01;30:*.bak=01;30:*.aux=01;30:*.lof=01;30:*.lol=01;30:*.lot=01;30:*.out=01;30:*.toc=01;30:*.bbl=01;30:*.blg=01;30:*~=01;30:*#=01;30:*.part=01;30:*.incomplete=01;30:*.swp=01;30:*.tmp=01;30:*.temp=01;30:*.o=01;30:*.obj=01;30:*.pyc=01;30:*.pyo=01;30:*.class=01;30:*.cache=01;30:*.egg-info=01;30:" | |
# 24-bit colors | |
# $env.LS_COLORS = (vivid generate molokai | str trim) | |
# 8-bit colors | |
# $env.LS_COLORS = "st=0:di=0;38;5;81:so=0;38;5;16;48;5;203:ln=0;38;5;203:cd=0;38;5;203;48;5;236:ex=1;38;5;203:or=0;38;5;16;48;5;203:fi=0:bd=0;38;5;81;48;5;236:ow=0:mi=0;38;5;16;48;5;203:*~=0;38;5;243:no=0:tw=0:pi=0;38;5;16;48;5;81:*.z=4;38;5;203:*.t=0;38;5;48:*.o=0;38;5;243:*.d=0;38;5;48:*.a=1;38;5;203:*.c=0;38;5;48:*.m=0;38;5;48:*.p=0;38;5;48:*.r=0;38;5;48:*.h=0;38;5;48:*.ml=0;38;5;48:*.ll=0;38;5;48:*.gv=0;38;5;48:*.cp=0;38;5;48:*.xz=4;38;5;203:*.hs=0;38;5;48:*css=0;38;5;48:*.ui=0;38;5;149:*.pl=0;38;5;48:*.ts=0;38;5;48:*.gz=4;38;5;203:*.so=1;38;5;203:*.cr=0;38;5;48:*.fs=0;38;5;48:*.bz=4;38;5;203:*.ko=1;38;5;203:*.as=0;38;5;48:*.sh=0;38;5;48:*.pp=0;38;5;48:*.el=0;38;5;48:*.py=0;38;5;48:*.lo=0;38;5;243:*.bc=0;38;5;243:*.cc=0;38;5;48:*.pm=0;38;5;48:*.rs=0;38;5;48:*.di=0;38;5;48:*.jl=0;38;5;48:*.rb=0;38;5;48:*.md=0;38;5;185:*.js=0;38;5;48:*.go=0;38;5;48:*.vb=0;38;5;48:*.hi=0;38;5;243:*.kt=0;38;5;48:*.hh=0;38;5;48:*.cs=0;38;5;48:*.mn=0;38;5;48:*.nb=0;38;5;48:*.7z=4;38;5;203:*.ex=0;38;5;48:*.rm=0;38;5;208:*.ps=0;38;5;186:*.td=0;38;5;48:*.la=0;38;5;243:*.aux=0;38;5;243:*.xmp=0;38;5;149:*.mp4=0;38;5;208:*.rpm=4;38;5;203:*.m4a=0;38;5;208:*.zip=4;38;5;203:*.dll=1;38;5;203:*.bcf=0;38;5;243:*.awk=0;38;5;48:*.aif=0;38;5;208:*.zst=4;38;5;203:*.bak=0;38;5;243:*.tgz=4;38;5;203:*.com=1;38;5;203:*.clj=0;38;5;48:*.sxw=0;38;5;186:*.vob=0;38;5;208:*.fsx=0;38;5;48:*.doc=0;38;5;186:*.mkv=0;38;5;208:*.tbz=4;38;5;203:*.ogg=0;38;5;208:*.wma=0;38;5;208:*.mid=0;38;5;208:*.kex=0;38;5;186:*.out=0;38;5;243:*.ltx=0;38;5;48:*.sql=0;38;5;48:*.ppt=0;38;5;186:*.tex=0;38;5;48:*.odp=0;38;5;186:*.log=0;38;5;243:*.arj=4;38;5;203:*.ipp=0;38;5;48:*.sbt=0;38;5;48:*.jpg=0;38;5;208:*.yml=0;38;5;149:*.txt=0;38;5;185:*.csv=0;38;5;185:*.dox=0;38;5;149:*.pro=0;38;5;149:*.bst=0;38;5;149:*TODO=1:*.mir=0;38;5;48:*.bat=1;38;5;203:*.m4v=0;38;5;208:*.pod=0;38;5;48:*.cfg=0;38;5;149:*.pas=0;38;5;48:*.tml=0;38;5;149:*.bib=0;38;5;149:*.ini=0;38;5;149:*.apk=4;38;5;203:*.h++=0;38;5;48:*.pyc=0;38;5;243:*.img=4;38;5;203:*.rst=0;38;5;185:*.swf=0;38;5;208:*.htm=0;38;5;185:*.ttf=0;38;5;208:*.elm=0;38;5;48:*hgrc=0;38;5;149:*.bmp=0;38;5;208:*.fsi=0;38;5;48:*.pgm=0;38;5;208:*.dpr=0;38;5;48:*.xls=0;38;5;186:*.tcl=0;38;5;48:*.mli=0;38;5;48:*.ppm=0;38;5;208:*.bbl=0;38;5;243:*.lua=0;38;5;48:*.asa=0;38;5;48:*.pbm=0;38;5;208:*.avi=0;38;5;208:*.def=0;38;5;48:*.mov=0;38;5;208:*.hxx=0;38;5;48:*.tif=0;38;5;208:*.fon=0;38;5;208:*.zsh=0;38;5;48:*.png=0;38;5;208:*.inc=0;38;5;48:*.jar=4;38;5;203:*.swp=0;38;5;243:*.pid=0;38;5;243:*.gif=0;38;5;208:*.ind=0;38;5;243:*.erl=0;38;5;48:*.ilg=0;38;5;243:*.eps=0;38;5;208:*.tsx=0;38;5;48:*.git=0;38;5;243:*.inl=0;38;5;48:*.rtf=0;38;5;186:*.hpp=0;38;5;48:*.kts=0;38;5;48:*.deb=4;38;5;203:*.svg=0;38;5;208:*.pps=0;38;5;186:*.ps1=0;38;5;48:*.c++=0;38;5;48:*.cpp=0;38;5;48:*.bsh=0;38;5;48:*.php=0;38;5;48:*.exs=0;38;5;48:*.toc=0;38;5;243:*.mp3=0;38;5;208:*.epp=0;38;5;48:*.rar=4;38;5;203:*.wav=0;38;5;208:*.xlr=0;38;5;186:*.tmp=0;38;5;243:*.cxx=0;38;5;48:*.iso=4;38;5;203:*.dmg=4;38;5;203:*.gvy=0;38;5;48:*.bin=4;38;5;203:*.wmv=0;38;5;208:*.blg=0;38;5;243:*.ods=0;38;5;186:*.psd=0;38;5;208:*.mpg=0;38;5;208:*.dot=0;38;5;48:*.cgi=0;38;5;48:*.xml=0;38;5;185:*.htc=0;38;5;48:*.ics=0;38;5;186:*.bz2=4;38;5;203:*.tar=4;38;5;203:*.csx=0;38;5;48:*.ico=0;38;5;208:*.sxi=0;38;5;186:*.nix=0;38;5;149:*.pkg=4;38;5;203:*.bag=4;38;5;203:*.fnt=0;38;5;208:*.idx=0;38;5;243:*.xcf=0;38;5;208:*.exe=1;38;5;203:*.flv=0;38;5;208:*.fls=0;38;5;243:*.otf=0;38;5;208:*.vcd=4;38;5;203:*.vim=0;38;5;48:*.sty=0;38;5;243:*.pdf=0;38;5;186:*.odt=0;38;5;186:*.purs=0;38;5;48:*.h264=0;38;5;208:*.jpeg=0;38;5;208:*.dart=0;38;5;48:*.pptx=0;38;5;186:*.lock=0;38;5;243:*.bash=0;38;5;48:*.rlib=0;38;5;243:*.hgrc=0;38;5;149:*.psm1=0;38;5;48:*.toml=0;38;5;149:*.tbz2=4;38;5;203:*.yaml=0;38;5;149:*.make=0;38;5;149:*.orig=0;38;5;243:*.html=0;38;5;185:*.fish=0;38;5;48:*.diff=0;38;5;48:*.xlsx=0;38;5;186:*.docx=0;38;5;186:*.json=0;38;5;149:*.psd1=0;38;5;48:*.tiff=0;38;5;208:*.flac=0;38;5;208:*.java=0;38;5;48:*.less=0;38;5;48:*.mpeg=0;38;5;208:*.conf=0;38;5;149:*.lisp=0;38;5;48:*.epub=0;38;5;186:*.cabal=0;38;5;48:*.patch=0;38;5;48:*.shtml=0;38;5;185:*.class=0;38;5;243:*.xhtml=0;38;5;185:*.mdown=0;38;5;185:*.dyn_o=0;38;5;243:*.cache=0;38;5;243:*.swift=0;38;5;48:*README=0;38;5;16;48;5;186:*passwd=0;38;5;149:*.ipynb=0;38;5;48:*shadow=0;38;5;149:*.toast=4;38;5;203:*.cmake=0;38;5;149:*.scala=0;38;5;48:*.dyn_hi=0;38;5;243:*.matlab=0;38;5;48:*.config=0;38;5;149:*.gradle=0;38;5;48:*.groovy=0;38;5;48:*.ignore=0;38;5;149:*LICENSE=0;38;5;249:*TODO.md=1:*COPYING=0;38;5;249:*.flake8=0;38;5;149:*INSTALL=0;38;5;16;48;5;186:*setup.py=0;38;5;149:*.gemspec=0;38;5;149:*.desktop=0;38;5;149:*Makefile=0;38;5;149:*Doxyfile=0;38;5;149:*TODO.txt=1:*README.md=0;38;5;16;48;5;186:*.kdevelop=0;38;5;149:*.rgignore=0;38;5;149:*configure=0;38;5;149:*.DS_Store=0;38;5;243:*.fdignore=0;38;5;149:*COPYRIGHT=0;38;5;249:*.markdown=0;38;5;185:*.cmake.in=0;38;5;149:*.gitconfig=0;38;5;149:*INSTALL.md=0;38;5;16;48;5;186:*CODEOWNERS=0;38;5;149:*.gitignore=0;38;5;149:*Dockerfile=0;38;5;149:*SConstruct=0;38;5;149:*.scons_opt=0;38;5;243:*README.txt=0;38;5;16;48;5;186:*SConscript=0;38;5;149:*.localized=0;38;5;243:*.travis.yml=0;38;5;186:*Makefile.in=0;38;5;243:*.gitmodules=0;38;5;149:*LICENSE-MIT=0;38;5;249:*Makefile.am=0;38;5;149:*INSTALL.txt=0;38;5;16;48;5;186:*MANIFEST.in=0;38;5;149:*.synctex.gz=0;38;5;243:*.fdb_latexmk=0;38;5;243:*CONTRIBUTORS=0;38;5;16;48;5;186:*configure.ac=0;38;5;149:*.applescript=0;38;5;48:*appveyor.yml=0;38;5;186:*.clang-format=0;38;5;149:*.gitattributes=0;38;5;149:*LICENSE-APACHE=0;38;5;249:*CMakeCache.txt=0;38;5;243:*CMakeLists.txt=0;38;5;149:*CONTRIBUTORS.md=0;38;5;16;48;5;186:*requirements.txt=0;38;5;149:*CONTRIBUTORS.txt=0;38;5;16;48;5;186:*.sconsign.dblite=0;38;5;243:*package-lock.json=0;38;5;243:*.CFUserTextEncoding=0;38;5;243" | |
# other vivid themes | |
# ayu, iceberg-dark, jellybeans, lava, molokai | |
# nord, one-dark, one-light, snazzy, solarized-dark | |
# solarized-light | |
# Specifies how environment variables are: | |
# - converted from a string to a value on Nushell startup (from_string) | |
# - converted from a value back to a string when running external commands (to_string) | |
# Note: The conversions happen *after* config.nu is loaded | |
# $env.ENV_CONVERSIONS = { | |
# "PATH": { | |
# from_string: { |s| $s | split row (char esep) | path expand } | |
# to_string: { |v| $v | path expand | str join (char esep) } | |
# } | |
# "Path": { | |
# from_string: { |s| $s | split row (char esep) | path expand } | |
# to_string: { |v| $v | path expand | str join (char esep) } | |
# } | |
# "LS_COLORS": { | |
# from_string: { |s| $s | split row (char esep) } | |
# # from_string: { |s| $s | split row '=' | $"(ansi -e ($in.1))m($in.0)(ansi reset) ($in.1)" } | split column ' ' | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "DYLD_FALLBACK_LIBRARY_PATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PATHEXT": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PSMODULEPATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# } | |
export-env { | |
let esep_list_converter = { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | str join (char esep) } | |
} | |
let esep_path_converter = { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | path expand | str join (char esep) } | |
} | |
$env.ENV_CONVERSIONS = { | |
# PATH: $esep_path_converter | |
# Path: $esep_path_converter | |
LS_COLORS: $esep_list_converter | |
DYLD_FALLBACK_LIBRARY_PATH: $esep_path_converter | |
# PATHEXT: $esep_list_converter | |
# PSMODULEPATH: $esep_path_converter | |
} | |
} | |
# Directories to search for scripts when calling source or use | |
# | |
# By default, <nushell-config-dir>/scripts is added | |
# $env.NU_LIB_DIRS = [ | |
# ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts | |
# '/Users/fdncred/src/nu_scripts' | |
# ($nu.config-path | path dirname) | |
# ($nu.data-dir | path join 'completions') # default home for nushell completions | |
# ] | |
# set $env.NU_LIB_DIRS and $env.NU_PLUGIN_DIRS to empty lists since I have const in config.nu | |
# $env.NU_LIB_DIRS = [] | |
# $env.NU_PLUGIN_DIRS = [] | |
# Directories to search for plugin binaries when calling register | |
# | |
# By default, <nushell-config-dir>/plugins is added | |
# $env.NU_PLUGIN_DIRS = [ | |
# ($nu.config-path | path dirname | path join 'plugins') | |
# '/Users/fdncred/.cargo/bin' | |
# ] | |
# To add entries to PATH (on Windows you might use Path), you can use the following pattern: | |
# $env.PATH = ($env.PATH | prepend '/some/path') | |
# latest zoxide | |
# zoxide init nushell --hook prompt | save -f ~/.zoxide.nu | |
# zoxide init nushell --cmd cd --hook prompt | save -f ~/.zoxide.nu | |
# $env.POSH_THEME = $"(brew --prefix oh-my-posh)/themes/jandedobbeleer.omp.json" | |
# $env.NU_VERSION = "0.74.1" | |
# Carapace | |
## ~/.config/nushell/env.nu | |
# $env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense' # optional | |
# mkdir ~/.cache/carapace | |
# carapace _carapace nushell | save --force ~/.cache/carapace/init.nu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", | |
"blocks": [ | |
{ | |
"type": "rprompt", | |
"segments": [ | |
{ | |
"properties": { | |
"time_format": "15:04:05 PM" | |
}, | |
"style": "plain", | |
"template": " {{ .CurrentDate | date .Format }} ", | |
"foreground": "#00C5C7", | |
"background": "", | |
"type": "time" | |
} | |
] | |
}, | |
{ | |
"type": "prompt", | |
"alignment": "left", | |
"segments": [ | |
{ | |
"properties": { | |
"style": "full" | |
}, | |
"style": "plain", | |
"template": "{{ .Path }}>", | |
"foreground": "#77E4F7", | |
"background": "", | |
"type": "path" | |
}, | |
{ | |
"style": "powerline", | |
"template": "{{if .Env.POSH_GIT_STRING}}{{.Env.POSH_GIT_STRING}}{{end}}", | |
"foreground": "#FFE700", | |
"background": "", | |
"type": "git", | |
"background_templates": [ | |
"{{ if or (.Working.Changed) (.Staging.Changed) }}#FFEB3B{{ end }}", | |
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}", | |
"{{ if gt .Ahead 0 }}#B388FF{{ end }}", | |
"{{ if gt .Behind 0 }}#B388FB{{ end }}" | |
] | |
} | |
] | |
}, | |
{ | |
"type": "prompt", | |
"alignment": "left", | |
"segments": [ | |
{ | |
"style": "plain", | |
"template": "❯ ", | |
"foreground": "#43D426", | |
"background": "", | |
"type": "text" | |
} | |
], | |
"newline": true | |
} | |
], | |
"version": 3 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module 'D:\src\GitHub\vcpkg\scripts\posh-vcpkg' | |
Import-Module Get-ChildItemColor | |
Set-Alias l Get-ChildItemColor -option AllScope | |
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope | |
#C:\Users\us991808\Documents\WindowsPowerShell\Scripts\winfetch.ps1 | |
#import-module microsoft.powershell.graphicaltools | |
Import-Module posh-git | |
#Import-Module oh-my-posh | |
#Set-Theme Paradox | |
# $env:POSH_THEMES_PATH = "C:\Users\us991808\AppData\Local\Programs\oh-my-posh\themes" | |
$env:POSH_THEMES_PATH = "C:\Program Files (x86)\oh-my-posh\themes" | |
#oh-my-posh --init --shell pwsh --config $env:POSH_THEMES_PATH/agnoster.omp.json | Invoke-Expression | |
#oh-my-posh --init --shell pwsh --config $env:POSH_THEMES_PATH/blue-owl.omp2.json | Invoke-Expression | |
oh-my-posh --init --shell pwsh --config $env:POSH_THEMES_PATH/powerlevel10k_lean.omp2.json | Invoke-Expression | |
# $env:POSH_GIT_ENABLED = $true | |
function Set-PoshGitStatus { | |
$global:GitStatus = Get-GitStatus | |
$env:POSH_GIT_STRING = Write-GitStatus -Status $global:GitStatus | |
} | |
New-Alias -Name 'Set-PoshContext' -Value 'Set-PoshGitStatus' -Scope Global -Force | |
# others to try out | |
#stelbent.minimal | |
#rudolfs-dark | |
#powerlevel10k_rainbow | |
#powerlevel10k_lean | |
#paradox | |
#fish | |
Import-Module PSReadLine | |
Set-PSReadLineOption -PredictionSource History | |
Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord | |
Set-PSReadLineKeyHandler -Chord "Ctrl+d" -Function BackwardKillWord | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
$env:Path += ';C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin' | |
$env:Path += ';C:\Program Files\WingetUI\choco-cli\tools' | |
$ErrorView = "Concise" | |
function _z_cd($dir) { | |
Set-Location $dir -ea Stop | |
if ($env:_ZO_ECHO -eq "1") { | |
Write-Host "$PWD" | |
} | |
} | |
function z { | |
if ($args.Length -eq 0) { | |
_z_cd ~ | |
} | |
elseif ($args.Length -eq 1 -and $args[0] -eq '-') { | |
_z_cd - | |
} | |
else { | |
$_zoxide_result = zoxide query -- @args | |
if ($LASTEXITCODE -eq 0) { | |
_z_cd $_zoxide_result | |
} | |
} | |
} | |
function zi { | |
$_zoxide_result = zoxide query -i -- @args | |
if ($LASTEXITCODE -eq 0) { | |
_z_cd $_zoxide_result | |
} | |
} | |
function za { zoxide add @args } | |
function zq { zoxide query @args } | |
function zqi { zoxide query -i @args } | |
function zr { zoxide remove @args } | |
function zl { zoxide query --list } | |
function zri { | |
$_zoxide_result = zoxide query -i -- @args | |
if ($LASTEXITCODE -eq 0) { | |
zoxide remove $_zoxide_result | |
} | |
} | |
if ($PSVersionTable.PSVersion.Major -ge 6) { | |
$ExecutionContext.InvokeCommand.LocationChangedAction = { | |
$null = zoxide add $(Get-Location) | |
} | |
} else { | |
Write-Error "pwd hook requires pwsh - use 'zoxide init powershell --hook prompt'" | |
} | |
function cargo_clippy { | |
$env:RUSTFLAGS = "-D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err" | |
cargo clippy --all --features=dataframe -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err | |
} | |
function cargo_tests { | |
#$env:RUSTFLAGS = "-D warnings" | |
#cargo test --workspace | |
cargo nextest run --all --features=dataframe | |
} | |
# Ignore the git tls error | |
# $env:GIT_SSL_NO_VERIFY = 1 | |
#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module | |
Import-Module -Name Microsoft.WinGet.CommandNotFound | |
#f45873b3-b655-43a6-b217-97c00aa0db58 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# version output to markdown | |
def nuvermd [] { version | transpose key value | to md } | |
# version output to nushell table | |
def nuver [] { version | transpose key value } | |
# use pbcopy on macos to copy to clipboard | |
alias clip = pbcopy | |
# ls with colors, icons and grid | |
def lsg [] { ls | sort-by type name -i | grid -c } | |
# figure out how many lines are in code with tokei | |
def tok [] { | |
tokei | lines | skip 1 | str join "\n" | detect columns | | |
where Language !~ "=" and Language !~ "-" and Language !~ '\(' | | |
into int Files Lines Code Comments Blanks | |
} | |
#alias for lazygit | |
alias lg = lazygit | |
# alias lvim = ^/home/fdncred/.local/bin/lvim | |
# exec -a "$NVIM_APPNAME" nvim -u "$LUNARVIM_BASE_DIR/init.lua" "$@" | |
def path_underline [color: string] { | |
{|p| if ($p | path exists) { | |
$color + "_underline" | |
} else { | |
$color | |
} | |
} | |
} | |
def is_alias [cmd: string] { | |
$cmd in (scope aliases | get name) | |
} | |
# # abbreviation for git status | |
# alias gst = git status | |
# # List all local branches | |
# alias gb = git branch | |
# Fix vi mistakes | |
#alias vi = nvim | |
# Fix vim mistakes | |
#alias vim = nvim | |
# alias gfu = git fetch upstream | |
# alias gmum = git merge upstream/main | |
# alias gpom = git push origin main | |
# alias gcom = git checkout main | |
# long listing | |
alias ll = ls -l | |
# region: Themes | |
# attributes | |
# code meaning | |
# l blink | |
# b bold | |
# d dimmed | |
# h hidden | |
# i italic | |
# r reverse | |
# s strikethrough | |
# u underline | |
# n nothing | |
# defaults to nothing | |
# let base00 = "#181818" # Default Background | |
# let base01 = "#282828" # Lighter Background (Used for status bars, line number and folding marks) | |
# let base02 = "#383838" # Selection Background | |
# let base03 = "#585858" # Comments, Invisibles, Line Highlighting | |
# let base04 = "#b8b8b8" # Dark Foreground (Used for status bars) | |
# let base05 = "#d8d8d8" # Default Foreground, Caret, Delimiters, Operators | |
# let base06 = "#e8e8e8" # Light Foreground (Not often used) | |
# let base07 = "#f8f8f8" # Light Background (Not often used) | |
# let base08 = "#ab4642" # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted | |
# let base09 = "#dc9656" # Integers, Boolean, Constants, XML Attributes, Markup Link Url | |
# let base0a = "#f7ca88" # Classes, Markup Bold, Search Text Background | |
# let base0b = "#a1b56c" # Strings, Inherited Class, Markup Code, Diff Inserted | |
# let base0c = "#86c1b9" # Support, Regular Expressions, Escape Characters, Markup Quotes | |
# let base0d = "#7cafc2" # Functions, Methods, Attribute IDs, Headings | |
# let base0e = "#ba8baf" # Keywords, Storage, Selector, Markup Italic, Diff Changed | |
# let base0f = "#a16946" # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?> | |
# let base16_theme = { | |
# separator: $base03 | |
# leading_trailing_space_bg: $base04 | |
# header: $base0b | |
# date: $base0e | |
# filesize: $base0d | |
# row_index: $base0c | |
# bool: $base08 | |
# int: $base0b | |
# duration: $base08 | |
# range: $base08 | |
# float: $base08 | |
# string: $base04 | |
# nothing: $base08 | |
# binary: $base08 | |
# cellpath: $base08 | |
# # shape_garbage: { fg: $base07 bg: $base08 attr: b} # base16 white on red | |
# # but i like the regular white on red for parse errors | |
# shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b} | |
# shape_bool: $base0d | |
# shape_int: { fg: $base0e attr: b} | |
# shape_float: { fg: $base0e attr: b} | |
# shape_range: { fg: $base0a attr: b} | |
# shape_internalcall: { fg: $base0c attr: b} | |
# shape_external: $base0c | |
# shape_externalarg: { fg: $base0b attr: b} | |
# shape_literal: $base0d | |
# shape_operator: $base0a | |
# shape_signature: { fg: $base0b attr: b} | |
# shape_string: $base0b | |
# shape_filepath: $base0d | |
# shape_globpattern: { fg: $base0d attr: b} | |
# shape_variable: $base0e | |
# shape_flag: { fg: $base0d attr: b} | |
# shape_custom: {attr: b} | |
# shape_matching_brackets: { attr: u } | |
# } | |
let my_theme = { | |
binary: red | |
bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
cellpath: cyan | |
date: {|| (date now) - $in | | |
if $in < 1hr { | |
'red3b' #"\e[38;5;160m" #'#e61919' # 160 | |
} else if $in < 6hr { | |
'orange3' #"\e[38;5;172m" #'#e68019' # 172 | |
} else if $in < 1day { | |
'yellow3b' #"\e[38;5;184m" #'#e5e619' # 184 | |
} else if $in < 3day { | |
'chartreuse2b' #"\e[38;5;112m" #'#80e619' # 112 | |
} else if $in < 1wk { | |
'green3b' #"\e[38;5;40m" #'#19e619' # 40 | |
} else if $in < 6wk { | |
'darkturquoise' #"\e[38;5;44m" #'#19e5e6' # 44 | |
} else if $in < 52wk { | |
'deepskyblue3b' #"\e[38;5;32m" #'#197fe6' # 32 | |
} else { 'dark_gray' } | |
} | |
duration: blue_bold | |
filesize: {|e| if $e == 0b { 'black' } else if $e < 1mb { 'blue' } else { 'cyan' } } | |
float: red | |
header: gb | |
hints: dark_gray | |
int: green | |
leading_trailing_space_bg: {bg: dark_gray_dimmed} | |
nothing: red | |
range: purple | |
row_index: cb | |
separator: purple | |
# string: { if $in =~ '^#\w{6}$' { $in } else { 'white' } } | |
string: {|| if $in =~ '^#[a-fA-F\d]+' { $in } else { 'default' } } | |
# search_result: {bg: red fg: white} | |
search_result: {bg: deepskyblue1 fg: black} | |
# search_result: blue_reverse | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: "#33ff00" | |
shape_bool: light_cyan | |
shape_closure: "#ffb000" | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: darkorange | |
shape_externalarg: green_bold | |
shape_external_resolved: light_yellow_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: { fg: white bg: red attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_keyword: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: { attr: u } | |
# shape_matching_brackets: { fg: red bg: default attr: b } | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
shape_vardecl: purple | |
} | |
# For more information on themes, see | |
# https://www.nushell.sh/book/coloring_and_theming.html | |
let dark_theme = { | |
# color for nushell primitives | |
separator: white | |
leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off | |
header: green_bold | |
empty: blue | |
# Closures can be used to choose colors for specific values. | |
# The value (in this case, a bool) is piped into the closure. | |
bool: {|| if $in { 'light_cyan' } else { 'light_red' } } | |
int: white | |
filesize: {|e| | |
if $e == 0b { | |
'white' | |
} else if $e < 1mb { | |
'cyan' | |
} else { 'blue' } | |
} | |
duration: white | |
date: {|| (date now) - $in | | |
if $in < 1hr { | |
'red3b' | |
} else if $in < 6hr { | |
'orange3' | |
} else if $in < 1day { | |
'yellow3b' | |
} else if $in < 3day { | |
'chartreuse2b' | |
} else if $in < 1wk { | |
'green3b' | |
} else if $in < 6wk { | |
'darkturquoise' | |
} else if $in < 52wk { | |
'deepskyblue3b' | |
} else { 'dark_gray' } | |
} | |
range: white | |
float: white | |
string: white | |
nothing: white | |
binary: white | |
cellpath: white | |
row_index: green_bold | |
record: white | |
list: white | |
block: white | |
hints: dark_gray | |
shape_and: purple_bold | |
shape_binary: purple_bold | |
shape_block: blue_bold | |
shape_bool: light_cyan | |
shape_custom: green | |
shape_datetime: cyan_bold | |
shape_directory: cyan | |
shape_external: cyan | |
shape_externalarg: green_bold | |
shape_filepath: cyan | |
shape_flag: blue_bold | |
shape_float: purple_bold | |
# shapes are used to change the cli syntax highlighting | |
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b} | |
shape_globpattern: cyan_bold | |
shape_int: purple_bold | |
shape_internalcall: cyan_bold | |
shape_list: cyan_bold | |
shape_literal: blue | |
shape_match_pattern: green | |
shape_matching_brackets: { attr: u } | |
shape_nothing: light_cyan | |
shape_operator: yellow | |
shape_or: purple_bold | |
shape_pipe: purple_bold | |
shape_range: yellow_bold | |
shape_record: cyan_bold | |
shape_redirection: purple_bold | |
shape_signature: green_bold | |
shape_string: green | |
shape_string_interpolation: cyan_bold | |
shape_table: blue_bold | |
shape_variable: purple | |
} | |
# endregion | |
# region: External Completers | |
# let external_completer = {|spans| | |
# { | |
# $spans.0: {carapace $spans.0 nushell $spans | from json } # default | |
# } | get $spans.0 | each {|it| do $it} | |
# } | |
# let external_completer = {|spans| | |
# { | |
# $spans.0: {carapace $spans.0 nushell $spans | from json } # default | |
# "empty": { "[]" | from json } # no result (valid json) | |
# "unknown": { "" | from json } # default file completion (invalid json) | |
# "vals": { '["a", "b", "c"]' | from json } # external completion (valid json) | |
# } | get $spans.0 | each {|it| do $it} | |
# } | |
# let fish_completer = {|spans| | |
# fish --command $'complete "--do-complete=($spans | str join " ")"' | |
# | str trim | split row "\n" | each { |line| $line | split column "\t" value description } | flatten | |
# } | |
# latest external completers from the cookbook 7/18/2023 | |
# let carapace_completer = {|spans| | |
# carapace $spans.0 nushell $spans | from json | |
# } | |
# let fish_completer = {|spans| | |
# fish --command $'complete "--do-complete=($spans | str join (char space))"' | |
# | $"value(char tab)description(char newline)" + $in | |
# | from tsv --flexible --no-infer | |
# } | |
# let zoxide_completer = {|spans| | |
# $spans | skip 1 | zoxide query -l $in | lines | where {|x| $x != $env.PWD} | |
# } | |
# let carapace_completer = {|spans: list<string>| | |
# carapace $spans.0 nushell $spans | |
# | from json | |
# | if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null } | |
# } | |
# let multiple_completers = {|spans| | |
# let expanded_alias = (scope aliases | where name == $spans.0 | get -i 0 | get -i expansion) | |
# let spans = (if $expanded_alias != null { | |
# $spans | skip 1 | prepend ($expanded_alias | split words) | |
# } else { $spans }) | |
# # match spans.0 { | |
# # "z" | "zi" => $zoxide_completer | |
# # "nu" => $fish_completer | |
# # "git" => $carapace_completer | |
# # _ => $carapace_completer | |
# # } | |
# { | |
# # zoxide alias | |
# z: $zoxide_completer | |
# # zoxide alias | |
# zi: $zoxide_completer | |
# # carapace completions are incorrect for nu | |
# nu: $fish_completer | |
# # fish completes commits and branch names in a nicer way | |
# git: $fish_completer | |
# } | get -i $spans.0 | default $carapace_completer | do $in $spans # use carapace as default | |
# } | |
let external_completer = {|spans| | |
let carapace_completer = {|spans| | |
carapace $spans.0 nushell ...$spans | |
| from json | |
| if ($in | is-not-empty) and ($in | where value =~ 'ERR"?$' | is-empty) { $in } else { null } | |
} | |
let zoxide_completer = {|spans| | |
$spans | skip 1 | zoxide query -l $in | lines | where {|x| $x != $env.PWD} | |
} | |
let expanded_alias = scope aliases | where name == $spans.0 | get -i 0.expansion | |
let spans = if $expanded_alias != null { | |
$spans | skip 1 | prepend ($expanded_alias | str replace '^' '' | split row " " | take 1) | |
} else { | |
$spans | |
} | |
match $spans.0 { | |
z | zi | __zoxide_z | __zoxide_zi => $zoxide_completer, | |
_ => $carapace_completer | |
} | do $in $spans | |
} | |
# endregion | |
# region: Config | |
$env.config = { | |
show_banner: true # true or false to enable or disable the banner | |
ls: { | |
use_ls_colors: true # use the LS_COLORS environment variable to colorize output | |
clickable_links: true # true or false to enable or disable clickable links in the ls listing. your terminal has to support links. | |
} | |
rm: { | |
always_trash: true # always act as if -t was given. Can be overridden with -p | |
} | |
table: { | |
mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other | |
index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column | |
show_empty: false # show 'empty list' and 'empty record' placeholders for command output | |
padding: {left: 1, right: 1} # int or record {left: 0 right: 0} | |
trim: { # A strategy of managing table view in case of limited space. | |
methodology: wrapping # truncating or wrapping | |
wrapping_try_keep_words: true | |
# A suffix which will be used with 'truncating' methodology | |
truncating_suffix: "…" # "⋯" "︙" | |
} | |
header_on_separator: true # show header text on separator/border line | |
# abbreviated_row_count: 10 # limit data rows from top and bottom after reaching a set point | |
} | |
error_style: "fancy" # "fancy" or "plain" for screen reader-friendly error messages | |
# datetime_format: { | |
# # normal: "%Y-%m-%d %H:%M:%S" | |
# normal: "%F %r" | |
# # table: "%Y-%m-%d %H:%M:%S" | |
# # table: "%b %d %Y %I:%M:%S %p" | |
# # table: "%s" | |
# # table: "%F %r" | |
# table: "%x %r" | |
# } | |
datetime_format: { | |
# normal: '%a, %d %b %Y %H:%M:%S %z' # shows up in displays of variables or other datetime's outside of tables | |
# table: '%m/%d/%y %I:%M:%S%p' # generally shows up in tabular outputs such as ls | |
} | |
explore: { | |
config: { | |
cursor_color: 'red' | |
} | |
table: { | |
selected_cell: { bg: 'blue'} | |
show_cursor: false | |
} | |
try: { | |
reactive: true | |
} | |
} | |
history: { | |
max_size: 1_000_000 # Session has to be reloaded for this to take effect | |
sync_on_enter: true # Enable to share the history between multiple sessions, else you have to close the session to persist history to file | |
file_format: sqlite # "sqlite" or "plaintext" | |
isolation: false # true enables history isolation, false disables it. history_isolation is a unique history per session. | |
} | |
completions: { | |
case_sensitive: false # set to true to enable case-sensitive completions | |
quick: true # set this to false to prevent auto-selecting completions when only one remains | |
partial: true # set this to false to prevent partial filling of the prompt | |
algorithm: "prefix" # prefix, fuzzy | |
external: { | |
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow | |
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options | |
completer: null | |
} | |
use_ls_colors: true # set this to true to enable file/path/directory completions using LS_COLORS | |
} | |
filesize: { | |
metric: true # true => KB, MB, GB (ISO standard), false => KiB, MiB, GiB (Windows standard) | |
format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto | |
} | |
cursor_shape: { | |
emacs: line | |
vi_insert: block | |
vi_normal: underscore | |
} | |
color_config: $my_theme | |
use_grid_icons: true | |
footer_mode: 5 #always, never, number_of_rows, auto | |
float_precision: 2 | |
buffer_editor: "nvim" # command that will be used to edit the current line buffer with ctr+e | |
use_ansi_coloring: true | |
# ansi_coloring: auto # enabled, disabled or auto | |
bracketed_paste: true # enable bracketed paste, currently useless on windows | |
edit_mode: emacs # emacs, vi | |
# shell_integration: true # enables terminal markers and a workaround to arrow keys stop working issue | |
shell_integration: { | |
# osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title | |
osc2: true | |
# osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory | |
osc7: true | |
# osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it | |
osc8: true | |
# osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal | |
osc9_9: false | |
# osc133 is several escapes invented by Final Term which include the supported ones below. | |
# 133;A - Mark prompt start | |
# 133;B - Mark prompt end | |
# 133;C - Mark pre-execution | |
# 133;D;exit - Mark execution finished with exit code | |
# This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is | |
osc133: true | |
# osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features | |
# 633;A - Mark prompt start | |
# 633;B - Mark prompt end | |
# 633;C - Mark pre-execution | |
# 633;D;exit - Mark execution finished with exit code | |
# 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce | |
# 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal | |
# and also helps with the run recent menu in vscode | |
osc633: true | |
# reset_application_mode is escape \x1b[?1l and was added to help ssh work better | |
reset_application_mode: true | |
} | |
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt. | |
use_kitty_protocol: true # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this | |
highlight_resolved_externals: true | |
plugins: {} # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration. | |
plugin_gc: { | |
# Configuration for plugin garbage collection | |
default: { | |
enabled: true # true to enable stopping of inactive plugins | |
stop_after: 0sec # how long to wait after a plugin is inactive to stop it | |
} | |
plugins: { | |
# alternate configuration for specific plugins, by name, for example: | |
# | |
# gstat: { | |
# enabled: false | |
# } | |
} | |
} | |
hooks: { | |
pre_prompt: [{|| | |
#if (shells | length) > 1 { tabline-hook } | |
null | |
#print -n "pre_p " (date now | format date "%Y-%m-%d %H:%M:%S.%f") (char nl) | |
#if "LAST_CMD" in $env { | |
# print $"(ansi title)(pwd | str replace "/Users/fdncred" "~") > ($env.LAST_CMD)(ansi st)" | |
#} else { | |
# print $"(ansi title)(pwd | str replace "/Users/fdncred" "~")(ansi st)" | |
#} | |
}] | |
pre_execution: [{|| | |
null | |
# $env.LAST_CMD = (commandline) | |
#print -n "pre_e " (date now | format date "%Y-%m-%d %H:%M:%S.%f") (char nl) | |
}] | |
env_change: { | |
PWD: [ | |
{ |before, after| | |
#print $"before: [($before)], after: [($after)]" | |
# print ($env.LS_COLORS) | |
print (lsg) | |
# null | |
}, | |
{ | |
condition: {|_, after| not ($after | path join 'toolkit.nu' | path exists)} | |
code: "hide toolkit" | |
# code: "overlay hide --keep-env [ PWD ] toolkit" | |
}, | |
{ | |
condition: {|_, after| $after | path join 'toolkit.nu' | path exists} | |
code: " | |
print $'(ansi default_underline)(ansi default_bold)toolkit(ansi reset) module (ansi green_italic)detected(ansi reset)...' | |
print $'(ansi yellow_italic)activating(ansi reset) (ansi default_underline)(ansi default_bold)toolkit(ansi reset) module with `(ansi default_dimmed)(ansi default_italic)use toolkit.nu(ansi reset)`' | |
use toolkit.nu | |
# overlay use --prefix toolkit.nu | |
" | |
}, | |
{|before, _| | |
if $before == null { | |
let file = ($nu.home-path | path join ".local" "share" "nushell" "startup-times.nuon") | |
if not ($file | path exists) { | |
mkdir ($file | path dirname) | |
touch $file | |
} | |
let ver = (version) | |
open $file | append { | |
date: (date now) | |
time: $nu.startup-time | |
build: ($ver.build_rust_channel) | |
allocator: ($ver.allocator) | |
version: ($ver.version) | |
commit: ($ver.commit_hash) | |
build_time: ($ver.build_time) | |
} | collect { save --force $file } | |
} | |
} | |
] | |
} | |
# display_output: { | |
# if (term size).columns > 100 { table -e } else { table } | |
# # table | |
# } | |
# display_output: { | |
# $env.__ = $in; | |
# print $env.__; | |
# } | |
display_output: { table } # run before the output of a command is drawn, example: `{ if (term size).columns >= 100 { table -e } else { table } }` | |
command_not_found: {|| | |
null # replace with source code to return an error message when a command is not found | |
} | |
} | |
# old timey crt colors | |
# #ffb000 <- 600nm P3 <--history_menu | |
# #ffcc00 <- 593nm | |
# #33ff00 <- 524nm <-- completion_menu | |
# #33ff33 <- P1 | |
# #00ff33 <- 506nm | |
# #66ff66 <- P24 | |
# #00ff66 <- 502nm | |
# #282828 <- background | |
# log_level: trace | |
# region: Menus | |
menus: [ | |
# Configuration for default nushell menus | |
# Note the lack of souce parameter | |
{ | |
name: completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
} | |
style: { | |
text: { fg: "#33ff00" } | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
selected_text: {attr: r} | |
# selected_text: { attr: r } | |
description_text: yellow | |
match_text: {attr: u} | |
selected_match_text: {attr: ur} | |
} | |
# style: { | |
# text: green | |
# selected_text: {attr: r} | |
# description_text: yellow | |
# } | |
} | |
{ | |
name: ide_completion_menu | |
only_buffer_difference: false | |
marker: $" \n❯ (char -u '1f4ce') " | |
type: { | |
layout: ide | |
min_completion_width: 0, | |
max_completion_width: 50, | |
max_completion_height: 10, # will be limited by the available lines in the terminal | |
padding: 0, | |
border: true, | |
cursor_offset: 0, | |
description_mode: "prefer_right" | |
min_description_width: 0 | |
max_description_width: 50 | |
max_description_height: 10 | |
description_offset: 1 | |
# If true, the cursor pos will be corrected, so the suggestions match up with the typed text | |
# | |
# C:\> str | |
# str join | |
# str trim | |
# str split | |
correct_cursor_pos: false | |
} | |
style: { | |
# text: { fg: "#33ff00" } | |
# selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b} | |
# description_text: yellow | |
text: green | |
selected_text: {attr: r} | |
description_text: yellow | |
match_text: {fg: darkorange} | |
selected_match_text: {fg: darkorange attr: r} | |
} | |
} | |
{ | |
name: history_menu | |
only_buffer_difference: true | |
marker: $"(char -u '1f50d') " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#ffb000" | |
selected_text: { fg: "#ffb000" attr: r } | |
description_text: yellow | |
} | |
} | |
{ | |
name: help_menu | |
only_buffer_difference: true | |
marker: "? " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: "#7F00FF" | |
selected_text: { fg: "#ffff00" bg: "#7F00FF" attr: b } | |
description_text: "#ffff00" | |
} | |
} | |
# Example of extra menus created using a nushell source | |
# Use the source field to create a list of records that populates | |
# the menu | |
{ | |
name: fzf_history_menu_fzf_ui | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
open $nu.history-path | get history.command_line | |
| to text | fzf +s --tac | str trim | |
| where $it =~ $buffer | |
| each { |v| {value: ($v | str trim) } } | |
} | |
} | |
{ | |
name: fzf_menu_nu_ui | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: list | |
page_size: 10 | |
} | |
style: { | |
text: "#66ff66" | |
selected_text: { fg: "#66ff66" attr: r } | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
open $nu.history-path | get history.command_line | |
| to text | |
| fzf -f $buffer | |
| lines | |
| each { |v| {value: ($v | str trim) } } | |
} | |
} | |
{ | |
name: commands_menu | |
only_buffer_difference: false | |
marker: "# " | |
type: { | |
layout: columnar | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each { |it| {value: $it.name description: $it.usage} } | |
} | |
} | |
{ | |
name: vars_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope variables | |
| where name == $buffer | |
| each { |it| {value: $it.value }} | |
} | |
} | |
{ | |
name: commands_with_description | |
only_buffer_difference: true | |
marker: "# " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope commands | |
| where name =~ $buffer | |
| each { |it| {value: $it.name description: $it.usage} } | |
} | |
} | |
{ | |
name: abbr_menu | |
only_buffer_difference: false | |
marker: "👀 " | |
type: { | |
layout: columnar | |
columns: 1 | |
col_width: 20 | |
col_padding: 2 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
scope aliases | |
| where name == $buffer | |
| each { |it| {value: $it.expansion }} | |
} | |
} | |
{ | |
name: grid_history_menu | |
only_buffer_difference: true | |
marker: "<?> " | |
type: { | |
layout: description | |
columns: 4 | |
col_width: 20 | |
col_padding: 2 | |
selection_rows: 4 | |
description_rows: 10 | |
} | |
style: { | |
text: green | |
selected_text: green_reverse | |
description_text: yellow | |
} | |
source: { |buffer, position| | |
history | |
| where command =~ $buffer | |
| where exit_status < 1 | |
| get command | |
| each { |it| {value: $it description: (try {help $"($it | str trim)"| lines | get 0} catch { "" }) } } | |
} | |
} | |
] | |
# endregion | |
# region: Keybindings | |
# mac keyboard | |
# home = fn + left | |
# end = fn + right | |
# pageup = fn + up | |
# pagedown = fn + down | |
# backspace = delete | |
# delete = fn + delete | |
keybindings: [ | |
{ | |
name: insert_newline | |
modifier: alt | |
keycode: char_i | |
mode: [emacs vi_normal vi_insert] | |
event: { edit: insertnewline } | |
} | |
{ | |
name: insert_newline | |
modifier: alt | |
keycode: enter | |
mode: [emacs vi_normal vi_insert] | |
event: { edit: insertnewline } | |
} | |
# { | |
# name: insert_newline | |
# modifier: shift | |
# keycode: (char cr) | |
# mode: [emacs vi_normal vi_insert] | |
# event: { edit: insertnewline } | |
# } | |
{ | |
name: trigger-completion-menu | |
modifier: none | |
keycode: tab | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: completion_menu } | |
{ send: menunext } | |
{ edit: complete } | |
] | |
} | |
} | |
{ | |
name: completion_previous | |
modifier: shift | |
keycode: backtab | |
mode: [emacs vi_normal vi_insert] | |
event: { send: menuprevious } | |
} | |
{ | |
name: clear | |
modifier: none | |
keycode: esc | |
mode: [emacs vi_normal vi_insert] | |
event: { edit: clear } | |
} | |
{ | |
name: complete_hint_chunk | |
modifier: alt | |
keycode: right | |
mode: [emacs vi_normal vi_insert] | |
event: { until: [ | |
{ send: historyhintwordcomplete } | |
{ edit: movewordright } | |
] | |
} | |
} | |
{ | |
name: un_complete_hint_chunk | |
modifier: alt | |
keycode: left | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: backspaceword } | |
] | |
} | |
{ | |
name: trigger-history-menu | |
modifier: control | |
keycode: char_x | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: history_menu } | |
{ send: menupagenext } | |
] | |
} | |
} | |
{ | |
name: trigger-history-previous | |
modifier: control | |
keycode: char_z | |
mode: [emacs vi_normal vi_insert] | |
event: { until: [ | |
{ send: menupageprevious } | |
{ edit: undo } | |
] | |
} | |
} | |
{ | |
name: trigger-help-menu | |
modifier: control | |
keycode: char_q | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: help_menu } | |
{ send: menunext } | |
] | |
} | |
} | |
{ | |
name: prev_shell | |
modifier: control | |
keycode: char_p | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: clear } | |
{ edit: insertchar value: p } | |
{ send: enter } | |
] | |
} | |
{ | |
name: next_shell | |
modifier: control | |
keycode: char_n | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: clear } | |
{ edit: insertchar value: n } | |
{ send: enter } | |
] | |
} | |
# { | |
# name: change_dir_with_fzf | |
# modifier: control | |
# keycode: char_f | |
# mode: [emacs vi_normal vi_insert] | |
# event: { | |
# send: executehostcommand, | |
# cmd: "cd (ls | where type == dir | each { |it| $it.name} | str join (char nl) | fzf | decode utf-8 | str trim)" | |
# } | |
# } | |
{ | |
name: complete_in_cd | |
modifier: none | |
keycode: f2 | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: clear } | |
{ edit: insertString value: "./" } | |
{ send: Menu name: completion_menu } | |
] | |
} | |
{ | |
name: reload_config | |
modifier: none | |
keycode: f5 | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
send: executehostcommand, | |
cmd: $"source '($nu.env-path)';source '($nu.config-path)'" | |
} | |
} | |
{ | |
name: clear_backbuffer | |
modifier: control | |
keycode: char_l | |
mode: [emacs vi_normal vi_insert] | |
event: { send: ClearScrollback } | |
} | |
# { | |
# name: edit_buffer | |
# modifier: control | |
# keycode: char_i | |
# mode: [emacs vi_normal vi_insert] | |
# event: { send: OpenEditor } | |
# } | |
{ | |
name: insert_last_token | |
modifier: alt | |
keycode: char_. | |
mode: [emacs vi_normal vi_insert] | |
event: [ | |
{ edit: InsertString, value: " !$" } | |
{ send: Enter } | |
] | |
} | |
# Keybindings used to trigger the user defined menus | |
{ #notworking | |
name: fzf_history_menu_fzf_ui | |
modifier: alt | |
keycode: char_e | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: fzf_history_menu_fzf_ui } | |
} | |
{ | |
name: fzf_menu_nu_ui | |
modifier: alt | |
keycode: char_w | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: fzf_menu_nu_ui } | |
} | |
{ | |
name: commands_menu | |
modifier: control | |
keycode: char_t | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: commands_menu } | |
} | |
{ | |
name: vars_menu | |
modifier: control | |
keycode: char_y | |
mode: [emacs, vi_normal, vi_insert] | |
event:[ | |
{ send: menu name: vars_menu } | |
{ edit: insertchar, value: ' '} | |
] | |
} | |
{ | |
name: commands_with_description | |
modifier: control | |
keycode: char_u | |
mode: [emacs, vi_normal, vi_insert] | |
event: { send: menu name: commands_with_description } | |
} | |
# { | |
# name: alias_menu | |
# modifier: control | |
# keycode: char_a | |
# mode: [emacs, vi_normal, vi_insert] | |
# event: { send: menu name: alias_menu } | |
# } | |
{ | |
name: abbr | |
modifier: control | |
keycode: space | |
mode: [emacs, vi_normal, vi_insert] | |
event: [ | |
{ send: menu name: abbr_menu } | |
{ edit: insertchar, value: ' '} | |
] | |
} | |
# { | |
# name: fuzzy_history_skim | |
# modifier: control | |
# keycode: char_r | |
# mode: [emacs vi_normal vi_insert] | |
# event: { | |
# send: executehostcommand | |
# cmd: "commandline (history | each { |it| $it.command } | uniq | reverse | str join (char nl) | sk --layout=reverse --height=40% -q (commandline) | decode utf-8 | str trim)" | |
# } | |
# } | |
{ | |
name: insert_last_arg_from_prev_cmd | |
modifier: alt | |
keycode: char_. | |
mode: [emacs, vi_normal, vi_insert] | |
event: { | |
send: executeHostCommand | |
cmd: "commandline --insert (history | last | get command | parse --regex '(?P<arg>[^ ]+)$' | get arg | first)" | |
} | |
} | |
{ | |
name: fuzzy_history_fzf | |
modifier: control | |
keycode: char_r | |
mode: [emacs , vi_normal, vi_insert] | |
event: { | |
send: executehostcommand | |
cmd: "commandline ( | |
history | |
| where exit_status == 0 | |
| get command | |
| reverse | |
| uniq | |
| str join (char -i 0) | |
| fzf --scheme=history --read0 --tiebreak=chunk --layout=reverse --preview='echo {..}' --preview-window='bottom:3:wrap' --bind alt-up:preview-up,alt-down:preview-down --height=70% -q (commandline) --preview='echo -n {} | nu --stdin -c \'nu-highlight\'' | |
| decode utf-8 | |
| str trim | |
)" | |
} | |
} | |
# { | |
# name: fuzzy_history | |
# modifier: control | |
# keycode: char_r | |
# mode: [emacs, vi_normal, vi_insert] | |
# event: [ | |
# { | |
# send: ExecuteHostCommand | |
# cmd: "commandline ( | |
# history | |
# | each { |it| $it.command } | |
# | uniq | |
# | reverse | |
# | str join (char -i 0) | |
# | fzf --read0 --layout=reverse --height=40% -q (commandline) | |
# | decode utf-8 | |
# | str trim | |
# )" | |
# } | |
# ] | |
# } | |
{ | |
name: insert_file | |
modifier: alt | |
keycode: char_y | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
send: executehostcommand | |
cmd: "commandline --insert (fzf --tiebreak=chunk --layout=reverse --multi --preview='echo {..}' --preview-window='bottom:3:wrap' --height=70% | decode utf-8 | str trim)" | |
} | |
} | |
{ | |
name: insert_sudo | |
modifier: alt | |
keycode: char_s | |
mode: [emacs, vi_insert, vi_normal] | |
event: [ | |
{ edit: MoveToStart } | |
{ send: ExecuteHostCommand, | |
cmd: 'if (commandline | split row -r '\s+' | first) != `sudo` { commandline --insert `sudo `;commandline --cursor-end; }' | |
} | |
] | |
} | |
{ | |
name: copy_selection | |
modifier: control_shift | |
keycode: char_c | |
mode: emacs | |
event: { edit: copyselection } | |
} | |
{ | |
name: cut_selection | |
modifier: control_shift | |
keycode: char_x | |
mode: emacs | |
event: { edit: cutselection } | |
} | |
{ | |
name: select_all | |
modifier: control_shift | |
keycode: char_a | |
mode: emacs | |
event: { edit: selectall } | |
} | |
{ | |
name: paste | |
modifier: control_shift | |
keycode: char_v | |
mode: emacs | |
event: { edit: pastecutbufferbefore } | |
} | |
{ | |
name: ide_completion_menu | |
modifier: control | |
keycode: char_n | |
mode: [emacs vi_normal vi_insert] | |
event: { | |
until: [ | |
{ send: menu name: ide_completion_menu } | |
{ send: menunext } | |
{ edit: complete } | |
] | |
} | |
} | |
] | |
# endregion | |
} | |
# endregion | |
# Custom Commands | |
source defs.nu | |
# region: prompts | |
# prompt | |
use "modules/prompt/oh-my.nu" git_prompt | |
$env.PROMPT_COMMAND = {|| (git_prompt).left_prompt } | |
$env.PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt } | |
$env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) {$"(ansi green_bold)\n❯ (ansi reset)"} else {$"(ansi red_bold)\n❯ (ansi reset)"}} | |
$env.TRANSIENT_PROMPT_COMMAND = { "" } | |
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = { || (git_prompt).right_prompt } | |
$env.TRANSIENT_PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) {$"(ansi light_yellow_bold)❯ (ansi reset)"} else {$"(ansi light_red_bold)❯ (ansi reset)"}} | |
# use "modules/prompt/full-line.nu" | |
# $env.PROMPT_COMMAND = {|| full-line } | |
# $env.PROMPT_COMMAND_RIGHT = "" | |
# $env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) {$"(ansi green_bold)\n❯ (ansi reset)"} else {$"(ansi red_bold)\n❯ (ansi reset)"}} | |
# $env.STARSHIP_SHELL = "nu" | |
# $env.STARSHIP_SESSION_KEY = (random chars -l 16) | |
# $env.PROMPT_INDICATOR = "" | |
# $env.PROMPT_MULTILINE_INDICATOR = (^starship prompt --continuation) | |
# $env.PROMPT_COMMAND = { || | |
# let width = (term size | get columns) | |
# ^starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" | |
# } | |
# $env.PROMPT_COMMAND_RIGHT = { || | |
# let width = (term size | get columns) | |
# ^starship prompt --right $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" | |
# } | |
# source "prompt/oh-my-v2.nu" | |
# $env.PROMPT_COMMAND = { (get_prompt 24bit).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 24bit).right_prompt } | |
# experiment with panache-git | |
# source "prompt/panache-git.nu" | |
# $env.PROMPT_COMMAND = { panache-git } | |
# endregions | |
# external completions | |
use "custom-completions/cargo/cargo-completions.nu" * | |
# use "custom-completions/winget/winget-completions.nu" * | |
# git completions and aliases | |
use custom-completions/git/git-completions.nu * | |
use aliases/git/git-aliases.nu * | |
use custom-completions/gh/gh-completions.nu * | |
# temperature converter | |
use "sourced/temp.nu" * | |
# get_weather | |
use "modules/weather/get-weather.nu" get_weather | |
# zoxide | |
source ~/.zoxide.nu | |
# if LS_COLORS exists, hide it | |
if 'LS_COLORS' in ($env | columns) { | |
hide-env LS_COLORS | |
} | |
# make sure my PATH is unique | |
$env.PATH = ($env.PATH | each {|r| $r | split row (char esep)} | flatten | uniq | str join (char esep)) | |
# source /home/fdncred/.config/broot/launcher/nushell/br | |
# alias ls = eza -lhA --color=always --group-directories-first --color-scale-mode=gradient --grid --icons --git --git-repos --color-scale all --no-user --no-permissions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check for env var exists | |
# "FOO" | env exists? | |
def "env exists" [] { | |
# each {|s| $s in (env).name } | |
$in in $env | |
} | |
# Xterm Xterm | |
# Num Name HEX RGB HSL | |
# 0 Black (SYSTEM) #000000 rgb(0,0,0) hsl(0,0%,0%) | |
# 1 Maroon (SYSTEM) #800000 rgb(128,0,0) hsl(0,100%,25%) | |
# 2 Green (SYSTEM) #008000 rgb(0,128,0) hsl(120,100%,25%) | |
# 3 Olive (SYSTEM) #808000 rgb(128,128,0) hsl(60,100%,25%) | |
# 4 Navy (SYSTEM) #000080 rgb(0,0,128) hsl(240,100%,25%) | |
# 5 Purple (SYSTEM) #800080 rgb(128,0,128) hsl(300,100%,25%) | |
# 6 Teal (SYSTEM) #008080 rgb(0,128,128) hsl(180,100%,25%) | |
# 7 Silver (SYSTEM) #c0c0c0 rgb(192,192,192) hsl(0,0%,75%) | |
# 8 Grey (SYSTEM) #808080 rgb(128,128,128) hsl(0,0%,50%) | |
# 9 Red (SYSTEM) #ff0000 rgb(255,0,0) hsl(0,100%,50%) | |
# 10 Lime (SYSTEM) #00ff00 rgb(0,255,0) hsl(120,100%,50%) | |
# 11 Yellow (SYSTEM) #ffff00 rgb(255,255,0) hsl(60,100%,50%) | |
# 12 Blue (SYSTEM) #0000ff rgb(0,0,255) hsl(240,100%,50%) | |
# 13 Fuchsia (SYSTEM) #ff00ff rgb(255,0,255) hsl(300,100%,50%) | |
# 14 Aqua (SYSTEM) #00ffff rgb(0,255,255) hsl(180,100%,50%) | |
# 15 White (SYSTEM) #ffffff rgb(255,255,255) hsl(0,0%,100%) | |
let bn = (ansi { fg: '#ffffff' bg: '#000000' }) | |
let bb = (ansi { fg: '#ffffff' bg: '#555555' }) | |
let rn = (ansi { fg: '#ffffff' bg: '#AA0000' }) | |
let rb = (ansi { fg: '#ffffff' bg: '#FF5555' }) | |
let gn = (ansi { fg: '#000000' bg: '#00AA00' }) | |
let gb = (ansi { fg: '#000000' bg: '#55FF55' }) | |
let yn = (ansi { fg: '#000000' bg: '#AAAA00' }) | |
let yb = (ansi { fg: '#000000' bg: '#FFFF55' }) | |
let un = (ansi { fg: '#ffffff' bg: '#0000AA' }) | |
let ub = (ansi { fg: '#ffffff' bg: '#5555FF' }) | |
let mn = (ansi { fg: '#ffffff' bg: '#AA00AA' }) | |
let mb = (ansi { fg: '#ffffff' bg: '#FF55FF' }) | |
let cn = (ansi { fg: '#000000' bg: '#00AAAA' }) | |
let cb = (ansi { fg: '#000000' bg: '#55FFFF' }) | |
let wn = (ansi { fg: '#000000' bg: '#AAAAAA' }) | |
let wb = (ansi { fg: '#000000' bg: '#FFFFFF' }) | |
let s = 'XXXXXX' | |
let r = (ansi reset) | |
def standard-colors-rgb [] { | |
[ | |
[color normal bold]; | |
[Black $"($bn)($s)($r)" $"($bb)($s)($r)"] | |
[Red $"($rn)($s)($r)" $"($rb)($s)($r)"] | |
[Green $"($gn)($s)($r)" $"($gb)($s)($r)"] | |
[Yellow $"($yn)($s)($r)" $"($yb)($s)($r)"] | |
[Blue $"($un)($s)($r)" $"($ub)($s)($r)"] | |
[Magenta $"($mn)($s)($r)" $"($mb)($s)($r)"] | |
[Cyan $"($cn)($s)($r)" $"($cb)($s)($r)"] | |
[White $"($wn)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
def standard-colors-name [] { | |
[ | |
[color normal light]; | |
[Black $"(ansi black)ansi black 30" $"(ansi dark_gray)ansi dark_gray 90"] | |
[Red $"(ansi red)ansi red 31" $"(ansi light_red)ansi light_red 91"] | |
[Green $"(ansi green)ansi green 32" $"(ansi light_green)ansi light_green 92"] | |
[Yellow $"(ansi yellow)ansi yellow 33" $"(ansi light_yellow)ansi light_yellow 93"] | |
[Blue $"(ansi blue)ansi blue 34" $"(ansi light_blue)ansi light_blue 94"] | |
[Magenta $"(ansi magenta)ansi magenta 35" $"(ansi light_magenta)ansi light_magenta 95"] | |
[Purple $"(ansi purple)ansi purple 35" $"(ansi light_purple)ansi light_purple 95"] | |
[Cyan $"(ansi cyan)ansi cyan 36" $"(ansi light_cyan)ansi light_cyan 96"] | |
[White $"(ansi white)ansi white 37" $"(ansi light_gray)ansi light_gray 97"] | |
] | |
} | |
# https://www.ditig.com/256-colors-cheat-sheet | |
# 38;5;<num> for these palleted index numbers | |
# Xterm 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #800000 #008000 #808000 #000080 #800080 #008080 #C0C0C0 | |
# Xterm 8 9 10 11 12 13 14 15 | |
# Bold #808080 #FF0000 #00FF00 #FFFF00 #0000FF #FF00FF #00FFFF #FFFFFF | |
def wide-colors [] { | |
# Code 0 1 2 3 4 5 6 7 | |
# Name Black Red Green Yellow Blue Magenta Cyan White | |
# Normal #000000 #AA0000 #00AA00 #AAAA00 #0000AA #AA00AA #00AAAA #AAAAAA | |
# Bold #555555 #FF5555 #55FF55 #FFFF55 #5555FF #FF55FF #55FFFF #FFFFFF | |
# [code '0' '1' '2' '3' '4' '5' '6' '7']; | |
[ | |
[name black red green yellow blue magenta cyan white]; | |
[normal $"($bn)($s)($r)" $"($rn)($s)($r)" $"($gn)($s)($r)" $"($yn)($s)($r)" $"($un)($s)($r)" $"($mn)($s)($r)" $"($cn)($s)($r)" $"($wn)($s)($r)"] | |
[bold $"($bb)($s)($r)" $"($rb)($s)($r)" $"($gb)($s)($r)" $"($yb)($s)($r)" $"($ub)($s)($r)" $"($mb)($s)($r)" $"($cb)($s)($r)" $"($wb)($s)($r)"] | |
] | |
} | |
# get the terminal size with ansi escape codes | |
def terminal-size [] { | |
let sz = (input (ansi size) --bytes-until-any 'R' -s) | |
# $sz should look like this | |
# Length: 9 (0x9) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5b 33 38 3b 31 35 30 52 •[38;150R | |
let sz_len = ($sz | bytes length) | |
# let's skip the esc[ and R | |
let r = ($sz | bytes at 2..($sz_len - 2)) | |
# $r should look like 38;150 | |
let size = ($r | split row ';') | |
# output in record syntax | |
{ | |
rows: ($size | get 0) | |
columns: ($size | get 1) | |
} | |
} | |
# get background color with x11 ansi escapes | |
# have to hit ctrl+g after the statement to get the value in $x | |
# let x = input $"(ansi -o '11;?')(char bel)" --bytes-until (char bel) | |
# when input = rgb:4_numbers/4_numbers/4_numbers like rgb:1919/1313/2323 | |
# this means 16-bit rgb components. 16^4 means four hex digits. FFFF is 65535 | |
# 48-bit color. it could be 1 number 4-bits, 2 8-bits, 3 12-bits, 4 16-bits | |
# #3a7 is the same as #3000a0007000. | |
# refernce https://www.x.org/releases/X11R7.7/doc/man/man7/X.7.xhtml#heading11 | |
# mine was rgb:1919/1313/2323 | |
# (('1919' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# (('1313' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# (('2323' | into int -r 16) / 256 | math round | fmt).lowerhex | |
# or | |
# 0x1919 / 0x100 | math round | |
# 0x1313 / 0x100 | math round | |
# 0x2323 / 0x100 | math round | |
def get-bg [] { | |
# have to hit control+g in kitty to get value in $bg | |
let bg = (input $"(ansi -o '11;?')(ansi st)" --bytes-until-any '\' -s) | |
# $bg should look like this | |
# Length: 26 (0x1a) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 31 39 31 39 2f 31 33 •]11;rgb:1919/13 | |
# 00000010: 31 33 2f 32 33 32 33 1b 5c 07 13/2323•\• | |
# jt's output | |
# Length: 24 (0x18) bytes | printable whitespace ascii_other non_ascii | |
# 00000000: 1b 5d 31 31 3b 72 67 62 3a 33 66 33 66 2f 33 66 •]11;rgb:3f3f/3f | |
# 00000010: 33 66 2f 33 66 33 66 07 3f/3f3f• | |
# TODO figure how other ways that string can start so we can programmatically | |
# calculate the start_index better. It's probably not always \x1b]11;rgb: | |
let start_index = 9 | |
let end_index = ($bg | bytes index-of 0x[1b 5c]) | |
let term_data = ($bg | bytes at $start_index..$end_index) | |
let rgb_string = ($term_data | decode utf-8) | |
# Let's now get the rgb values by splitting on / | |
# 1919/1313/2323 | |
let rgb = ($rgb_string | split row '/') | |
let r = ($rgb | get 0) | |
let g = ($rgb | get 1) | |
let b = ($rgb | get 2) | |
# Let's get the hex values here. Note `fmt` requires --features=extra now | |
let red = (($r | into int -r 16) / 256 | math round | fmt).lowerhex | |
let green = (($g | into int -r 16) / 256 | math round | fmt).lowerhex | |
let blue = (($b | into int -r 16) / 256 | math round | fmt).lowerhex | |
# output in record syntax | |
{ | |
red: $red | |
green: $green | |
blue: $blue | |
hex: $"#($red | str substring 2..)($green | str substring 2..)($blue | str substring 2..)" | |
rgb: $"RGB(char lp)(($red | into int | fmt).display), (($green | into int | fmt).display), (($blue | into int | fmt).display)(char rp)" | |
} | |
} | |
# Clear the screen with ansi escapes | |
def cls [] { | |
ansi cls | |
} | |
# Full term reset, cls, clear buffer, attributes off, | |
def clsterm [] { | |
$"(ansi esc)c(ansi clsb)(ansi cls)(ansi reset)(ansi home)" | |
} | |
# good for things like this | |
# ps | where name =~ Firefox | get mem | sum | |
def sum [] { | |
reduce {|acc, item| $acc + $item } | |
} | |
# written by Kubouch for virtualenv | |
def is-string [ | |
x # value to check to see if it's a string | |
] { | |
($x | describe) == "string" | |
} | |
def has-env [name: string] { | |
$name in $env | |
} | |
# go to a folder like $nu.config-path | goto | |
def --env goto [] { | |
let input = $in | |
cd ( | |
if ($input | path type) == file { | |
($input | path dirname) | |
} else { | |
$input | |
} | |
) | |
} | |
# Run the cargo nextest tests for nushell | |
def cargo_tests [] { | |
cargo nextest run --all --features=dataframe | |
} | |
# Run the nushell cargo clippy lint | |
def cargo_clippy [] { | |
cargo clippy --workspace --all --features=dataframe -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect | |
} | |
# alias "core ls" = ls | |
# new ls sorted by type name -i | |
def ls2 [path?] { | |
if $path == null { | |
core ls . | sort-by type name -i | |
} else { | |
core ls $path | sort-by type name -i | |
} | |
} | |
# list all files with du and mime-type | |
def la [] { | |
core ls --all --du --mime-type | collect {|x| $x} | |
} | |
# def old-ls [path?] { | |
# if $path == null { | |
# ls . | sort-by type name -i | |
# } else { | |
# ls $path | sort-by type name -i | |
# } | |
# } | |
# ls sort type name -i | |
# def lss [path?] { | |
# if $path == null { | |
# old-ls . | |
# } else { | |
# old-ls $path | |
# } | |
# } | |
def --env cc [dir = ""] { | |
let cctemp = ['C:\Users\dschroeder\source\repos\forks', 'C:\'] | |
let default = 'C:\Users\dschroeder\source\repos\forks' | |
let complete_dir = (if $dir == "" { | |
$default | |
} else { | |
$cctemp | |
| reduce -f "" { |$it, $acc| if $acc == "" { | |
let new_path = ([$it $dir] | path join) | |
if ($new_path | path exists) { | |
$new_path | |
} else { | |
"" | |
} | |
} else { | |
$acc | |
} | |
} | |
}) | |
let complete_dir = if $complete_dir == "" { $default } else { $complete_dir } | |
$env.PWD = $complete_dir | |
} | |
# Get column # | |
def column [n] { transpose | select $n | transpose | select column1 | headers } | |
# How many stars does nushell have | |
def stars [] { | |
http get https://api.github.com/repos/nushell/nushell | get stargazers_count | |
} | |
# Hide all the prompt variables | |
def --env hide_prompt [] { | |
hide-env PROMPT_COMMAND | |
hide-env PROMPT_COMMAND_RIGHT | |
hide-env PROMPT_INDICATOR | |
} | |
# Easy way to get a short working directory | |
def pwd-short [] { | |
$env.PWD | str replace $nu.home-path '~' | |
} | |
def show [] { | |
let gitProxy = (if (git config --global --list | grep proxy | empty?) { 'Off' } else { 'On' }) | |
version | transpose | rename nu-ver value | |
print [ | |
[name, value]; | |
['Git Proxy', $gitProxy] | |
] | |
} | |
# another switch-like statement | |
let behaviors = [ | |
[condition, result]; | |
[{|x| ($x|describe) == string}, 'is a string '] | |
[{|x| ($x|str length) >= 6}, 'length is at least 6'] | |
[{|x| $x|str contains '.txt'}, 'contains .txt'] | |
] | |
def switch [ input: string ] { | |
$behaviors|where (do $it.condition $input)|get result | |
} | |
# Check how many downloads nushell has had | |
def nudown [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | | |
get assets | | |
flatten | | |
select name download_count created_at | | |
update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S'} | |
} | |
# Ye old start command | |
def start2 [path] { | |
if $nu.os-info.name == "windows" { | |
^start $path | |
} else if $nu.os-info.name == "macos" { | |
^open $path | |
} else { | |
xdg-open $path | |
} | |
} | |
# reject a column from a deeply nested json | |
def reject_deep [p: cell-path, f: cell-path] { | |
update $p { |x| $x | get $p | reject $f } | |
} | |
# convert input to hex | |
def "into hex" [] { | |
$in | fmt | get lowerhex | |
} | |
# convert input to octal | |
def "into octal" [] { | |
$in | fmt | get octal | |
} | |
def "nu-complete help categories" [] { | |
help commands | get category | uniq | |
} | |
def hc [cat?: string@"nu-complete help categories"] { | |
help commands | select name category usage | move usage --after name | where category == cat | |
} | |
# Move up $nb directories | |
def --env up [nb: int = 1] { | |
let path = (1..($nb) | each {|_| ".."} | reduce {|it, acc| $acc + "/" + $it}) | |
cd $path | |
} | |
# # make and cd to a folder | |
# def --env mkcd [name: path] { | |
# cd (mkdir $name -v | into string) | |
# } | |
# show a slightly different banner | |
def show_banner [] { | |
let ellie = [ | |
" __ ," | |
" .--()°'.'" | |
"'|, . ,' " | |
' !_-(_\ ' | |
] | |
let s = (sys) | |
print $"(ansi reset)(ansi green)($ellie.0)" | |
print $"(ansi green)($ellie.1) (ansi yellow) (ansi yellow_bold)Nushell (ansi reset)(ansi yellow)v(version | get version)(ansi reset)" | |
print $"(ansi green)($ellie.2) (ansi light_blue) (ansi light_blue_bold)RAM (ansi reset)(ansi light_blue)($s.mem.used) / ($s.mem.total)(ansi reset)" | |
print $"(ansi green)($ellie.3) (ansi light_purple)ﮫ (ansi light_purple_bold)Uptime (ansi reset)(ansi light_purple)($s.host.uptime)(ansi reset)" | |
} | |
# Returns a filtered table that has distinct values in the specified column | |
def uniq-by2 [ | |
column: string # The column to scan for duplicate values | |
] { | |
reduce { |item, acc| | |
if ($acc | any { |storedItem| | |
($storedItem | get $column) == ($item | get $column) | |
}) { | |
$acc | |
} else { | |
$acc | append $item | |
} | |
} | |
} | |
# how to use uniq-by | |
# let people = [ | |
# {name: 'A', email: '[email protected]'}, | |
# {name: 'a', email: '[email protected]'}, | |
# {name: 'b', email: '[email protected]'} | |
# ] | |
# $people | uniq-by email | |
# Get values from simple key-value object | |
def get-values [] { | |
let subject = $in | |
let keys = ($subject | columns) | |
$keys | each {|it| $subject | get $it } | |
} | |
# Get an abbreviated path | |
def spwd [] { | |
let home = (if ($nu.os-info.name == windows) { $env.USERPROFILE } else { $env.HOME }) | |
let sep = (if ($nu.os-info.name == windows) { "\\" } else { "/" }) | |
let spwd_paths = ( | |
$"!/($env.PWD)" | | |
str replace $"!/($home)" ~ | | |
split row $sep | |
) | |
# Darren's hack to make all slashes point to the right | |
let sep = '/' | |
# end hack | |
let spwd_len = (($spwd_paths | length) - 1) | |
for -n i in $spwd_paths { | |
let spwd_src = ($i.item | split chars) | |
if ($i.index == $spwd_len) { | |
print -n $i.item | |
} else if ($spwd_src.0 == ".") { | |
print -n $".($spwd_src.1)($sep)" | |
} else { | |
print -n $"($spwd_src.0)($sep)" | |
} | |
} | |
} | |
def get-monday [] { | |
(seq date -r --days 7 | | |
into datetime | | |
where { |e| | |
($e | format date %u) == "1" }).0 | | |
format date "%Y-%m-%d" | |
} | |
# Delete all branches that are not in the excepts list | |
# Usage: del-branches [main] | |
def del-branches [ | |
excepts:list # don't delete branch in the list | |
--dry-run(-d) # do a dry-run | |
] { | |
let branches = (git branch | lines | str trim) | |
let remote_branches = (git branch -r | lines | str replace -r '^.+?/' '' | uniq) | |
if $dry_run { | |
print "Starting Dry-Run" | |
} else { | |
print "Deleting for real" | |
} | |
$branches | each {|it| | |
if ($it not-in $excepts) and ($it not-in $remote_branches) and (not ($it | str starts-with "*")) { | |
# git branch -D $it | |
if $dry_run { | |
print $"git branch -D ($it)" | |
} else { | |
print $"Deleting ($it) for real" | |
#git branch -D $it | |
} | |
} | |
} | |
} | |
# Avoid duplicating values in a list | |
# Example | |
# $env.PATH = ( | |
# $env.PATH | split row (char esep) | |
# | prepend-if-not-in ($env.HOME | path join ".local" "bin") | |
# | prepend-if-not-in ($env.EMACS_HOME | path join "bin") | |
# | prepend-if-not-in ($env.CARGO_HOME | path join "bin") | |
# | prepend-if-not-in ($env.XDG_DATA_HOME | path join "clang-15" "bin") | |
# | prepend-if-not-in ($env.XDG_DATA_HOME | path join "gem" "ruby" $env.GEM_VERSION "bin") | |
# ) | |
def prepend-if-not-in [ | |
value: string | |
] { | |
let list = $in | |
$list | if ($value in $list) {$in} else {$in | prepend $value} | |
} | |
def inspect2 [ | |
callback?: closure | |
] { | |
# Examples: | |
# 123 | inspect | echo ($in * 2) | |
# 123 | inspect { |num| print $"num is ($num)" } | echo ($in * 2) | |
let input = $in | |
if $callback == null { | |
print $input | |
} else { | |
do $callback $input | |
} | |
$input | |
} | |
# def pwd [] { $env.PWD } | |
# def stefans_meeting_pr_list [] { | |
# gh pr list --json url,number,author,title,labels,isDraft | | |
# from json | | |
# each {|i| | |
# [$"- [($i.number)]\(($i.url)\) ($i.title) \(@($i.author.login)\)", | |
# ($i.labels | | |
# each {|l| | |
# $l | | |
# get name | | |
# $" - ($in)" | |
# }), | |
# (if $i.isDraft {" - Currently marked as draft"}) | |
# ] | | |
# each while { $in } | | |
# flatten | | |
# to text | |
# } | | |
# reverse | | |
# to text | |
# } | |
# Show the statistics of the sqlite history database | |
def "history stats" [ | |
--summary (-s): int = 10 | |
--last-cmds (-l): int | |
] { | |
let top_commands = ( | |
history | |
| if ($last_cmds != null) { last $last_cmds } else { $in } | |
| get command | |
| split column ' ' command | |
| uniq -c | |
| flatten | |
| sort-by --reverse count | |
| first $summary | |
) | |
let total_cmds = (history | length) | |
let unique_cmds = (history | get command | uniq | length) | |
print $"(ansi green)Top ($top_commands | length)(ansi reset) most used commands:" | |
print $top_commands | |
print $"(ansi green)Total commands in history:(ansi reset) ($total_cmds)" | |
print $"(ansi green)Unique commands:(ansi reset) ($unique_cmds)" | |
} | |
def "history search" [ | |
str: string = '' # search string | |
--cwd(-c) # Filter search result by directory | |
--exit(-e): int = 0 # Filter search result by exit code | |
--before(-b): datetime = 2100-01-01 # Only include results added before this date | |
--after(-a): datetime = 1970-01-01 # Only include results after this date | |
--limit(-l): int = 25 # How many entries to return at most | |
] { | |
if $cwd == false { | |
history | |
| where start_timestamp != "" | |
| update start_timestamp {|r| $r.start_timestamp | into datetime} | |
| where command =~ $str and exit_status == $exit and start_timestamp > $after and start_timestamp < $before | |
| first $limit | |
} else { | |
history | |
| where start_timestamp != "" | |
| update start_timestamp {|r| $r.start_timestamp | into datetime} | |
| where command =~ $str and cwd == $env.PWD and exit_status == $exit and start_timestamp > $after and start_timestamp < $before | |
| first $limit | |
} | |
} | |
# Show the items in list1 that are also in list2 | |
def sorted_list_intersect [xs1: list, xs2: list] { | |
let len1 = ($xs1 | length) | |
let len2 = ($xs2 | length) | |
mut i = 0 | |
mut j = 0 | |
while ($i < $len1 and $j < $len2) { | |
if ($xs1 | get $i) < ($xs2 | get $j) { | |
$i = $i + 1 | |
} else if ($xs2 | get $j) < ($xs1 | get $i) { | |
$j = $j + 1 | |
} else { | |
echo ($xs2 | get $j) | |
$i = $i + 1 | |
$j = $j + 1 | |
} | |
} | |
} | |
# Show information about the crates that are installed via cargo | |
def "cargo list" [] { | |
cargo install --list | |
| lines | |
| str replace -r '^(\w)' "\n${1}" | |
| str join | |
| lines | skip 1 | |
| parse --regex '(?<pkg>.*) v(?<version>\d+\.\d+\.\d+)(?<path>.*):(?<bins>.*)' | |
| str trim | |
| update bins {|it| $it.bins | str replace -r '\s+' ' ' | split row ' '} | |
| update path {|it| $it.path | str replace '(' '' | str replace ')' ''} | |
| update bins {|r| $r.bins | str join (char nl)} | |
} | |
# create a nanosecond duration from a number piped in | |
def "from ns" [] { | |
[$in "ns"] | str join | into duration | |
} | |
# Benchmark a closure | |
def time_closure [ | |
code: closure | |
-n: int = 50 | |
--verbose (-v) | |
] { | |
let times = ( | |
seq 1 $n | |
| each {|i| | |
if $verbose { print -n $"($i) / ($n)\r" } | |
timeit {|| do $code } | into int | into float | |
} | |
) | |
{ | |
mean: ($times | math avg | from ns) | |
std: ($times | math stddev | from ns) | |
data: ($times | each {|| from ns }) | |
} | |
} | |
# >_ benchmark { $nu.scope } -n 5 | table --expand | |
# ╭──────┬──────────────────────────╮ | |
# │ mean │ 21ms 751µs 951ns │ | |
# │ std │ 13ms 148µs 288ns │ | |
# │ │ ╭───┬──────────────────╮ │ | |
# │ data │ │ 0 │ 46ms 538µs 992ns │ │ | |
# │ │ │ 1 │ 23ms 997µs 830ns │ │ | |
# │ │ │ 2 │ 13ms 690µs 461ns │ │ | |
# │ │ │ 3 │ 12ms 286µs 892ns │ │ | |
# │ │ │ 4 │ 12ms 245µs 580ns │ │ | |
# │ │ ╰───┴──────────────────╯ │ | |
# ╰──────┴──────────────────────────╯ | |
# Check how many downloads nushell has had | |
def get_github_downloads [] { | |
http get https://api.github.com/repos/nushell/nushell/releases | | |
get assets | | |
flatten | | |
select name download_count created_at | | |
update created_at {|r| $r.created_at | into datetime | format date '%m/%d/%Y %H:%M:%S'} | |
} | |
# Get brew downloads for the past 30 days | |
def get_brew_downloads [] { | |
let brew_dl = (http get https://formulae.brew.sh/api/formula/nushell.json) | |
let macos_dl = ($brew_dl | get analytics.install.30d.nushell) | |
let linux_dl = ($brew_dl | get analytics-linux.install.30d.nushell) | |
[[os downloads]; [macos $macos_dl] [linux $linux_dl]] | |
} | |
# Get cargo downloads for crate | |
def "get_cargo_downloads" [ crate: string ] { | |
# alternatively scrape this | |
# http get https://crates.io/api/v1/crates/nu | |
# http get https://crates.io/api/v1/crates/nu/0.76.0 | get version | |
cargo info $crate | |
| lines | |
| parse "{key}: {value}" | |
| str trim | |
| transpose -r | |
| into record | |
| merge ({ | |
versions: ( | |
cargo info $crate -VV | |
| lines -s | |
| skip 1 | |
| parse --regex '(?<version>\d+\.\d+\.\d+)\s+(?<released>.* ago)\s+(?<downloads>\d+)' | |
| into int downloads | |
) | |
}) | |
} | |
def get_all_nu_downloads [version = "0.76.0"] { | |
let github_dl = (get_github_downloads | where name =~ $version | get download_count | math sum) | |
let brew_dl = (get_brew_downloads | get downloads | math sum) | |
let cargo_dl = (get_cargo_downloads nu | get versions | where version =~ $version | get downloads.0) | |
[[source downloads]; [github $github_dl] [brew $brew_dl] [cargo $cargo_dl] [sum ($github_dl + $brew_dl + $cargo_dl)]] | |
} | |
def helps [] { | |
help commands | | |
get name | | |
str join "\n" | | |
fzf --preview-window 'up,60%,border-bottom,+{2}+3/3,~1' --preview $"nu --config '($nu.config-path)' --env-config '($nu.env-path)' -c 'help {1} {2} {3} {4} {5}'" | |
# help commands | |
# | get name | |
# | str join "\n" | |
# | fzf --preview $"nu --config ($nu.config-path) --env-config ($nu.env-path) -c 'help {}'" | |
} | |
# get the environment details | |
def "env details" [] { | |
let e = ($env | reject config | transpose key value) | |
$e | each { |r| | |
let is_envc = ($r.key == ENV_CONVERSIONS) | |
let is_closure = ($r.value | describe | str contains 'closure') | |
let is_list = ($r.value | describe | str contains 'list') | |
if $is_envc { | |
echo [[key value]; | |
[($r.key) ($r.value | transpose key value | each { |ec| | |
let to_string = ($ec.value | get to_string | view source $in | nu-highlight) | |
let from_string = ($ec.value | get from_string | view source $in | nu-highlight) | |
echo ({'ENV_CONVERSIONS': {($ec.key): { 'to_string': ($to_string) 'from_string': ($from_string)}}}) | |
})] | |
] | |
} else if $is_closure { | |
let closure_value = (view source ($env | get $r.key) | nu-highlight) | |
echo [[key value]; [($r.key) ($closure_value)]] | |
} else if $is_list { | |
let list_value = ($env | get $r.key | split row (char esep)) | |
echo [[key value]; [($r.key) ($list_value)]] | |
} else { | |
echo [[key value]; [($r.key) ($r.value)]] | |
} | |
} | |
} | |
def env [] { env details | flatten | table -e } | |
# Get the type of a value | |
def get-type [value] { | |
$value | describe | |
} | |
# Check if a value is of a certain type | |
def is-type [type] { | |
($in | describe) == $type | |
} | |
# brew upgrade everything | |
def brewup [] { | |
print $"(ansi { fg: white bg: blue attr: n }) ============== MAINTAIN BREW =============== (ansi reset)" | |
print $"(ansi purple)Updating brew...(ansi reset)" | |
brew update | |
print $"(ansi purple)Upgrading brew...(ansi reset)" | |
brew upgrade | |
print $"(ansi purple)Cleaning up brew (char lp)keep only last(char rp)...(ansi reset)" | |
brew cleanup -s | |
print $"(ansi purple)Calling the DOCTOR! What is missing?...(ansi reset)" | |
brew doctor | |
brew missing | |
print $"(ansi purple)Updating brew casks and cleaning up...(ansi reset)" | |
brew cu --all --yes --cleanup | |
print $"(ansi { fg: white bg: blue attr: n }) ============ MAINTAIN COMPLETE ============= (ansi reset)" | |
} | |
## lazy demo | |
def "lazy make record" [ | |
record: record | |
] { | |
let columns = ($record | columns) | |
lazy make --columns $columns --get-value { |col| do ($record | get $col) } | |
} | |
def "breed person" [name: string = "john doe", birthyear: int = 1987, status: string = "maidenless"] { | |
# static props | |
let inner = { | |
callsign: ($name | split words | each { split chars | first } | str join | str upcase) | |
} | |
# ... methods (?) | |
let age = { (date now | format date "%Y" | into int) - $birthyear } | |
# public interface/getters | |
lazy make record { | |
age: $age, | |
presentation: { $"hi, I'm ($name), (do $age) years old and currently ($status)" }, | |
callsign: { $inner.callsign } | |
} | |
} | |
# Only list the nushell environment variables | |
def env-nu [] { | |
$env | | |
transpose key value | | |
each {|r| | |
if ($r.value | describe) != string { | |
$r | |
} | |
} | transpose -ird | |
} | |
# build and install nushell alone | |
def tkb [] { | |
print $"(ansi light_green)Building and installing nushell(ansi reset)" | |
print $"(ansi yellow)Touch crates/nu-cmd-lang/build.rs(ansi reset)" | |
touch crates/nu-cmd-lang/build.rs | |
print $"(ansi yellow)Installing nushell with extra,datatframe,mimalloc(ansi reset)" | |
use /home/fdncred/src/nushell/toolkit.nu | |
toolkit install extra dataframe mimalloc | |
} | |
# build and install nushell with all plugins and then regsiter | |
def tkba [] { | |
print $"(ansi light_green)Building and installing nushell WITH plugins(ansi reset)" | |
print $"(ansi yellow)Touch crates/nu-cmd-lang/build.rs(ansi reset)" | |
touch crates/nu-cmd-app/build.rs | |
print $"(ansi yellow)Installing nushell with extra,dataframe,mimalloc WITH plugins(ansi reset)" | |
use /home/fdncred/src/nushell/toolkit.nu | |
toolkit install --all extra dataframe mimalloc | |
print $"(ansi yellow)Registering nushell plugins(ansi reset)" | |
toolkit add plugins | |
} | |
# Show a summarized table of nushell startup times | |
def startup-stats [] { | |
open ~/.local/share/nushell/startup-times.nuon | | |
where build == release | | |
group-by commit | | |
transpose commit data | | |
upsert perf {|r| | |
if ($r.data | length) > 3 { | |
$r.data.time | sort | range 0..(-3) | math avg | |
} else { | |
$r.data.time | math avg | |
} | |
} | | |
upsert start_date {|s| | |
$s.data.date | sort | math min | format date '%Y-%m-%d' | |
} | | |
upsert end_date {|e| | |
$e.data.date | sort | math max | format date '%Y-%m-%d' | |
} | | |
upsert num_startups {|n| | |
$n.data | length | |
} | sort-by start_date | |
} | |
# Translate text using Google Translate | |
def tl [ | |
--source: string = "auto", # The source language | |
--dest: string = "fr", # The destination language | |
text: string, # The text to translate | |
] { | |
{ | |
scheme: "https", | |
host: "translate.googleapis.com", | |
path: "/translate_a/single", | |
params: { | |
client: gtx, | |
sl: $source, | |
tl: $dest, | |
dt: t, | |
q: ($text | url encode), | |
} | |
} | |
| url join | |
| http get $in | |
| get 0.0.0 | |
} | |
# ls grid that shows git status modified with a red * | |
def "l" [] { | |
let modified = ( ^git status o+e>| lines | find modified | |
| parse "{x}:{modified}" | |
| reject x | |
| str trim | |
| get modified) | |
ls | |
| upsert m {|f| if $f.name in $modified {$"(ansi red)*(ansi reset)"}} | |
| rename --column {name: fname} | |
| upsert name {|f| $"($f.fname)($f.m)"} | |
| grid -c | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nushell Environment Config File | |
# use cargo's sparse protocol (after 1.68.0) | |
$env.CARGO_REGISTRIES_CRATES_IO_PROTOCOL = 'sparse' | |
# nushell is automatically appended | |
# $env.XDG_CONFIG_HOME = '/home/fdncred/.config' | |
$env.GIT_REPOS_HOME = '/home/fdncred/src' | |
# Some environment variables | |
# $env.GITHUB_USERNAME = "fdncred" | |
# $env.GITHUB_PASSWORD = "12345" | |
$env.LESS = "-FRXS" | |
$env.PAGER = "less" | |
$env.PATH = ($env.PATH | | |
split row (char esep) | | |
append '/mnt/c/Users/20396600/AppData/Local/Programs/Microsoft VS Code/bin' | | |
append '/mnt/c/Users/20396600/AppData/Local/Programs/Microsoft VS Code Insiders/bin' | | |
prepend /home/fdncred/.cargo/bin | | |
prepend /usr/local/bin | | |
prepend /home/fdncred/.local/bin | |
) | |
$env.MANPATH = "/usr/share/man:/usr/local/share/man" | |
$env.MANPAGER = "sh -c 'col -bx | bat -l man -p'" | |
$env.EDITOR = "hx" | |
# Use nushell functions to define your right and left prompt | |
# note - i put this in my config.nu so i could utilize the NU_LIB_DIRS env var | |
# use "c:\Users\20396600\source\repos\forks\nu_scripts\prompt\oh-my.nu" git_prompt | |
# $env.PROMPT_COMMAND = { (git_prompt).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (git_prompt).right_prompt } | |
# The prompt indicators are environmental variables that represent | |
# the state of the prompt | |
$env.PROMPT_INDICATOR = {|| " " } | |
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " } | |
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = $"(ansi -e { fg: '#66cdaa'})(char -u 276f)(ansi -e { fg: '#76eec6'})(char -u 276f)(ansi -e { fg: '#7fffd4'})(char -u 276f)(ansi reset)(char space)" | |
$env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e { fg: '#CB4B16'})(char -u '276f')(ansi -e { fg: '#CACA02'})(char -u '276f')(ansi -e { fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" } | |
# use "c:\Users\20396600\source\repos\forks\nu_scripts\prompt\oh-my-minimal.nu" get_prompt | |
# $env.PROMPT_COMMAND = { (get_prompt 1).left_prompt } | |
# $env.PROMPT_COMMAND_RIGHT = { (get_prompt 1).right_prompt } | |
# $env.PROMPT_INDICATOR = { " " } | |
# $env.PROMPT_INDICATOR = { "〉" } | |
# $env.PROMPT_INDICATOR_VI_INSERT = { ": " } | |
# $env.PROMPT_INDICATOR_VI_NORMAL = { "〉" } | |
# $env.PROMPT_MULTILINE_INDICATOR = { "::: " } | |
# $env.PROMPT_INDICATOR_HISTORY = { "? " } | |
# note - the string color will affect ls_colors | |
# if you make it wd, all colors for strings will | |
# be dimmed | |
# base16 | |
# https://github.com/Kirill-Bugaev/awesome-base16/blob/master/base16/apps/default_dark/dircolors | |
# $env.LS_COLORS = "no=00;37:fi=01;34:rs=00;37:di=00;34:ln=00;36:mh=00;37:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=00;05;37;41:mi=00;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=04;34:st=37;44:ex=00;32:*.cmd=00;33:*.exe=00;33:*.com=00;33:*.btm=00;33:*.bat=00;33:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz=01;31:*.bz2=01;31:*.bzip2=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.apk=01;31:*.gem=01;31:*.jpg=00;35:*.JPG=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.svg=00;35:*.svgz=00;35:*.mng=00;35:*.pcx=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.yuv=00;35:*.cgm=00;35:*.emf=00;35:*.eps=00;35:*.CR2=00;35:*.ico=00;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.html=00;32:*.css=00;32:*.rst=00;32:*.md=00;32:*.patch=00;32:*.diff=00;32:*.tex=00;32:*.xls=00;32:*.xlsx=00;32:*.doc=00;32:*.docx=00;32:*.ppt=00;32:*.pptx=00;32:*.key=00;32:*.ods=00;32:*.odt=00;32:*.pt=01;32:*.tmpl=01;32:*.in=01;32:*.ots=01;32:*.ott=01;32:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.m4a=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:*.mov=01;36:*.mpg=01;36:*.mpeg=01;36:*.m2v=01;36:*.mkv=01;36:*.ogm=01;36:*.mp4=01;36:*.m4v=01;36:*.mp4v=01;36:*.vob=01;36:*.qt=01;36:*.nuv=01;36:*.wmv=01;36:*.asf=01;36:*.rm=01;36:*.rmvb=01;36:*.flc=01;36:*.avi=01;36:*.fli=01;36:*.flv=01;36:*.gl=01;36:*.m2ts=01;36:*.divx=01;36:*.webm=01;36:*.axv=01;36:*.anx=01;36:*.ogv=01;36:*.ogx=01;36:*.conf=00;36:*.config=00;36:*.cnf=00;36:*.cfg=00;36:*.ini=00;36:*.properties=00;36:*.yaml=00;36:*.vcl=00;36:*.c=00;33:*.cpp=00;33:*.py=00;33:*.coffesscript=00;33:*.js=00;33:*.rb=00;33:*.sh=00;33:*.zsh=00;33:*.env=00;33:*.bash=00;33:*.php=00;33:*.java=00;33:*.zcml=00;33:*.pl=00;33:*.lua=00;33:*.clj=00;33:*.cs=00;33:*.fs=00;33:*.fsx=00;33:*.go=00;33:*.db=00;32:*.sql=00;32:*.json=00;32:*.plist=00;32:*.xml=00;32:*.tex=01;37:*.rdf=01;37:*.owl=01;37:*.n3=01;37:*.ttl=01;37:*.nt=01;37:*.torrent=01;37:*.xml=01;37:*Makefile=01;37:*makefile=01;37:*Rakefile=01;37:*build.xml=01;37:*rc=01;37:*.nfo=01;37:*README=01;37:*README.txt=01;37:*readme.txt=01;37:*README.markdown=01;37:*README.md=01;37:*.cc=01;37:*.log=01;30:*.bak=01;30:*.aux=01;30:*.lof=01;30:*.lol=01;30:*.lot=01;30:*.out=01;30:*.toc=01;30:*.bbl=01;30:*.blg=01;30:*~=01;30:*#=01;30:*.part=01;30:*.incomplete=01;30:*.swp=01;30:*.tmp=01;30:*.temp=01;30:*.o=01;30:*.obj=01;30:*.pyc=01;30:*.pyo=01;30:*.class=01;30:*.cache=01;30:*.egg-info=01;30:" | |
# 24-bit colors | |
# $env.LS_COLORS = (vivid generate molokai | str trim) | |
# 8-bit colors | |
# $env.LS_COLORS = "st=0:di=0;38;5;81:so=0;38;5;16;48;5;203:ln=0;38;5;203:cd=0;38;5;203;48;5;236:ex=1;38;5;203:or=0;38;5;16;48;5;203:fi=0:bd=0;38;5;81;48;5;236:ow=0:mi=0;38;5;16;48;5;203:*~=0;38;5;243:no=0:tw=0:pi=0;38;5;16;48;5;81:*.z=4;38;5;203:*.t=0;38;5;48:*.o=0;38;5;243:*.d=0;38;5;48:*.a=1;38;5;203:*.c=0;38;5;48:*.m=0;38;5;48:*.p=0;38;5;48:*.r=0;38;5;48:*.h=0;38;5;48:*.ml=0;38;5;48:*.ll=0;38;5;48:*.gv=0;38;5;48:*.cp=0;38;5;48:*.xz=4;38;5;203:*.hs=0;38;5;48:*css=0;38;5;48:*.ui=0;38;5;149:*.pl=0;38;5;48:*.ts=0;38;5;48:*.gz=4;38;5;203:*.so=1;38;5;203:*.cr=0;38;5;48:*.fs=0;38;5;48:*.bz=4;38;5;203:*.ko=1;38;5;203:*.as=0;38;5;48:*.sh=0;38;5;48:*.pp=0;38;5;48:*.el=0;38;5;48:*.py=0;38;5;48:*.lo=0;38;5;243:*.bc=0;38;5;243:*.cc=0;38;5;48:*.pm=0;38;5;48:*.rs=0;38;5;48:*.di=0;38;5;48:*.jl=0;38;5;48:*.rb=0;38;5;48:*.md=0;38;5;185:*.js=0;38;5;48:*.go=0;38;5;48:*.vb=0;38;5;48:*.hi=0;38;5;243:*.kt=0;38;5;48:*.hh=0;38;5;48:*.cs=0;38;5;48:*.mn=0;38;5;48:*.nb=0;38;5;48:*.7z=4;38;5;203:*.ex=0;38;5;48:*.rm=0;38;5;208:*.ps=0;38;5;186:*.td=0;38;5;48:*.la=0;38;5;243:*.aux=0;38;5;243:*.xmp=0;38;5;149:*.mp4=0;38;5;208:*.rpm=4;38;5;203:*.m4a=0;38;5;208:*.zip=4;38;5;203:*.dll=1;38;5;203:*.bcf=0;38;5;243:*.awk=0;38;5;48:*.aif=0;38;5;208:*.zst=4;38;5;203:*.bak=0;38;5;243:*.tgz=4;38;5;203:*.com=1;38;5;203:*.clj=0;38;5;48:*.sxw=0;38;5;186:*.vob=0;38;5;208:*.fsx=0;38;5;48:*.doc=0;38;5;186:*.mkv=0;38;5;208:*.tbz=4;38;5;203:*.ogg=0;38;5;208:*.wma=0;38;5;208:*.mid=0;38;5;208:*.kex=0;38;5;186:*.out=0;38;5;243:*.ltx=0;38;5;48:*.sql=0;38;5;48:*.ppt=0;38;5;186:*.tex=0;38;5;48:*.odp=0;38;5;186:*.log=0;38;5;243:*.arj=4;38;5;203:*.ipp=0;38;5;48:*.sbt=0;38;5;48:*.jpg=0;38;5;208:*.yml=0;38;5;149:*.txt=0;38;5;185:*.csv=0;38;5;185:*.dox=0;38;5;149:*.pro=0;38;5;149:*.bst=0;38;5;149:*TODO=1:*.mir=0;38;5;48:*.bat=1;38;5;203:*.m4v=0;38;5;208:*.pod=0;38;5;48:*.cfg=0;38;5;149:*.pas=0;38;5;48:*.tml=0;38;5;149:*.bib=0;38;5;149:*.ini=0;38;5;149:*.apk=4;38;5;203:*.h++=0;38;5;48:*.pyc=0;38;5;243:*.img=4;38;5;203:*.rst=0;38;5;185:*.swf=0;38;5;208:*.htm=0;38;5;185:*.ttf=0;38;5;208:*.elm=0;38;5;48:*hgrc=0;38;5;149:*.bmp=0;38;5;208:*.fsi=0;38;5;48:*.pgm=0;38;5;208:*.dpr=0;38;5;48:*.xls=0;38;5;186:*.tcl=0;38;5;48:*.mli=0;38;5;48:*.ppm=0;38;5;208:*.bbl=0;38;5;243:*.lua=0;38;5;48:*.asa=0;38;5;48:*.pbm=0;38;5;208:*.avi=0;38;5;208:*.def=0;38;5;48:*.mov=0;38;5;208:*.hxx=0;38;5;48:*.tif=0;38;5;208:*.fon=0;38;5;208:*.zsh=0;38;5;48:*.png=0;38;5;208:*.inc=0;38;5;48:*.jar=4;38;5;203:*.swp=0;38;5;243:*.pid=0;38;5;243:*.gif=0;38;5;208:*.ind=0;38;5;243:*.erl=0;38;5;48:*.ilg=0;38;5;243:*.eps=0;38;5;208:*.tsx=0;38;5;48:*.git=0;38;5;243:*.inl=0;38;5;48:*.rtf=0;38;5;186:*.hpp=0;38;5;48:*.kts=0;38;5;48:*.deb=4;38;5;203:*.svg=0;38;5;208:*.pps=0;38;5;186:*.ps1=0;38;5;48:*.c++=0;38;5;48:*.cpp=0;38;5;48:*.bsh=0;38;5;48:*.php=0;38;5;48:*.exs=0;38;5;48:*.toc=0;38;5;243:*.mp3=0;38;5;208:*.epp=0;38;5;48:*.rar=4;38;5;203:*.wav=0;38;5;208:*.xlr=0;38;5;186:*.tmp=0;38;5;243:*.cxx=0;38;5;48:*.iso=4;38;5;203:*.dmg=4;38;5;203:*.gvy=0;38;5;48:*.bin=4;38;5;203:*.wmv=0;38;5;208:*.blg=0;38;5;243:*.ods=0;38;5;186:*.psd=0;38;5;208:*.mpg=0;38;5;208:*.dot=0;38;5;48:*.cgi=0;38;5;48:*.xml=0;38;5;185:*.htc=0;38;5;48:*.ics=0;38;5;186:*.bz2=4;38;5;203:*.tar=4;38;5;203:*.csx=0;38;5;48:*.ico=0;38;5;208:*.sxi=0;38;5;186:*.nix=0;38;5;149:*.pkg=4;38;5;203:*.bag=4;38;5;203:*.fnt=0;38;5;208:*.idx=0;38;5;243:*.xcf=0;38;5;208:*.exe=1;38;5;203:*.flv=0;38;5;208:*.fls=0;38;5;243:*.otf=0;38;5;208:*.vcd=4;38;5;203:*.vim=0;38;5;48:*.sty=0;38;5;243:*.pdf=0;38;5;186:*.odt=0;38;5;186:*.purs=0;38;5;48:*.h264=0;38;5;208:*.jpeg=0;38;5;208:*.dart=0;38;5;48:*.pptx=0;38;5;186:*.lock=0;38;5;243:*.bash=0;38;5;48:*.rlib=0;38;5;243:*.hgrc=0;38;5;149:*.psm1=0;38;5;48:*.toml=0;38;5;149:*.tbz2=4;38;5;203:*.yaml=0;38;5;149:*.make=0;38;5;149:*.orig=0;38;5;243:*.html=0;38;5;185:*.fish=0;38;5;48:*.diff=0;38;5;48:*.xlsx=0;38;5;186:*.docx=0;38;5;186:*.json=0;38;5;149:*.psd1=0;38;5;48:*.tiff=0;38;5;208:*.flac=0;38;5;208:*.java=0;38;5;48:*.less=0;38;5;48:*.mpeg=0;38;5;208:*.conf=0;38;5;149:*.lisp=0;38;5;48:*.epub=0;38;5;186:*.cabal=0;38;5;48:*.patch=0;38;5;48:*.shtml=0;38;5;185:*.class=0;38;5;243:*.xhtml=0;38;5;185:*.mdown=0;38;5;185:*.dyn_o=0;38;5;243:*.cache=0;38;5;243:*.swift=0;38;5;48:*README=0;38;5;16;48;5;186:*passwd=0;38;5;149:*.ipynb=0;38;5;48:*shadow=0;38;5;149:*.toast=4;38;5;203:*.cmake=0;38;5;149:*.scala=0;38;5;48:*.dyn_hi=0;38;5;243:*.matlab=0;38;5;48:*.config=0;38;5;149:*.gradle=0;38;5;48:*.groovy=0;38;5;48:*.ignore=0;38;5;149:*LICENSE=0;38;5;249:*TODO.md=1:*COPYING=0;38;5;249:*.flake8=0;38;5;149:*INSTALL=0;38;5;16;48;5;186:*setup.py=0;38;5;149:*.gemspec=0;38;5;149:*.desktop=0;38;5;149:*Makefile=0;38;5;149:*Doxyfile=0;38;5;149:*TODO.txt=1:*README.md=0;38;5;16;48;5;186:*.kdevelop=0;38;5;149:*.rgignore=0;38;5;149:*configure=0;38;5;149:*.DS_Store=0;38;5;243:*.fdignore=0;38;5;149:*COPYRIGHT=0;38;5;249:*.markdown=0;38;5;185:*.cmake.in=0;38;5;149:*.gitconfig=0;38;5;149:*INSTALL.md=0;38;5;16;48;5;186:*CODEOWNERS=0;38;5;149:*.gitignore=0;38;5;149:*Dockerfile=0;38;5;149:*SConstruct=0;38;5;149:*.scons_opt=0;38;5;243:*README.txt=0;38;5;16;48;5;186:*SConscript=0;38;5;149:*.localized=0;38;5;243:*.travis.yml=0;38;5;186:*Makefile.in=0;38;5;243:*.gitmodules=0;38;5;149:*LICENSE-MIT=0;38;5;249:*Makefile.am=0;38;5;149:*INSTALL.txt=0;38;5;16;48;5;186:*MANIFEST.in=0;38;5;149:*.synctex.gz=0;38;5;243:*.fdb_latexmk=0;38;5;243:*CONTRIBUTORS=0;38;5;16;48;5;186:*configure.ac=0;38;5;149:*.applescript=0;38;5;48:*appveyor.yml=0;38;5;186:*.clang-format=0;38;5;149:*.gitattributes=0;38;5;149:*LICENSE-APACHE=0;38;5;249:*CMakeCache.txt=0;38;5;243:*CMakeLists.txt=0;38;5;149:*CONTRIBUTORS.md=0;38;5;16;48;5;186:*requirements.txt=0;38;5;149:*CONTRIBUTORS.txt=0;38;5;16;48;5;186:*.sconsign.dblite=0;38;5;243:*package-lock.json=0;38;5;243:*.CFUserTextEncoding=0;38;5;243" | |
# other vivid themes | |
# ayu, iceberg-dark, jellybeans, lava, molokai | |
# nord, one-dark, one-light, snazzy, solarized-dark | |
# solarized-light | |
# Specifies how environment variables are: | |
# - converted from a string to a value on Nushell startup (from_string) | |
# - converted from a value back to a string when running external commands (to_string) | |
# Note: The conversions happen *after* config.nu is loaded | |
# $env.ENV_CONVERSIONS = { | |
# "PATH": { | |
# from_string: { |s| $s | split row (char esep) | path expand } | |
# to_string: { |v| $v | path expand | str join (char esep) } | |
# } | |
# "Path": { | |
# from_string: { |s| $s | split row (char esep) | path expand } | |
# to_string: { |v| $v | path expand | str join (char esep) } | |
# } | |
# "LS_COLORS": { | |
# from_string: { |s| $s | split row (char esep) } | |
# # from_string: { |s| $s | split row '=' | $"(ansi -e ($in.1))m($in.0)(ansi reset) ($in.1)" } | split column ' ' | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "DYLD_FALLBACK_LIBRARY_PATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PATHEXT": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# "PSMODULEPATH": { | |
# from_string: { |s| $s | split row (char esep) } | |
# to_string: { |v| $v | str join (char esep) } | |
# } | |
# } | |
export-env { | |
let esep_list_converter = { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | str join (char esep) } | |
} | |
let esep_path_converter = { | |
from_string: { |s| $s | split row (char esep) } | |
to_string: { |v| $v | path expand | str join (char esep) } | |
} | |
$env.ENV_CONVERSIONS = { | |
PATH: $esep_path_converter | |
Path: $esep_path_converter | |
LS_COLORS: $esep_list_converter | |
DYLD_FALLBACK_LIBRARY_PATH: $esep_path_converter | |
PATHEXT: $esep_list_converter | |
PSMODULEPATH: $esep_path_converter | |
} | |
} | |
# Directories to search for scripts when calling source or use | |
# | |
# By default, <nushell-config-dir>/scripts is added | |
$env.NU_LIB_DIRS = [ | |
($nu.config-path | path dirname | path join 'scripts') | |
'/home/fdncred/src/nu_scripts' | |
($nu.config-path | path dirname) | |
] | |
# Directories to search for plugin binaries when calling register | |
# | |
# By default, <nushell-config-dir>/plugins is added | |
$env.NU_PLUGIN_DIRS = [ | |
($nu.config-path | path dirname | path join 'plugins') | |
] | |
# To add entries to PATH (on Windows you might use Path), you can use the following pattern: | |
# $env.PATH = ($env.PATH | prepend '/some/path') | |
# latest zoxide | |
# zoxide init nushell --hook prompt | save -f ~/.zoxide.nu | |
# zoxide init nushell --cmd cd --hook prompt | save -f ~/.zoxide.nu | |
# $env.POSH_THEME = $"(brew --prefix oh-my-posh)/themes/jandedobbeleer.omp.json" | |
# $env.NU_VERSION = "0.74.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment