mirror of
https://github.com/RGBCube/ncc
synced 2025-07-29 02:57:44 +00:00
nushell: add thought dump editing commands
This commit is contained in:
parent
8bea87cf0d
commit
8829a7c9e1
1 changed files with 57 additions and 0 deletions
|
@ -15,13 +15,70 @@ def today []: nothing -> string {
|
||||||
date now | format date "%Y-%m-%d"
|
date now | format date "%Y-%m-%d"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Create a directory and cd into it.
|
||||||
def --env mc [path: path]: nothing -> nothing {
|
def --env mc [path: path]: nothing -> nothing {
|
||||||
mkdir $path
|
mkdir $path
|
||||||
cd $path
|
cd $path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Create a directory, cd into it and initialize version control.
|
||||||
def --env mcg [path: path]: nothing -> nothing {
|
def --env mcg [path: path]: nothing -> nothing {
|
||||||
mkdir $path
|
mkdir $path
|
||||||
cd $path
|
cd $path
|
||||||
jj git init --colocate
|
jj git init --colocate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let site_path = glob "~" | path join "projects" "site"
|
||||||
|
|
||||||
|
# Edit a thought dump.
|
||||||
|
def "dump ed" [
|
||||||
|
path: string # The thought dump to edit. Namespaced using '.', does not include file extension.
|
||||||
|
]: nothing -> nothing {
|
||||||
|
let dump_path = $site_path | path join "site" "dump" ...($path | split row ".") | $in + ".md"
|
||||||
|
|
||||||
|
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)"
|
||||||
|
dump rm ($dump_path | str substring 0..<-3)
|
||||||
|
} else if $old_dump_hash == (open $dump_path | hash sha256) {
|
||||||
|
print $"(ansi yellow)thought dump was not touched(ansi reset)"
|
||||||
|
} else {
|
||||||
|
cd $"(ansi magenta)thought dump was edited(ansi reset)"
|
||||||
|
print $"(ansi green)deploying...(ansi reset)"
|
||||||
|
|
||||||
|
cd $site_path
|
||||||
|
./apply.nu
|
||||||
|
cd -
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Delete a thought dump.
|
||||||
|
def "dump rm" [
|
||||||
|
path: string # The thought dump to edit. Namespaced using '.', does not include file extension.
|
||||||
|
]: nothing -> nothing {
|
||||||
|
print $path
|
||||||
|
let dump_path = $site_path | path join "site" "dump" ...($path | split row ".") | $in + ".md"
|
||||||
|
let parent_path = $dump_path | path parse | get parent
|
||||||
|
|
||||||
|
print $"(ansi red)deleting thought dump...(ansi reset)"
|
||||||
|
rm $dump_path
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
print $"(ansi green)deploying...(ansi reset)"
|
||||||
|
|
||||||
|
cd $site_path
|
||||||
|
./apply.nu
|
||||||
|
cd -
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue