Skip to main content
  1. Blog/

making taskwarrior better with Nushell

·218 words·2 mins

Works with:

❯ : nu --version
0.82.0
  1. run
  2. work
  3. open window right now!

normally

task add run task add work task add open window due:now

[run work [open window due:now]] | each {task add $in}

Custom command

def nt [] {
    each {task add $in}
}

Then we can simply do

[run work [open window due:now]] | nt

We can also exptend the custom command to accept a list af new tasks as a positional parameter:


def nt [tasks?: list] {
  if ($in | describe) == nothing {
    $tasks | each { task add $in }
  } else {
    each { task add $in}
  }
}

Then we could write:

nt [run work [open window due:now]]

And get the same result.

And finally taking into consideration if no list is provided and also adding a biot of doucmentation to the command:

# Pipe in the list of tasks or give the list as a positional parameter
# Format: [taskone tasktwo [task three due:now]]
def nt [tasks?: list] {
  if ($in | describe) == nothing {
    if ($tasks | describe) == nothing {
      'Pipe in the list of task or give the list as a positional parameter'
    } else {
      $tasks | each { task add $in }
    }
  } else {
    each { task add $in}
  }
}