nu_command/experimental/
job_id.rs1use nu_engine::command_prelude::*;
2
3#[derive(Clone)]
4pub struct JobId;
5
6impl Command for JobId {
7 fn name(&self) -> &str {
8 "job id"
9 }
10
11 fn description(&self) -> &str {
12 "Get id of current job."
13 }
14
15 fn extra_description(&self) -> &str {
16 "This command returns the job id for the current background job.
17The special id 0 indicates that this command was not called from a background job thread, and
18was instead spawned by main nushell execution thread."
19 }
20
21 fn signature(&self) -> nu_protocol::Signature {
22 Signature::build("job id")
23 .category(Category::Experimental)
24 .input_output_types(vec![(Type::Nothing, Type::Int)])
25 }
26
27 fn search_terms(&self) -> Vec<&str> {
28 vec!["self", "this", "my-id", "this-id"]
29 }
30
31 fn run(
32 &self,
33 engine_state: &EngineState,
34 _stack: &mut Stack,
35 call: &Call,
36 _input: PipelineData,
37 ) -> Result<PipelineData, ShellError> {
38 let head = call.head;
39
40 Ok(Value::int(engine_state.current_job.id.get() as i64, head).into_pipeline_data())
41 }
42
43 fn examples(&self) -> Vec<Example<'_>> {
44 vec![Example {
45 example: "job id",
46 description: "Get id of current job",
47 result: None,
48 }]
49 }
50}