Skip to content

Instantly share code, notes, and snippets.

View fdncred's full-sized avatar

Darren Schroeder fdncred

View GitHub Profile
@fdncred
fdncred / hex_to_f32.nu
Created August 31, 2026 13:39
converting hex to f32 in nushell
```nushell
# Reinterpret a 32-bit hexadecimal integer as an IEEE-754 single-precision
# (f32) floating-point value.
#
# An IEEE-754 f32 is laid out as:
#
# [ sign: 1 bit ][ exponent: 8 bits ][ fraction: 23 bits ]
#
# For example:
#
@fdncred
fdncred / pr.nu
Created July 18, 2024 15:33
rich_in_nu
# emulate the python rich print
# test case 1: pr "hello world"
# test case 2: pr "hello world" --style bold
# test case 3: pr "hello world" --style 'bold underline'
# test case 4: pr "hello world" --style 'dim italic red'
def pr [
msg,
--style: string,
] {
let style = if $style == null {
@fdncred
fdncred / memory-perf.md
Last active May 7, 2024 12:49
memory perf

Nushell Memory Utilization

2023-08-29 07:13:21.667983800 -05:00

❯ let before = (sys).mem.used
❯ $before
9,382,694,912
❯ mut csv = open ~\OneDrive\vdi\DBScripts\Output\violations-20220731-20230801.csv
❯ $csv | length
1046339
@fdncred
fdncred / nushell_bashisms.md
Last active April 15, 2024 14:22
nushell bashisms

Bashisms

What is a bashism

A bashism is a command, operator, or syntax in the repl that most people associate with bash.

What bashisms does Nushell support?

Bang Bang syntax

@fdncred
fdncred / config_loading.md
Last active October 23, 2024 22:35
nushell config file loading

Config file loading rules

  1. default_config.nu and default_env.nu refer to the files that are compiled inside of the nushell executable and are also located in our repo.
  2. personal env.nu/config.nu/login.nu refer to the files that are in the $nu.default-config-dir that you have personally edited.
  3. specified config.nu/env.nu refer to files that are specified on the command line with the --config and --env-config command line parameters.

nu

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
@fdncred
fdncred / escape_sequences.md
Created December 20, 2023 15:38
escape sequences

OSC4 - set foreground/background colors

OSC 4 ; -2; ? ST //bg
OSC 4 ; -1 ; ? ST //fg
OSC 4 ; -2 ; rgb : [red] / [green] / [blue] ST
OSC 4 ; -1 ; rgb : [red] / [green] / [blue] ST

OSC6 - set window title and tab color

OSC 6 ; 1 ; bg ; red ; brightness ; [N] ST
OSC 6 ; 1 ; bg ; green ; brightness ; [N] ST

OSC 6 ; 1 ; bg ; blue ; brightness ; [N] ST

@fdncred
fdncred / dt-formats.nu
Created October 30, 2023 19:58
datetime formats
def utc [now?: datetime] {
if $now == null {
date now | date to-timezone utc | format date "%Y-%m-%dT%H:%M:%SZ"
} else {
$now | date to-timezone utc | format date "%Y-%m-%dT%H:%M:%SZ"
}
}
def iso-8601 [now?: datetime] {
if $now == null {
@fdncred
fdncred / pr.nu
Last active October 30, 2023 12:02
rich_print
# emulate the python rich print
# https://github.com/Textualize/rich
# https://github.com/Textualize/rich/blob/master/rich/console.py#L1624
# test case 1: pr "hello world"
# test case 2: pr "hello world" --style bold
# test case 3: pr "hello world" --style 'bold underline'
# test case 4: pr "hello world" --style 'dim italic red'
def pr [
msg,
--style: string,
@fdncred
fdncred / build_all_plugins.nu
Last active September 27, 2024 13:15
build all plugins
# Build All Plugins
def build_all_external_plugins [] {
let plugins = ls nu_plugin_* | where name != nu_plugin_template
for plug in $plugins {
print $"(ansi green_bold)Doing some git work on (ansi purple_bold)($plug.name)(ansi reset)(char nl)"
cd ($plug.name | path expand)
git restore Cargo.lock
git restore Cargo.toml
git pull
@fdncred
fdncred / fzf_integration.md
Last active September 24, 2022 07:37
fzf_integration

FZF

Most of this is taken from fzf.fish. A really nice fzf integration with fish-shell.

There's quite a bit of usage of a fish command called commandline. It would be super helpful for porting things like this script if we had such a utility to modify the readline command line buffer.

General Setup

Set the default fzf options

let-env FZF_DEFAULT_OPTS = '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"'