1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-08-02 21:17:45 +00:00

Compare commits

..

No commits in common. "0eb9a36ce6a37653b1a58ebcb592da8e549bfd2b" and "83cdf1bf2b0afbe8247dd271ae06a593b5281c60" have entirely different histories.

5 changed files with 610 additions and 408 deletions

View file

@ -1,438 +1,424 @@
use std-rfc/clip $env.config = {
use std null_device bracketed_paste: true
buffer_editor: ""
datetime_format: {}
edit_mode: vi
error_style: fancy
float_precision: 2
footer_mode: 25
render_right_prompt_on_last_line: false
show_banner: false
use_ansi_coloring: true
use_kitty_protocol: true
source ~/.config/nushell/zoxide.nu shell_integration: {
osc2: false
# Retrieve the output of the last command. osc7: true
def _ []: nothing -> any { osc8: true
$env.last? osc9_9: false
osc133: true
osc633: true
reset_application_mode: true
}
} }
# Create a directory and cd into it. $env.config.color_config = {
def --env mc [path: path]: nothing -> nothing { binary: white
mkdir $path block: white
cd $path bool: {|| if $in { "light_green" } else { "light_red" } }
cell-path: white
date: purple
duration: white
empty: blue
filesize: cyan
float: white
header: green_bold
hints: dark_gray
int: white
list: white
nothing: white
range: white
record: white
row_index: green_bold
search_result: { bg: red fg: white }
separator: white
string: {|| if $in =~ "^(#|0x)[a-fA-F0-9]+$" { ($in | str replace "0x" "#") } else { "white" } }
leading_trailing_space_bg: { attr: n }
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
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_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_table: blue_bold
shape_vardecl: purple
shape_variable: purple
shape_matching_brackets: { attr: u }
shape_string_interpolation: cyan_bold
} }
# Create a directory, cd into it and initialize version control. $env.config.ls = {
def --env mcg [path: path]: nothing -> nothing { clickable_links: true
mkdir $path use_ls_colors: true
cd $path
jj git init --colocate
} }
# `nu-highlight` with default colors
#
# Custom themes can produce a lot more ansi color codes and make the output
# exceed discord's character limits
def nu-highlight-default [] {
let input = $in
$env.config.color_config = {}
$input | nu-highlight
}
$env.config.history.file_format = "sqlite"
$env.config.history.isolation = false
$env.config.history.max_size = 10_000_000
$env.config.history.sync_on_enter = true
$env.config.show_banner = false
$env.config.rm.always_trash = false $env.config.rm.always_trash = false
$env.config.recursion_limit = 100 $env.config.table = {
header_on_separator: false
$env.config.edit_mode = "vi" index_mode: always
mode: rounded
$env.config.cursor_shape.emacs = "line" padding: { left: 1 right: 1 }
$env.config.cursor_shape.vi_insert = "line" show_empty: true
$env.config.cursor_shape.vi_normal = "block" trim: {
methodology: wrapping
$env.config.completions.algorithm = "substring" wrapping_try_keep_words: true
$env.config.completions.sort = "smart" truncating_suffix: "..."
$env.config.completions.case_sensitive = false
$env.config.completions.quick = true
$env.config.completions.partial = true
$env.config.completions.use_ls_colors = true
$env.config.completions.external.enable = true
$env.config.completions.external.max_results = 100
$env.config.completions.external.completer = {|tokens: list<string>|
let expanded = scope aliases
| where name == $tokens.0
| get --ignore-errors 0.expansion
mut tokens = if $expanded != null and $tokens.0 != "cd" {
$expanded | split row " " | append ($tokens | skip 1)
} else {
$tokens
}
$tokens.0 = $tokens.0 | str trim --left --char "^"
let command = $tokens
| str join " "
| str replace --all (char single_quote) $"\\(char single_quote)"
fish --command $"complete '--do-complete=($command)'"
| $"value(char tab)description(char newline)" + $in
| from tsv --flexible --no-infer
}
$env.config.use_kitty_protocol = true
$env.config.shell_integration.osc2 = true
$env.config.shell_integration.osc7 = true
$env.config.shell_integration.osc8 = true
$env.config.shell_integration.osc9_9 = true
$env.config.shell_integration.osc133 = true
$env.config.shell_integration.osc633 = true
$env.config.shell_integration.reset_application_mode = true
$env.config.bracketed_paste = true
$env.config.use_ansi_coloring = "auto"
$env.config.error_style = "fancy"
$env.config.highlight_resolved_externals = true
$env.config.display_errors.exit_code = false
$env.config.display_errors.termination_signal = true
$env.config.footer_mode = 25
$env.config.table.mode = "single"
$env.config.table.index_mode = "always"
$env.config.table.show_empty = true
$env.config.table.padding.left = 1
$env.config.table.padding.right = 1
$env.config.table.trim.methodology = "wrapping"
$env.config.table.trim.wrapping_try_keep_words = true
$env.config.table.trim.truncating_suffix = "..."
$env.config.table.header_on_separator = true
$env.config.table.abbreviated_row_count = null
$env.config.table.footer_inheritance = true
$env.config.table.missing_value_symbol = $"(ansi magenta_bold)nope(ansi reset)"
$env.config.datetime_format.table = null
$env.config.datetime_format.normal = $"(ansi blue_bold)%Y(ansi reset)(ansi yellow)-(ansi blue_bold)%m(ansi reset)(ansi yellow)-(ansi blue_bold)%d(ansi reset)(ansi black)T(ansi magenta_bold)%H(ansi reset)(ansi yellow):(ansi magenta_bold)%M(ansi reset)(ansi yellow):(ansi magenta_bold)%S(ansi reset)"
$env.config.filesize.unit = "metric"
$env.config.filesize.show_unit = true
$env.config.filesize.precision = 1
$env.config.render_right_prompt_on_last_line = false
$env.config.float_precision = 2
$env.LS_COLORS = (open ~/.config/nushell/ls_colors.txt)
$env.config.ls.use_ls_colors = true
$env.config.hooks.pre_prompt = []
$env.config.hooks.pre_execution = [
{||
commandline
| str trim
| if ($in | is-not-empty) { print $"(ansi title)($in) — nu(char bel)" }
}
]
$env.config.hooks.env_change = {}
$env.config.hooks.display_output = {||
tee { table --expand | print }
| if $in != null { $env.last = $in }
}
$env.config.hooks.command_not_found = []
# Copy the current commandline, add syntax highlighting, wrap it in a
# markdown code block, copy that to the system clipboard.
#
# Perfect for sharing code snippets on discord
def "nu-keybind commandline-copy" []: nothing -> nothing {
commandline
| nu-highlight-default
| [
"```ansi"
$in
"```"
]
| str join (char nl)
| clip copy --ansi
}
$env.config.keybindings ++= [
{
name: copy_color_commandline
modifier: control_alt
keycode: char_c
mode: [ emacs vi_insert vi_normal ]
event: {
send: executehostcommand
cmd: 'nu-keybind commandline-copy'
}
}
]
$env.config.color_config.bool = {||
if $in {
"light_green_bold"
} else {
"light_red_bold"
} }
} }
$env.config.color_config.string = {|| $env.config.explore = {
if $in =~ "^(#|0x)[a-fA-F0-9]+$" { command_bar_text: { fg: "#C4C9C6" }
$in | str replace "0x" "#" highlight: { fg: black bg: yellow }
} else { status: {
"white" error: { fg: white bg: red }
warn: {}
info: {}
}
status_bar_background: { fg: "#1D1F21" bg: "#C4C9C6" }
table: {
split_line: { fg: "#404040" }
selected_cell: { bg: light_blue }
selected_row: {}
selected_column: {}
} }
} }
$env.config.color_config.row_index = "light_yellow_bold" $env.config.history = {
$env.config.color_config.header = "light_yellow_bold" file_format: sqlite
isolation: false
max_size: 100_000
sync_on_enter: true
}
do --env { $env.config.completions = {
def prompt-header [ algorithm: prefix
--left-char: string case_sensitive: false
]: nothing -> string { partial: true
let jj_workspace_root = try { quick: true
jj workspace root err> $null_device external: {
} catch { enable: true
"" max_results: 100
} completer: {|tokens: list<string>|
let expanded = scope aliases | where name == $tokens.0 | get --ignore-errors expansion.0
let body = if ($jj_workspace_root | is-not-empty) { mut expanded_tokens = if $expanded != null and $tokens.0 != "cd" {
let subpath = pwd | path relative-to $jj_workspace_root $expanded | split row " " | append ($tokens | skip 1)
let subpath = if ($subpath | is-not-empty) {
$"(ansi magenta_bold) → (ansi reset)(ansi blue)($subpath)"
}
$"(ansi light_yellow_bold)($jj_workspace_root | path basename)($subpath)(ansi reset)"
} else {
let pwd = if (pwd | str starts-with $env.HOME) {
"~" | path join (pwd | path relative-to $env.HOME)
} else { } else {
pwd $tokens
} }
$"(ansi cyan)($pwd)(ansi reset)" $expanded_tokens.0 = ($expanded_tokens.0 | str trim --left --char "^")
fish --command $"complete '--do-complete=($expanded_tokens | str join ' ')'"
| $"value(char tab)description(char newline)" + $in
| from tsv --flexible --no-infer
} }
let middle = if $env.LAST_EXIT_CODE == 0 {
"━"
} else {
$"┫(ansi light_red_bold)($env.LAST_EXIT_CODE)(ansi light_yellow_bold)┣"
}
$"(ansi light_yellow_bold)($left_char)($middle)━(ansi reset) ($body)(char newline)"
} }
$env.PROMPT_INDICATOR = $"(ansi light_yellow_bold)┃(ansi reset) "
$env.PROMPT_INDICATOR_VI_NORMAL = $env.PROMPT_INDICATOR
$env.PROMPT_INDICATOR_VI_INSERT = $env.PROMPT_INDICATOR
$env.PROMPT_MULTILINE_INDICATOR = $env.PROMPT_INDICATOR
$env.PROMPT_COMMAND = {||
prompt-header --left-char "┏"
}
$env.PROMPT_COMMAND_RIGHT = {||
let jj_status = try {
jj --quiet --color always --ignore-working-copy log --no-graph --revisions @ --template '
separate(
" ",
if(empty, label("empty", "(empty)")),
coalesce(
surround(
"\"",
"\"",
if(
description.first_line().substr(0, 24).starts_with(description.first_line()),
description.first_line().substr(0, 24),
description.first_line().substr(0, 23) ++ "…"
)
),
label(if(empty, "empty"), description_placeholder)
),
bookmarks.join(", "),
change_id.shortest(),
commit_id.shortest(),
if(conflict, label("conflict", "(conflict)")),
if(divergent, label("divergent prefix", "(divergent)")),
if(hidden, label("hidden prefix", "(hidden)")),
)
' err> $null_device
} catch {
""
}
$jj_status
}
$env.TRANSIENT_PROMPT_INDICATOR = " "
$env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT = $env.TRANSIENT_PROMPT_INDICATOR
$env.TRANSIENT_PROMPT_INDICATOR_VI_NORMAL = $env.TRANSIENT_PROMPT_INDICATOR
$env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = $env.TRANSIENT_PROMPT_INDICATOR
$env.TRANSIENT_PROMPT_COMMAND = {||
prompt-header --left-char "━"
}
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = $env.PROMPT_COMMAND_RIGHT
} }
let menus = [ $env.config.cursor_shape = {
{ vi_insert: line
name: completion_menu vi_normal: block
only_buffer_difference: false }
marker: $env.PROMPT_INDICATOR
type: { $env.config.hooks = {
layout: ide command_not_found: {||}
border: false
correct_cursor_pos: true display_output: {
tee { table --expand | print }
| $env.last = $in
}
env_change: {}
pre_execution: [
{
let prompt = commandline | str trim
if ($prompt | is-empty) {
return
}
print $"(ansi title)($prompt) — nu(char bel)"
} }
]
pre_prompt: []
}
# Retrieve the output of the last command.
def _ []: nothing -> any {
$env.last
}
$env.config.menus = [
{
marker: "| "
name: completion_menu
only_buffer_difference: false
style: { style: {
text: white
selected_text: white_reverse
description_text: yellow description_text: yellow
match_text: { attr: u } selected_text: green_reverse
selected_match_text: { attr: ur } text: green
}
type: {
col_padding: 2
col_width: 20
columns: 4
layout: columnar
} }
} }
{ {
name: history_menu marker: "? "
name: history_menu
only_buffer_difference: true only_buffer_difference: true
marker: $env.PROMPT_INDICATOR style: {
description_text: yellow
selected_text: green_reverse
text: green
}
type: { type: {
layout: list layout: list
page_size: 10 page_size: 10
} }
}
{
marker: "? "
name: help_menu
only_buffer_difference: true
style: { style: {
text: white description_text: yellow
selected_text: white_reverse selected_text: green_reverse
text: green
}
type: {
col_padding: 2
col_width: 20
columns: 4
description_rows: 10
layout: description
selection_rows: 4
} }
} }
] ]
$env.config.menus = $env.config.menus $env.config.keybindings = [
| where name not-in ($menus | get name) {
| append $menus name: copy_commandline
modifier: alt
module dump { keycode: char_c
def site-path []: nothing -> path { mode: [ vi_normal vi_insert ]
$env.HOME | path join "Projects" "site" event: {
} send: executehostcommand
cmd: 'commandline | nu-highlight | $"```ansi\n($in)\n```" | copy'
def dump-path []: nothing -> path {
site-path | path join "site" "dump"
}
# Convert a thought dump namespace to the filesystem path.
export def to-path []: string -> path {
let namespace = $in
dump-path
| path join ...($namespace | split row ".")
| $in + ".md"
}
# Convert a filesystem path to a thought dump namespace.
export def to-dump []: path -> string {
let path = $in
$path
| path relative-to (dump-path)
| path split
| str join "."
| str substring 0..<-3
}
# List all thought dumps that start with the given namespace.
export def list [
namespace: string = ""
]: nothing -> table<namespace: string, path: path> {
let dump_prefix = dump-path | path join ...($namespace | split row ".")
let dump_parent_contents = glob ($dump_prefix | path parse | get parent | path join "**" "*.md")
let dump_matches = $dump_parent_contents | where { str starts-with $dump_prefix }
ls ...$dump_matches | each {
merge { path: $in.name }
| select path size modified
| merge { namespace: ($in.path | to-dump) }
} }
} }
{
# Deploy the thought dumps and thus the website. name: completion_menu
export def deploy []: nothing -> nothing { modifier: none
print $"(ansi green)deploying...(ansi reset)" keycode: tab
mode: [ vi_normal vi_insert ]
cd (site-path) event: {
./apply.nu until: [
} { send: menu name: completion_menu }
{ send: menunext }
# Edit a thought dump. { edit: complete }
export def edit [ ]
namespace: string # The thought dump to edit. Namespaced using '.', does not include file extension.
]: nothing -> nothing {
let dump_path = $namespace | to-path
let old_dump_size = try { ls $dump_path }
mkdir ($dump_path | path parse | get parent)
touch $dump_path
let old_dump_hash = open $dump_path | hash sha256
^$env.EDITOR $dump_path
let dump_size = ls $dump_path | get 0.size
if $dump_size == 0b {
print $"(ansi red)thought dump was emptied(ansi reset)"
delete $namespace --existed-before ($old_dump_size != null)
} else if $old_dump_hash == (open $dump_path | hash sha256) {
print $"(ansi yellow)thought dump was not modifier, doing nothing(ansi reset)"
} else {
print $"(ansi magenta)thought dump was edited(ansi reset)"
let jj_arguments = [ "--repository", (site-path) ]
jj ...$jj_arguments commit --message $"dump\(($namespace)\): update"
jj ...$jj_arguments bookmark set master --revision @-
[
{ jj ...$jj_arguments git push --remote origin }
{ jj ...$jj_arguments git push --remote rad }
{ deploy }
] | par-each { do $in } | last
} }
} }
{
# Delete a thought dump. name: history_menu
export def delete [ modifier: control
namespace: string # The thought dump to edit. Namespaced using '.', does not include file extension. keycode: char_h
--existed-before = true mode: [ vi_insert vi_normal ]
]: nothing -> nothing { event: { send: menu name: history_menu }
let dump_path = $namespace | to-path }
let parent_path = $dump_path | path parse | get parent {
name: escape
print $"(ansi red)deleting thought dump...(ansi reset)" modifier: none
print --no-newline (ansi red) keycode: escape
rm --verbose $dump_path mode: [ vi_normal vi_insert ]
print --no-newline (ansi reset) event: { send: esc }
}
if (ls $parent_path | length) == 0 { {
print $"(ansi red)parent folder is empty, deleting that too...(ansi reset)" name: cancel_command
print $"(ansi yellow)other parents will not be deleted, if you want to delete those do it manually(ansi reset)" modifier: control
rm $parent_path keycode: char_c
} mode: [ vi_normal vi_insert ]
event: { send: ctrlc }
if $existed_before { }
deploy {
} else { name: quit_shell
print $"(ansi green)the thought dump didn't exist before, so skipping deployment(ansi reset)" modifier: control
keycode: char_d
mode: [ vi_normal vi_insert ]
event: { send: ctrld }
}
{
name: clear_screen
modifier: control
keycode: char_l
mode: [ vi_normal vi_insert ]
event: { send: clearscreen }
}
{
name: open_command_editor
modifier: control
keycode: char_o
mode: [ vi_normal vi_insert ]
event: { send: openeditor }
}
{
name: abbr
modifier: control
keycode: space
mode: [ vi_normal vi_insert ]
event: [
{ send: menu name: abbr_menu }
{ edit: insertchar, value: " " }
]
}
{
name: move_up
modifier: none
keycode: up
mode: [ vi_normal vi_insert ]
event: {
until: [
{ send: menuup }
{ send: up }
]
} }
} }
} {
name: move_down
use dump modifier: none
keycode: down
mode: [ vi_normal vi_insert ]
event: {
until: [
{ send: menudown }
{ send: down }
]
}
}
{
name: move_left
modifier: none
keycode: left
mode: [ vi_normal vi_insert ]
event: {
until: [
{ send: menuleft }
{ send: left }
]
}
}
{
name: move_right_or_take_history_hint
modifier: none
keycode: right
mode: [ vi_normal vi_insert ]
event: {
until: [
{ send: historyhintcomplete }
{ send: menuright }
{ send: right }
]
}
}
{
name: move_one_word_left
modifier: control
keycode: left
mode: [ vi_normal vi_insert ]
event: { edit: movewordleft }
}
{
name: move_one_word_right_or_take_history_hint
modifier: control
keycode: right
mode: [ vi_normal vi_insert ]
event: {
until: [
{ send: historyhintwordcomplete }
{ edit: movewordright }
]
}
}
{
name: move_to_line_start
modifier: control
keycode: char_a
mode: [ vi_normal vi_insert ]
event: { edit: movetolinestart }
}
{
name: move_to_line_end_or_take_history_hint
modifier: control
keycode: char_e
mode: [ vi_normal vi_insert ]
event: {
until: [
{ send: historyhintcomplete }
{ edit: movetolineend }
]
}
}
{
name: delete_one_character_backward
modifier: none
keycode: backspace
mode: vi_insert
event: { edit: backspace }
}
{
name: delete_one_word_backward
modifier: control
keycode: backspace
mode: vi_insert
event: { edit: backspaceword }
}
{
name: newline_or_run_command
modifier: none
keycode: enter
mode: vi_insert
event: { send: enter }
}
]

