Skip to content

Instantly share code, notes, and snippets.

@jamesonknutson
jamesonknutson / job-prompt.nu
Last active July 31, 2025 22:04
Proof of concept job status display in nushell
# Jobs Prompt
# Proof-of-concept to display the status of ongoing (and completed) nushell jobs
# by showing their state in the $env.PROMPT_COMMAND closure. Abuses some tricks with $env, and hooks.
# Namely, it uses the `$env.config.hooks.pre_prompt` hook to call the `prompt` command, which
# saves it's result to `$env.JOBS_PROMPT`. Then, in the custom `$env.PROMPT_COMMAND` closure, that
# variable is read from, and used to display the text before your directory / real prompt.
#
# This was just a proof of concept that I worked on because I found it interesting, there are surely bugs,
# and the code is not good. But, it can serve as a base to work off of for anyone who likes the idea!
#
{
"$id": "https://github.com/microsoft/terminal/blob/main/doc/cascadia/profiles.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Microsoft's Windows Terminal Settings Profile Schema",
"$defs": {
"KeyChordSegment": {
"pattern": "^(?:(?:ctrl|alt|shift|win)\\+)*(?:app|backspace|browser_(?:back|forward|refresh|stop|search|favorites|home)|comma|delete|down|end|enter|esc|escape|home|insert|left|menu|minus|pagedown|pageup|period|pgdn|pgup|plus|right|space|tab|up|f(?:1\\d?|2[0-4]?|[3-9])|numpad\\d|numpad_(?:\\d|add|decimal|divide|minus|multiply|period|plus|subtract)|(?:vk|sc)\\((?:[1-9]|1?\\d{2}|2[0-4]\\d|25[0-5])\\)|[^\\s+])(?:\\+(?:ctrl|alt|shift|win))*$",
"type": "string",
"description": "The string should fit the format \"[ctrl+][alt+][shift+][win+]<KeyName>\", where each modifier is optional. KeyName is either any single key character, an explicit virtual key or scan code in the form vk(nnn) and sc(nnn) respectively, or one of the special names list
@jamesonknutson
jamesonknutson / groups.nu
Last active October 14, 2024 07:28
groups.nu
use std
def nested-type [
--keep-streams(-k) # If the input is a stream, should `stream` be returned, or should `.subtype.type` be returned?
] {
match $in {
{ type: 'stream', subtype: $subtype } => {
if not $keep_streams {
$subtype | nested-type --keep-streams=($keep_streams)
} else {
use std *
# Convert a value into a list.
export def 'into list' []: any -> list<any> {
append null
}
# { type: <'list'> , length : <int>, values: list<detailed_type> }
# { type: <'record'> , columns : record<any, detailed_type> }
@jamesonknutson
jamesonknutson / example.nu
Last active October 10, 2024 00:28
ps expand recursive example
use std *
# Convert a value into a list.
export def 'into list' []: any -> list<any> {
append null
}
# { type: <'list'> , length : <int>, values: list<detailed_type> }
# { type: <'record'> , columns : record<any, detailed_type> }
# repl-env.nu
# example:
# > let repl_env = repl-env setup-env
# > $env.repl-env = ($repl_env.repl-env | upsert max_length 5)
# > $env.config = $repl_env.config
#
# use the `@` alias to view the last commands output (or use the repl-env get-history command)
#
# $env.repl-env will look like:
# {