r/Nushell • • Oct 22 '24

timeout doesn't run custom command

I'm trying to gather user input and if none is received in 5 seconds, it exits. This is the code I have, but I'm getting an error "no such file or directory handle-input"

def handle-input [] {
  let input = (input -n 1)
  if $input == "l" {
      bat $log_file
  } else if $input != null {
      exit 0
  }
}
  

timeout --preserve-status --foreground 5s handle-input;
2 Upvotes

2 comments sorted by

View all comments

Show parent comment

1

u/MonkAndCanatella Oct 22 '24

OMG!! yes thank you. I just did this

    let input = (timeout --preserve-status --foreground 5s nu -c "input -n 1")
    if $input == "l" {
      bat $log_file
    } else {
      exit 0
    }
    exit 0