mirror of
https://github.com/RGBCube/ncc
synced 2025-07-29 11:07:44 +00:00
nushell: update configs
This commit is contained in:
parent
8182df2c50
commit
cf23682ea0
3 changed files with 300 additions and 573 deletions
|
@ -1,424 +1,318 @@
|
|||
$env.config = {
|
||||
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
|
||||
use std-rfc/clip
|
||||
|
||||
shell_integration: {
|
||||
osc2: false
|
||||
osc7: true
|
||||
osc8: true
|
||||
osc9_9: false
|
||||
osc133: true
|
||||
osc633: true
|
||||
reset_application_mode: true
|
||||
}
|
||||
source ~/.config/nushell/zoxide.nu
|
||||
source ~/.config/nushell/starship.nu
|
||||
|
||||
# Retrieve the output of the last command.
|
||||
def _ []: nothing -> any {
|
||||
$env.last?
|
||||
}
|
||||
|
||||
$env.config.color_config = {
|
||||
binary: white
|
||||
block: white
|
||||
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 and cd into it.
|
||||
def --env mc [path: path]: nothing -> nothing {
|
||||
mkdir $path
|
||||
cd $path
|
||||
}
|
||||
|
||||
$env.config.ls = {
|
||||
clickable_links: true
|
||||
use_ls_colors: true
|
||||
# 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
|
||||
}
|
||||
|
||||
$env.config.rm.always_trash = false
|
||||
|
||||
$env.config.table = {
|
||||
header_on_separator: false
|
||||
index_mode: always
|
||||
mode: rounded
|
||||
padding: { left: 1 right: 1 }
|
||||
show_empty: true
|
||||
trim: {
|
||||
methodology: wrapping
|
||||
wrapping_try_keep_words: true
|
||||
truncating_suffix: "..."
|
||||
}
|
||||
# `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.explore = {
|
||||
command_bar_text: { fg: "#C4C9C6" }
|
||||
highlight: { fg: black bg: yellow }
|
||||
status: {
|
||||
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.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.history = {
|
||||
file_format: sqlite
|
||||
isolation: false
|
||||
max_size: 100_000
|
||||
sync_on_enter: true
|
||||
}
|
||||
$env.config.show_banner = false
|
||||
|
||||
$env.config.completions = {
|
||||
algorithm: prefix
|
||||
case_sensitive: false
|
||||
partial: true
|
||||
quick: true
|
||||
external: {
|
||||
enable: true
|
||||
max_results: 100
|
||||
completer: {|tokens: list<string>|
|
||||
let expanded = scope aliases | where name == $tokens.0 | get --ignore-errors expansion.0
|
||||
$env.config.rm.always_trash = true
|
||||
|
||||
mut expanded_tokens = if $expanded != null and $tokens.0 != "cd" {
|
||||
$env.config.recursion_limit = 100
|
||||
|
||||
$env.config.edit_mode = "vi"
|
||||
$env.config.buffer_editor = "editor"
|
||||
|
||||
$env.config.cursor_shape.emacs = "line"
|
||||
$env.config.cursor_shape.vi_insert = "line"
|
||||
$env.config.cursor_shape.vi_normal = "block"
|
||||
|
||||
$env.config.completions.algorithm = "substring"
|
||||
$env.config.completions.sort = "smart"
|
||||
$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
|
||||
}
|
||||
|
||||
$expanded_tokens.0 = ($expanded_tokens.0 | str trim --left --char "^")
|
||||
$tokens.0 = $tokens.0 | str trim --left --char "^"
|
||||
|
||||
fish --command $"complete '--do-complete=($expanded_tokens | str join ' ')'"
|
||||
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.cursor_shape = {
|
||||
vi_insert: line
|
||||
vi_normal: block
|
||||
$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 = {
|
||||
command_not_found: {||}
|
||||
$env.config.hooks.env_change.PWD = [
|
||||
{|_before, after|
|
||||
ls $after
|
||||
| if ($in | length) < 20 { print }
|
||||
}
|
||||
]
|
||||
|
||||
display_output: {
|
||||
$env.config.hooks.display_output = {||
|
||||
tee { table --expand | print }
|
||||
| $env.last = $in
|
||||
| if $in != null { $env.last = $in }
|
||||
}
|
||||
|
||||
env_change: {}
|
||||
$env.config.hooks.command_not_found = []
|
||||
|
||||
pre_execution: [
|
||||
{
|
||||
let prompt = commandline | str trim
|
||||
|
||||
if ($prompt | is-empty) {
|
||||
return
|
||||
}
|
||||
|
||||
print $"(ansi title)($prompt) — nu(char bel)"
|
||||
}
|
||||
# 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
|
||||
"```"
|
||||
]
|
||||
|
||||
pre_prompt: []
|
||||
| str join (char nl)
|
||||
| clip copy --ansi
|
||||
}
|
||||
|
||||
# Retrieve the output of the last command.
|
||||
def _ []: nothing -> any {
|
||||
$env.last
|
||||
}
|
||||
|
||||
$env.config.menus = [
|
||||
$env.config.keybindings ++= [
|
||||
{
|
||||
marker: "| "
|
||||
name: completion_menu
|
||||
only_buffer_difference: false
|
||||
style: {
|
||||
description_text: yellow
|
||||
selected_text: green_reverse
|
||||
text: green
|
||||
}
|
||||
type: {
|
||||
col_padding: 2
|
||||
col_width: 20
|
||||
columns: 4
|
||||
layout: columnar
|
||||
}
|
||||
}
|
||||
{
|
||||
marker: "? "
|
||||
name: history_menu
|
||||
only_buffer_difference: true
|
||||
style: {
|
||||
description_text: yellow
|
||||
selected_text: green_reverse
|
||||
text: green
|
||||
}
|
||||
type: {
|
||||
layout: list
|
||||
page_size: 10
|
||||
}
|
||||
}
|
||||
{
|
||||
marker: "? "
|
||||
name: help_menu
|
||||
only_buffer_difference: true
|
||||
style: {
|
||||
description_text: yellow
|
||||
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.keybindings = [
|
||||
{
|
||||
name: copy_commandline
|
||||
modifier: alt
|
||||
name: copy_color_commandline
|
||||
modifier: control_alt
|
||||
keycode: char_c
|
||||
mode: [ vi_normal vi_insert ]
|
||||
mode: [ emacs vi_insert vi_normal ]
|
||||
event: {
|
||||
send: executehostcommand
|
||||
cmd: 'commandline | nu-highlight | $"```ansi\n($in)\n```" | copy'
|
||||
cmd: 'nu-keybind commandline-copy'
|
||||
}
|
||||
}
|
||||
{
|
||||
name: completion_menu
|
||||
modifier: none
|
||||
keycode: tab
|
||||
mode: [ vi_normal vi_insert ]
|
||||
event: {
|
||||
until: [
|
||||
{ send: menu name: completion_menu }
|
||||
{ send: menunext }
|
||||
{ edit: complete }
|
||||
]
|
||||
}
|
||||
}
|
||||
{
|
||||
name: history_menu
|
||||
modifier: control
|
||||
keycode: char_h
|
||||
mode: [ vi_insert vi_normal ]
|
||||
event: { send: menu name: history_menu }
|
||||
}
|
||||
{
|
||||
name: escape
|
||||
modifier: none
|
||||
keycode: escape
|
||||
mode: [ vi_normal vi_insert ]
|
||||
event: { send: esc }
|
||||
}
|
||||
{
|
||||
name: cancel_command
|
||||
modifier: control
|
||||
keycode: char_c
|
||||
mode: [ vi_normal vi_insert ]
|
||||
event: { send: ctrlc }
|
||||
}
|
||||
{
|
||||
name: quit_shell
|
||||
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
|
||||
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 }
|
||||
}
|
||||
]
|
||||
|
||||
$env.config.color_config.bool = {||
|
||||
if $in {
|
||||
"light_green_bold"
|
||||
} else {
|
||||
"light_red_bold"
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.color_config.string = {||
|
||||
if $in =~ "^(#|0x)[a-fA-F0-9]+$" {
|
||||
$in | str replace "0x" "#"
|
||||
} else {
|
||||
"white"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -31,20 +31,6 @@ in {
|
|||
};
|
||||
|
||||
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";
|
||||
|
|
|
@ -1,154 +1 @@
|
|||
$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
|
||||
# Crickets...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue