Last active
March 9, 2025 10:10
-
-
Save q60/9f3f64e50495d7b25b253b0f80cc49c2 to your computer and use it in GitHub Desktop.
nushell fg - job unfreeze but better
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module fg-jobs { | |
export def fg [ | |
id?: int@"jobs completions" # job id | |
] { | |
let jobs = jobs | |
match $id { | |
null => { | |
$jobs | |
} | |
_ => { | |
job unfreeze $id | |
} | |
} | |
} | |
def "jobs completions" [] { | |
jobs | |
| each { |row| | |
{value: $row.id, description: $row.command, style: yellow} | |
} | |
} | |
def jobs [] { | |
job list | |
| update pids { |row| $row.pids | first } | |
| rename --column {pids: pid} | |
| insert command { |row| add-command $row } | |
| move command --after id | |
| sort-by id | |
} | |
def add-command [row: record] { | |
let command =| | |
ps -l | |
| where pid == $row.pid | |
| get command | |
| first | |
| split row " " | |
$"($command.0 | path basename) ($command | skip 1 | str join ' ')" | |
| str trim | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment