Fresh start to remove subtree artifacts

This commit is contained in:
2025-01-22 12:56:39 +00:00
parent a42f4061af
commit dad55ecd26
44 changed files with 7651 additions and 1920 deletions
-3
View File
@@ -33,9 +33,6 @@ export alias bashpoem = poetry run bash
export alias nupoem = poetry run nu
export alias jupyterpoem = poetry run jupyter
# Aliases for custom git commands
export alias git-ammend = git commit -a --amend -C HEAD
# Who even uses vim or *especially* vi in this day and age?
export alias vim = nvim
export alias vi = nvim
@@ -12,7 +12,6 @@ source ~/.config/nushell/nu_scripts/custom-completions/man/man-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/mix/mix-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/nano/nano-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/nix/nix-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/pass/pass-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/poetry/poetry-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/pre-commit/pre-commit-completions.nu
source ~/.config/nushell/nu_scripts/custom-completions/pytest/pytest-completions.nu
-2
View File
@@ -11,7 +11,5 @@ source ~/.config/nushell/nu_scripts.nu
source ~/.config/nushell/completions/atuin.nu
source ~/.config/nushell/completions/zoxide.nu
source ~/.config/nushell/completions/nu_scripts.nu
# import nushell libs
use task.nu
# Finally, we run a system info fetch
sysfetch
-4
View File
@@ -71,10 +71,6 @@ $env.LESS_TERMCAP_so = (ansi --escape "01;44;36m") # begin standout-mode (botto
$env.LESS_TERMCAP_se = (ansi --escape "0m") # end standout-mode
$env.LESS_TERMCAP_us = (ansi --escape "00;36m") # begin underline
$env.LESS_TERMCAP_ue = (ansi --escape "0m") # end underline
# Set a custom copy of TERM so that shells under multiplexors behave correctly
if not ("MAIN_TERM" in $env) {
$env.MAIN_TERM = $env.TERM
}
# Finally, add session path variables
$env.PATH = (
+1 -1
View File
@@ -29,7 +29,7 @@ export def main [] {
PWD: [
{|before, after| # This hook runs onefetch when the current directory is a git repository
if ".git\n" in ($after | ls -a | str join) {
print (^onefetch)
print (^onefetch --nerd-fonts)
}
},
{||
+32 -49
View File
@@ -1,62 +1,45 @@
export def create_left_prompt [] -> string {
canonicalize_linefeeds (
^starship prompt
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
def get_env [s: string]: string -> string {
try { $env | get --ignore-errors $s } catch { "" }
}
export def create_right_prompt [] -> string {
canonicalize_linefeeds (
^starship prompt
--right
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
export def create_left_prompt []: nothing -> string {
^starship prompt --cmd-duration (get_env "CMD_DURATION_MS") --status (get_env "LAST_EXIT_CODE") --terminal-width (term size).columns
}
export def create_continuation_prompt [] -> string {
canonicalize_linefeeds (
^starship prompt
--continuation
--cmd-duration $env.CMD_DURATION_MS
$"--status=($env.LAST_EXIT_CODE)"
--terminal-width (term size).columns
)
export def create_right_prompt []: nothing -> string {
^starship prompt --right --cmd-duration (get_env "CMD_DURATION_MS") --status (get_env "LAST_EXIT_CODE") --terminal-width (term size).columns
}
def parse_ms_to_human_readable [ms: string] -> string {
let $time_in_ms = $ms | into int;
if $time_in_ms < 1000 {
$"($time_in_ms | into string)ms"
} else if $time_in_ms < 1000 * 60 {
$"(($time_in_ms / 1000) | into string --decimals 2)s"
} else if $time_in_ms < 1000 * 60 * 60 {
$"(($time_in_ms / (1000 * 60)) | into string --decimals 2)m"
} else if $time_in_ms < 1000 * 60 * 60 * 24 {
$"(($time_in_ms / (1000 * 60 * 60)) | into string --decimals 2)h"
export def create_continuation_prompt []: nothing -> string {
^starship prompt --continuation --cmd-duration (get_env "CMD_DURATION_MS") --status (get_env "LAST_EXIT_CODE") --terminal-width (term size).columns
}
def parse_ms_to_human_readable [ms: string]: string -> string {
if $ms == "" {
$ms
} else {
$"(($time_in_ms // (1000 * 60 * 60 * 24)) | into string)d/(parse_ms_to_human_readable ($time_in_ms mod (1000 * 60 * 60 * 24)))"
} | into string
}
export def create_transient_prompt_left [] -> string {
if $env.LAST_EXIT_CODE == 0 {
$"(ansi green_bold)(ansi reset)"
} else {
$"(ansi red_bold)(ansi reset)"
let $time_in_ms = $ms | into int;
if $time_in_ms < 1000 {
$"($time_in_ms | into string)ms"
} else if $time_in_ms < 1000 * 60 {
$"(($time_in_ms / 1000) | into string --decimals 2)s"
} else if $time_in_ms < 1000 * 60 * 60 {
$"(($time_in_ms / (1000 * 60)) | into string --decimals 2)m"
} else if $time_in_ms < 1000 * 60 * 60 * 24 {
$"(($time_in_ms / (1000 * 60 * 60)) | into string --decimals 2)h"
} else {
$"(($time_in_ms // (1000 * 60 * 60 * 24)) | into string)d/(parse_ms_to_human_readable ($time_in_ms mod (1000 * 60 * 60 * 24)))"
} | into string
}
}
export def create_transient_prompt_indicator [] -> string {
$"(ansi blue_bold)(parse_ms_to_human_readable $env.CMD_DURATION_MS) (if $env.LAST_EXIT_CODE == 0 { ansi green_bold } else { ansi red_bold })(ansi reset) "
}
def canonicalize_linefeeds (x: string) -> string {
if ("OS" in $env) and ($env.OS == "Windows_NT") {
$x | str replace "\n" "\r\n"
export def create_transient_prompt_left []: nothing -> string {
if (get_env "LAST_EXIT_CODE") == 0 {
$"(ansi green_bold)󱔳(ansi reset)"
} else {
$x
$"(ansi red_bold)󱔷(ansi reset)"
}
}
export def create_transient_prompt_indicator []: nothing -> string {
$"(ansi blue_bold) 󰔛 (parse_ms_to_human_readable (get_env "CMD_DURATION_MS")) (if (get_env "LAST_EXIT_CODE") == 0 { ansi green_bold } else { ansi red_bold })(ansi reset) "
}
-458
View File
@@ -1,458 +0,0 @@
export module mod {
export def main [] {"
Subcommands:
clean: Remove tasks from the status list.
edit: Edit the command, path or label of a stashed or queued task.
group: Add or remove groups.
kill: Kill specific running tasks or whole task groups.
log: Display the output of tasks.
pause: Either pause a running tasks or a specific groups of tasks.
queue: Queue stashed tasks for execution.
remove: Remove tasks from the queue.
restart: Restart failed or successful task(s).
send: Send something to a task. Useful for sending confirmations such as 'y' or 'n'.
set-parallel-limit: Set the maximum parallel tasks for a group.
shutdown: Shutdown pueue and thus this module.
spawn: Spawn a task to run in the background, even when the shell is closed.
start: Resume operation of specific tasks or groups of tasks.
stash: Stash a task that is not currently running.
status: Display the current status of all tasks.
switch: Switches the queue position of two tasks.
wait: Wait until the provided tasks are finished.
"}
# Spawn a task to run in the background, even when the shell is closed.
#
# Note that a fresh Nushell interpreter is spawned to execute the
# given task, so it won't inherit the current scope's variables,
# custom commands and alias definitions.
#
# It will only inherit environment variables which can be converted to a string.
#
# Note that the closure can't take arguments.
#
# Example usage: task spawn { echo "Hello, World!" }
export def spawn [
command: closure # The closure to run.
--working-directory (-w): directory # Specify the working directory the task will be run in.
--immediate (-i) # Immediately start the task.
--stashed (-s) # Create the task in Stashed state. Useful to avoid immediate execution if the queue is empty
--delay (-d): duration # Queue the task for execution only after the duration.
--group (-g): string # The group to spawn the task under.
--after (-a): int # Start the task once all specified tasks have successfully finished. As soon as one of the dependencies fails, this task will fail as well.
--priority (-o): string # Start this task with a higher priority. The higher the number, the faster it will be processed.
--label (-l): string # Label the task. This string will be shown in the `status` column of `task status`.
] -> int {
mut args = []
if $working_directory != null {
$args = ($args | prepend ["--working-directory", $working_directory])
}
if $immediate {
$args = ($args | prepend "--immediate")
}
if $stashed {
$args = ($args | prepend "--stashed")
}
if $delay != null {
$args = ($args | prepend ["--delay" ($delay | format duration sec | parse "{secs} {_}" | get 0.secs)])
}
if $group != null {
$args = ($args | prepend ["--group" $group])
}
if $after != null {
$args = ($args | prepend ["--after" $after])
}
if $priority != null {
$args = ($args | prepend ["--priority" $priority])
}
if $label != null {
$args = ($args | prepend ["--label" $label])
}
let source_path = mktemp --tmpdir --suffix "-nu-task"
(
view source $command
| str trim --left --char "{"
| str trim --right --char "}"
)
| save --force $source_path
(pueue add --print-task-id ...$args $"nu --config '($nu.config-path)' --env-config '($nu.env-path)' ($source_path)")
}
# Remove tasks from the queue.
# Running or paused tasks need to be killed first.
export def remove [
...ids: int # IDs of the tasks to remove from the status list.
] {
pueue remove ...$ids
}
# Switches the queue position of two tasks.
# Only works for queued or stashed tasks.
export def switch [
task_id_1: int # The first task ID.
task_id_2: int # The second task ID.
] {
pueue switch $task_id_1 $task_id_2
}
# Stash a task that is not currently running.
#
# Stashed tasks won't be automatically started.
# You will have to queue them or start them by hand.
export def stash [
...ids: int # IDs of the tasks to stash.
] {
pueue stash ...$ids
}
# Queue stashed tasks for execution.
export def queue [
...ids: int # IDs of the tasks to queue.
--delay (-d): duration # Queue only after the specified delay.
] {
let args = if $delay != null {
["--delay" ($delay | format duration sec | parse '{secs} {_}' | get 0.secs)]
} else {
[]
}
pueue enqueue ...$args ...$ids
}
# Resume operation of specific tasks or groups of tasks.
#
# By default, this resumes the default group and all its tasks.
# It can also be used force-start specific tasks or start whole groups.
export def start [
...ids: int # IDs of the tasks to start. By default all the tasks in the default group will be started.
--group (-g): string # Resume a specific group and all paused tasks in it. The group will be set to running and its paused tasks will be resumed.
--all (-a) # Resume all groups. All groups will be set to running and paused tasks will be resumed.
] {
mut args = []
if $group != null {
$args = ($args | prepend ["--group" $group])
}
if $all {
$args = ($args | prepend "--all")
}
pueue start ...$args
}
# Restart failed or successful task(s).
#
# By default, identical tasks will be created and
# enqueued, but it's possible to restart in-place.
#
# You can also edit a few properties, such as
# the path and the command of the task, before restarting.
export def restart [
...ids: int # IDs of the tasks to restart.
--all-failed (-a) # Restart all failed tasks across all groups. Nice to use in combination with `--in-place/i`.
--failed-in-group (-g): string # Like `--all-failed`, but only restart tasks failed tasks of a specific group. The group will be set to running and its paused tasks will be resumed.
--start-immediately (-k) # Immediately start the tasks, no matter how many open slots there are. This will ignore any dependencies tasks may have.
--stashed (-s) # Set the restarted task to a "Stashed" state. Useful to avoid immediate execution.
--in-place (-i) # Restart the tasks by reusing the already existing tasks.
--not-in-place (-n) # Opposite of `--in-place`. This is already the default unless you have `restart_in_place` set to true.
--edit (-e) # Edit the tasks' commands before restarting
--edit-path (-p) # Edit the tasks' paths before restarting
--edit-label (-l) # Edit the tasks' labels before restarting
] {
mut args = []
if $all_failed {
$args = ($args | prepend "--all-failed")
}
if $failed_in_group != null {
$args = ($args | prepend "--failed-in-group")
}
if $start_immediately {
$args = ($args | prepend "--start-immediately")
}
if $stashed {
$args = ($args | prepend "--stashed")
}
if $in_place {
$args = ($args | prepend "--in-place")
}
if $not_in_place {
$args = ($args | prepend "--not-in-place")
}
if $edit {
$args = ($args | prepend "--edit")
}
if $edit_path {
$args = ($args | prepend "--edit-path")
}
if $edit_label {
$args = ($args | prepend "--edit-label")
}
pueue restart ...$args ...$ids
}
# Either pause a running tasks or a specific groups of tasks.
#
# By default, pauses the default group and all its tasks.
#
# A paused group won't start any new tasks automatically.
export def pause [
...ids: int # IDs of the tasks to pause.
--group (-g) # Pause a specific group
--all (-a) # Pause all groups.
--wait (-w) # Only pause the specified group and let already running tasks finish by themselves
] {
mut args = []
if $group != null {
$args = ($args | prepend "--group")
}
if $all != null {
$args = ($args | prepend "--all")
}
if $wait != null {
$args = ($args | prepend "--wait")
}
pueue pause ...$args ...$ids
}
# Kill specific running tasks or whole task groups.
#
# Kills all tasks of the default group when no ids or a specific group are provided.
export def kill [
...ids: int # IDs of the tasks to kill.
--group (-g): string # Kill all running tasks in a group. This also pauses the group.
--all (-a) # Kill all running tasks across ALL groups. This also pauses all groups.
--signal (-s): string # Send a UNIX signal instead of simply killing the process. DISCLAIMER: This bypasses Pueue's process handling logic! You might enter weird invalid states, use at your own descretion.
] {
mut args = []
if $group != null {
$args = ($args | prepend ["--group" $group])
}
if $all {
$args = ($args | prepend "--all")
}
if $signal != null {
$args = ($args | prepend ["--signal" $signal])
}
pueue kill ...$args ...$ids
}
# Send something to a task. Useful for sending confirmations such as "y\n".
export def send [
id: int # ID of the task to send something to.
input: string # The input that should be sent to the process.
] {
pueue send $id $input
}
# Edit the command, path or label of a stashed or queued task.
#
# By default only the command is edited.
#
# Multiple properties can be added in one go.
export def edit [
id: int # ID of the task to edit.
--command (-c) # Edit the task's command
--path (-p) # Edit the task's path
--label (-l) # Edit the task's label
] {
mut args = []
if $command {
$args = ($args | prepend "--command")
}
if $path {
$args = ($args | prepend "--path")
}
if $label {
$args = ($args | prepend "--label")
}
pueue edit ...$args $id
}
# Use this to add or remove groups.
#
# By default, this will simply display all known groups.
export def group [] {
pueue group --json | from json
}
# Create a new group with a name.
export def "group add" [
name: string # The name of the new group.
--parallel (-p): int # The amount of parallel tasks the group can run at one time.
] {
let args = if $parallel != null {
["--parallel" $parallel]
} else {
[]
}
pueue group add ...$args $name
}
# Remove a group with a name.
export def "group remove" [
name: string # The name of the group to be removed.
] {
pueue group remove $name
}
# Display the current status of all tasks.
export def status [
--detailed (-d) # Return a table with more detailed information.
] {
let output = (
pueue status --json
| from json
| get tasks
| transpose --ignore-titles status
| flatten
)
# TODO: Rename the Done column to done.
if not $detailed {
$output | select id label group Done? status? start? end?
} else {
$output
}
}
# Display the output of tasks.
#
# Only the last few lines will be shown by default for multiple tasks.
# If you want to follow the output, use `--tail/-t`.
export def log [
...ids: int # The tasks to check the outputs of.
--last (-l): int # Only print the last N lines of each task's output. This is done by default if you're looking at multiple tasks.
--tail (-t) # Follow the output as it is printing. Only works with 1 task. When used in conjunction with `--last`, the last N lines will be printed before starting to wait for output.
--detailed (-d) # Include all fields, don't simplify output.
] {
def process_raw [raw: string] {
let full = (
$raw
| from json
| transpose -i info
| flatten --all
| flatten --all
)
if $detailed {
$full
} else {
$full | select id label group Done? status? start? end?
}
}
if (($ids | length) == 1) {
if $tail {
let args = if $last != null {
["--lines" $last]
} else {
[]
}
pueue follow ...$ids
} else {
let args = if $last != null {
["--lines" $last]
} else {
[]
}
process_raw (pueue log --full --json ...$args ...$ids)
| first
}
} else {
if $tail {
echo $"(ansi red)--tail can only be used with one task.(ansi reset)"
return
}
let args = if $last != null {
["--lines" $last]
} else {
[]
}
process_raw (pueue log --full --json ...$args ...$ids)
}
}
# Wait until the provided tasks are finished.
#
# This is like join() or await in many languages.
export def wait [
...ids: int # IDs of the tasks to wait for.
--group (-g): string # Wait for all tasks in a specific group.
--all (-a) # Wait for all tasks across all groups and the default group.
--quiet (-q) # Don't show any log output while waiting.
--status (-s): string # Wait for tasks to reach a specific task status.
] {
mut args = []
if $group != null {
$args = ($args | prepend ["--group" $group])
}
if $all {
$args = ($args | prepend $all)
}
if $quiet {
$args = ($args | prepend $quiet)
}
if $status != null {
$args = ($args | prepend ["--status" $status])
}
pueue wait ...$args ...$ids
}
# Remove tasks from the status list.
export def clean [
--successful-only (-s) # Only clean tasks that finished successfully
--group (-g): string # Only clean tasks of a specific group
] {
mut args = []
if $successful_only {
$args = ($args | prepend "--successful-only")
}
if $group != null {
$args = ($args | prepend ["--group" $group])
}
pueue clean ...$args
}
# Shutdown pueue and thus this module.
export def shutdown [] {
pueue shutdown
}
# Set the maximum parallel tasks for a group.
#
# Note that no tasks will be stopped if the number is lowered.
# The limit only applies when schelduing.
export def set-parallel-limit [
max: int # The maximum parallel tasks allowed for a group when schelduing.
--group (-g): string # The group to set the limit for. By default this is `default`.
] {
let args = if $group != null {
["--group" $group]
} else {
[]
}
pueue parallel ...$args $max
}
}
+6 -6
View File
@@ -1,10 +1,10 @@
export def 'exists' [ app: string ] -> bool {
export def 'exists' [ app ]: string -> bool {
not (which $app | is-empty)
}
export def 'sysfetch' [] {
export def 'sysfetch' []: nothing -> nothing {
if (exists fastfetch) {
if ("MAIN_TERM" in $env) and ("kitty" in $env.MAIN_TERM) and ($"($env.HOME)/.config/fastfetch/kitty.jsonc" | path exists) {
if (("kitty" in $env.TERM) or ("ghostty" in $env.TERM)) and ($"($env.HOME)/.config/fastfetch/kitty.jsonc" | path exists) {
fastfetch --load-config $"($env.HOME)/.config/fastfetch/kitty.jsonc"
} else {
fastfetch
@@ -23,7 +23,7 @@ export def 'sysfetch' [] {
}
}
export def 'register-plugins' [] {
export def 'register-plugins' []: nothing -> nothing {
for plugin_dir in $env.NU_PLUGIN_DIRS {
for plugin_path in (ls $"($env.NU_PLUGIN_DIRS.0)/nu_plugin_*").name {
nu -c $"register ($plugin_path)"
@@ -31,7 +31,7 @@ export def 'register-plugins' [] {
}
}
export def 'build-plugins' [] {
export def 'build-plugins' []: nothing -> nothing {
let curdir = pwd
let plugin_dir = $env.NU_PLUGIN_DIRS.0
cd $plugin_dir
@@ -40,7 +40,7 @@ export def 'build-plugins' [] {
register-plugins
}
export def 'install-default-plugins' [] {
export def 'install-default-plugins' []: nothing -> nothing {
[ nu_plugin_inc
nu_plugin_polars
# nu_plugin_gstat