Add docs for jobs#1826
Conversation
You don't need to do that. @hustcer generates all the commands shortly after each release. |
|
i'll take a look when i get the chance |
132ikl
left a comment
There was a problem hiding this comment.
thanks for writing this up! sorry I just got around to this, I completely forgot about this one 😅
i have a few suggestions, let me know what you think
|
|
||
| 1. Using a third-party task management tools, like [pueue](https://github.com/Nukesor/pueue) | ||
| 2. Using a terminal multiplexer, like [tmux](https://github.com/tmux/tmux/wiki) or [zellij](https://zellij.dev/) | ||
| Nushell currently presents experimental support for thread-based background jobs. |
There was a problem hiding this comment.
could you move this line to above the "Spawning Jobs" header?
also, nitpick, but not sure about "presents" here, I think just "has" works fine
| ::: tip Note | ||
| Unlike many other shells, Nushell jobs are **not** separate processes, and are instead implemented | ||
| as background threads. An important side effect of that, is that all background jobs terminate once the shell process exits. | ||
| ::: |
There was a problem hiding this comment.
could you expand this into a proper (but brief) section? things I think we should specifically cover:
- interactive vs. non-interactive job killing behavior on Nushell exit
- explain that this is the rationale behind no
disown/ eventuallyjob dispatch
|
|
||
| ## Using Nu With Terminal Multiplexer | ||
| Active jobs can be queried with the [`job list`](/commands/docs/job_list.md) command, which returns a table with the information of the jobs which are currently executing. | ||
| Jobs can also be kiled/interrupted by using the [`job kill`](/commands/docs/job_kill.md) command, which interrupts the job's thread and kills all of the job's child processes: |
There was a problem hiding this comment.
| Jobs can also be kiled/interrupted by using the [`job kill`](/commands/docs/job_kill.md) command, which interrupts the job's thread and kills all of the job's child processes: | |
| Jobs can also be killed/interrupted by using the [`job kill`](/commands/docs/job_kill.md) command, which interrupts the job's thread and kills all of the job's child processes: |
| ## Unix Ctrl-Z | ||
|
|
||
| In unix targets (namely Linux and MacOS), Nushell's background job support also integrates with the Ctrl-Z feature | ||
| of terminals (more specifically, the `SIGTSTP` signal), which allows users to suspend foreground processes into background jobs. | ||
| When a running process is suspended, it is turned into a background job of type `frozen`. A frozen job can be reanimated into foreground with the | ||
| [`job unfreeze`](/commands/docs/job_unfreeze.md) command. | ||
|
|
||
| ``` | ||
| long_running_process | ||
| # (Ctrl-Z is pressed) | ||
|
|
||
| job list | ||
| # => ┏━━━┳━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━┓ | ||
| # => ┃ # ┃ id ┃ type ┃ pids ┃ | ||
| # => ┣━━━╋━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━┫ | ||
| # => ┃ 0 ┃ 1 ┃ frozen ┃ [list 1 items] ┃ | ||
| # => ┗━━━┻━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━┛ | ||
|
|
||
| job unfreeze 1 | ||
| # (process is brought back where it stopped) | ||
| ``` | ||
|
|
||
| If no job id is provided to `job unfreeze`, it will unfreeze the job id of the most recently frozen job. | ||
| Therefore, one can use `alias fg = job unfreeze` to achieve a behavior similar to the one of existing unix shells. |
There was a problem hiding this comment.
| ## Unix Ctrl-Z | |
| In unix targets (namely Linux and MacOS), Nushell's background job support also integrates with the Ctrl-Z feature | |
| of terminals (more specifically, the `SIGTSTP` signal), which allows users to suspend foreground processes into background jobs. | |
| When a running process is suspended, it is turned into a background job of type `frozen`. A frozen job can be reanimated into foreground with the | |
| [`job unfreeze`](/commands/docs/job_unfreeze.md) command. | |
| ``` | |
| long_running_process | |
| # (Ctrl-Z is pressed) | |
| job list | |
| # => ┏━━━┳━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━┓ | |
| # => ┃ # ┃ id ┃ type ┃ pids ┃ | |
| # => ┣━━━╋━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━┫ | |
| # => ┃ 0 ┃ 1 ┃ frozen ┃ [list 1 items] ┃ | |
| # => ┗━━━┻━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━┛ | |
| job unfreeze 1 | |
| # (process is brought back where it stopped) | |
| ``` | |
| If no job id is provided to `job unfreeze`, it will unfreeze the job id of the most recently frozen job. | |
| Therefore, one can use `alias fg = job unfreeze` to achieve a behavior similar to the one of existing unix shells. | |
| ## Job suspension | |
| On Unix targets, such as Linux and macOS, Nushell also supports suspending external commands using <kbd>Ctrl</kbd>+<kbd>Z</kbd>. When a running process is suspended, it is turned into a "frozen" background job: | |
| ```nu | |
| long_running_process # this starts running, then Ctrl+Z is pressed | |
| # => Job 1 is frozen | |
| job list | |
| # => ┏━━━┳━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━┓ | |
| # => ┃ # ┃ id ┃ type ┃ pids ┃ | |
| # => ┣━━━╋━━━━╋━━━━━━━━╋━━━━━━━━━━━━━━━━┫ | |
| # => ┃ 0 ┃ 1 ┃ frozen ┃ [list 1 items] ┃ | |
| # => ┗━━━┻━━━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━┛ | |
| ``` | |
| A frozen job can be brought back into foreground with the [`job unfreeze`](/commands/docs/job_unfreeze.md) command: | |
| ```nu | |
| job unfreeze | |
| # process is brought back where it stopped | |
| ``` | |
| ::: tip Tip | |
| For those familiar with other Unix shells, you can create an alias to emulate the behavior of the `fg` command: | |
| ```nu | |
| alias fg = job unfreeze | |
| ``` | |
| ::: | |
| By default, `job unfreeze` will unfreeze the most recently frozen job. However, you can also specify the id of a specific job to unfreeze: | |
| ```nu | |
| vim | |
| # => Job 1 is frozen | |
| long_running_process | |
| # => Job 2 is frozen | |
| job unfreeze 1 | |
| # we're back in vim | |
| ``` |
I tweaked this section to make it flow better, let me know what you think.
I'm not sure if we need to specify SIGTSTP specifically, I thought of moving it to a note/tip but I couldn't think of what that would look like.
There was a problem hiding this comment.
that looks good to me! (and I'm not even the reviewer)
There was a problem hiding this comment.
could we rename the file to background_jobs.md also?
|
|
||
| Unlike terminal multiplexer, you don't need to attach to multiple tmux sessions, and get task status easily. | ||
| job spawn { sleep 10sec; ' inevitable' | save --append status.txt } | ||
| ## => 1 |
|
|
||
| Here we provide a [nushell module](https://github.com/nushell/nu_scripts/tree/main/modules/background_task) that makes working with pueue easier. | ||
| open status.txt | ||
| ## => i am |
There was a problem hiding this comment.
| ## => i am | |
| # => i am |
| 4. Add a line to the `$nu.config-path` file: `use task.nu` | ||
| 5. Restart Nushell. | ||
| open status.txt | ||
| ## => i am inevitable |
There was a problem hiding this comment.
| ## => i am inevitable | |
| # => i am inevitable |
|
looks great, thanks! |
|
The sidebar config is under |
* Fix sidebar for background job article #1826 (comment) * Also fix the German sidebar This refers to the German translation of the old version Pre-builtin jobs
|

This adds a book entry for background job handling in nushell, with regard to how it is currently implemented.
Quick question: How do I generate the
.mdfiles for new commands such asjob spawn?