View file

@ -1,5 +1,5 @@
{ config, lib, pkgs, ... }: let { config, lib, pkgs, ... }: let
inherit (lib) attrValues const disabled enabled getExe mapAttrs mkIf optionalAttrs readFile removeAttrs replaceString; inherit (lib) attrValues const enabled getExe mapAttrs mkIf optionalAttrs readFile removeAttrs replaceString;
in { in {
environment = optionalAttrs config.isLinux { environment = optionalAttrs config.isLinux {
sessionVariables.SHELLS = getExe pkgs.nushell; sessionVariables.SHELLS = getExe pkgs.nushell;
@ -26,8 +26,45 @@ in {
zoxide # For completions and better cd. zoxide # For completions and better cd.
; ;
}; };
variables.STARSHIP_LOG = "error";
}; };
nixpkgs.overlays = [(self: super: {
zoxide = super.zoxide.overrideAttrs (old: {
src = self.fetchFromGitHub {
owner = "Bahex";
repo = "zoxide";
rev = "0450775af9b1430460967ba8fb5aa434f95c4bc4";
hash = "sha256-WhACxJMuhI9HGohcwg+ztZpQCVUZ4uibIQqGfJEEp/Y=";
};
cargoDeps = self.rustPlatform.fetchCargoVendor {
inherit (self.zoxide) src;
hash = "sha256-v3tcQaEXfGyt1j2fShvxxrA9Xc90AWxEzEUT09cQ+is=";
};
});
starship = super.starship.overrideAttrs (old: {
src = self.fetchFromGitHub {
owner = "poliorcetics";
repo = "starship";
rev = "92aba18381994599850053ba667c25017566b8ee";
hash = "sha256-FKDvkDcxUPDLcjFQzvqsGXeJUm0Dq8TcA4edf5OkdWo=";
};
cargoDeps = self.rustPlatform.fetchCargoVendor {
inherit (self.starship) src;
hash = "sha256-nH1iYjKw/GbYKadoymH3onWBbMzuMUaRCSTNWVE+A9E=";
};
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.cmake
pkgs.zlib-ng
];
});
})];
home-manager.sharedModules = [(homeArgs: let home-manager.sharedModules = [(homeArgs: let
homeConfig = homeArgs.config; homeConfig = homeArgs.config;
in { in {
@ -39,6 +76,31 @@ in {
"nushell/ls_colors.txt".source = pkgs.runCommand "ls_colors.txt" {} '' "nushell/ls_colors.txt".source = pkgs.runCommand "ls_colors.txt" {} ''
${getExe pkgs.vivid} generate gruvbox-dark-hard > $out ${getExe pkgs.vivid} generate gruvbox-dark-hard > $out
''; '';
"nushell/starship.nu".source = pkgs.runCommand "starship.nu" {} ''
${getExe pkgs.starship} init nu > $out
'';
};
programs.starship = enabled {
# No because we are doing it at build time instead of the way
# this retarded module does it. Why the hell do you generate
# the config every time the shell is launched?
enableNushellIntegration = false;
settings = {
vcs.disabled = false;
command_timeout = 100;
scan_timeout = 20;
cmd_duration.show_notifications = config.isDesktop;
package.disabled = config.isServer;
character.error_symbol = "";
character.success_symbol = "";
};
}; };
programs.direnv = enabled { programs.direnv = enabled {

View file

@ -1 +1,154 @@
# Crickets... $env.ENV_CONVERSIONS.PATH = {
from_string: {|string|
$string | split row (char esep) | path expand --no-symlink
}
to_string: {|value|
$value | path expand --no-symlink | str join (char esep)
}
}
$env.LS_COLORS = (open ~/.config/nushell/ls_colors.txt)
source ~/.config/nushell/zoxide.nu
source ~/.config/nushell/starship.nu
def copy []: string -> nothing {
print --no-newline $"(ansi osc)52;c;($in | encode base64)(ansi st)"
}
def today []: nothing -> string {
date now | format date "%Y-%m-%d"
}
# Create a directory and cd into it.
def --env mc [path: path]: nothing -> nothing {
mkdir $path
cd $path
}
# Create a directory, cd into it and initialize version control.
def --env mcg [path: path]: nothing -> nothing {
mkdir $path
cd $path
jj git init --colocate
}
module dump {
def site-path []: nothing -> path {
$env.HOME | path join "Projects" "site"
}
def dump-path []: nothing -> path {
site-path | path join "site" "dump"
}
# Convert a thought dump namespace to the filesystem path.
export def to-path []: string -> path {
let namespace = $in
dump-path
| path join ...($namespace | split row ".")
| $in + ".md"
}
# Convert a filesystem path to a thought dump namespace.
export def to-dump []: path -> string {
let path = $in
$path
| path relative-to (dump-path)
| path split
| str join "."
| str substring 0..<-3
}
# List all thought dumps that start with the given namespace.
export def list [
namespace: string = ""
]: nothing -> table<namespace: string, path: path> {
let dump_prefix = dump-path | path join ...($namespace | split row ".")
let dump_parent_contents = glob ($dump_prefix | path parse | get parent | path join "**" "*.md")
let dump_matches = $dump_parent_contents | where { str starts-with $dump_prefix }
ls ...$dump_matches | each {
merge { path: $in.name }
| select path size modified
| merge { namespace: ($in.path | to-dump) }
}
}
# Deploy the thought dumps and thus the website.
export def deploy []: nothing -> nothing {
print $"(ansi green)deploying...(ansi reset)"
cd (site-path)
./apply.nu
}
# Edit a thought dump.
export def edit [
namespace: string # The thought dump to edit. Namespaced using '.', does not include file extension.
]: nothing -> nothing {
let dump_path = $namespace | to-path
let old_dump_size = try { ls $dump_path }
mkdir ($dump_path | path parse | get parent)
touch $dump_path
let old_dump_hash = open $dump_path | hash sha256
^$env.EDITOR $dump_path
let dump_size = ls $dump_path | get 0.size
if $dump_size == 0b {
print $"(ansi red)thought dump was emptied(ansi reset)"
delete $namespace --existed-before ($old_dump_size != null)
} else if $old_dump_hash == (open $dump_path | hash sha256) {
print $"(ansi yellow)thought dump was not modifier, doing nothing(ansi reset)"
} else {
print $"(ansi magenta)thought dump was edited(ansi reset)"
let jj_arguments = [ "--repository", (site-path) ]
jj ...$jj_arguments commit --message $"dump\(($namespace)\): update"
jj ...$jj_arguments bookmark set master --revision @-
[
{ jj ...$jj_arguments git push --remote origin }
{ jj ...$jj_arguments git push --remote rad }
{ deploy }
] | par-each { do $in } | last
}
}
# Delete a thought dump.
export def delete [
namespace: string # The thought dump to edit. Namespaced using '.', does not include file extension.
--existed-before = true
]: nothing -> nothing {
let dump_path = $namespace | to-path
let parent_path = $dump_path | path parse | get parent
print $"(ansi red)deleting thought dump...(ansi reset)"
print --no-newline (ansi red)
rm --verbose $dump_path
print --no-newline (ansi reset)
if (ls $parent_path | length) == 0 {
print $"(ansi red)parent folder is empty, deleting that too...(ansi reset)"
print $"(ansi yellow)other parents will not be deleted, if you want to delete those do it manually(ansi reset)"
rm $parent_path
}
if $existed_before {
deploy
} else {
print $"(ansi green)the thought dump didn't exist before, so skipping deployment(ansi reset)"
}
}
}
use dump

View file

@ -1,5 +0,0 @@
{
home-manager.sharedModules = [{
home.file.".hushlogin".text = "";
}];
}

View file

@ -123,16 +123,22 @@ def darwin-shadow-xcode-popup [] {
def darwin-set-zshrc [] { def darwin-set-zshrc [] {
print "setting zshrc..." print "setting zshrc..."
let nu_command = $"let usr_bin_index = $env.PATH let nu_command = $"
| enumerate let usr_bin_index = $env.PATH
| where item == /usr/bin | enumerate
| get 0.index; | where item == /usr/bin
| get 0.index
$env.PATH = $env.PATH | insert $usr_bin_index ($shadow_path | path expand); $env.PATH = $env.PATH | insert $usr_bin_index ($shadow_path | path expand)
$env.SHELL = which nu | get 0.path" | str replace --all "\n" "" $env.SHELL = which nu | get 0.path
"
let zshrc = $"exec nu --execute '($nu_command)'" let zshrc = $"
exec nu --execute '
($nu_command)
'
"
$zshrc | save --force ~/.zshrc $zshrc | save --force ~/.zshrc
} }