4 deleted 3 characters in body
source | link

This seems to work for me to tell whether the timeout is reached:

sudo-expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo, we're still able to tell if a password was required or not.

Used like in yours (with a few simplifications):

sudo-warning()
  if sudo-expired; then
    echo '%F{blue}🔒%f'
  else
    echo '%F{red}🔓%f'
  fi

TMOUT=10
TRAPALRM() zle reset-prompt
set -o promptsubst
PS1='%n$(sudo-warning) '

This seems to work for me to tell whether the timeout is reached:

sudo-expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo, we're still able to tell if a password was required or not.

Used like in yours (with a few simplifications):

sudo-warning()
  if sudo-expired; then
    echo '%F{blue}🔒%f'
  else
    echo '%F{red}🔓%f'
  fi

TMOUT=10
TRAPALRM() zle reset-prompt
set -o promptsubst
PS1='%n$(sudo-warning) '

This seems to work for me to tell whether the timeout is reached:

sudo-expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit kill sudo, we're still able to tell if a password was required or not.

Used like in yours (with a few simplifications):

sudo-warning()
  if sudo-expired; then
    echo '%F{blue}🔒%f'
  else
    echo '%F{red}🔓%f'
  fi

TMOUT=10
TRAPALRM() zle reset-prompt
set -o promptsubst
PS1='%n$(sudo-warning) '
3 added 285 characters in body
source | link

This seems to work for me to tell whether the timeout is reached:

sudo_expiredsudo-expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo, we're still able to tell if a password was required or not.

Used like in yours (with a few simplifications):

sudo-warning()
  if sudo-expired; then
    echo '%F{blue}🔒%f'
  else
    echo '%F{red}🔓%f'
  fi

TMOUT=10
TRAPALRM() zle reset-prompt
set -o promptsubst
PS1='%n$(sudo-warning) '

This seems to work for me to tell whether the timeout is reached:

sudo_expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo, we're still able to tell if a password was required or not.

This seems to work for me to tell whether the timeout is reached:

sudo-expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo, we're still able to tell if a password was required or not.

Used like in yours (with a few simplifications):

sudo-warning()
  if sudo-expired; then
    echo '%F{blue}🔒%f'
  else
    echo '%F{red}🔓%f'
  fi

TMOUT=10
TRAPALRM() zle reset-prompt
set -o promptsubst
PS1='%n$(sudo-warning) '
2 added 1 character in body
source | link

This seems to work for me to tell whether the timeout is reached:

sudo_expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to waitfail, but as long as Iwe don't let that limit to kill sudo, we're still able to tell if a password was required or not.

This seems to work for me to tell whether the timeout is reached:

sudo_expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to wait, but as long as I don't let that limit to kill sudo, we're still able to tell if a password was required or not.

This seems to work for me to tell whether the timeout is reached:

sudo_expired() [[ $(
  trap "" XFSZ
  limit filesize 0
  LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]

That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo, we're still able to tell if a password was required or not.

1
source | link