miquella / vaulted

Spawning and storage of secure environments
MIT License
253 stars 30 forks source link

Support the ability to report back the remaining time #158

Open drusellers opened 4 years ago

drusellers commented 4 years ago

I am currently using a shell script to calculate the remaining time of my vaulted session. It would be nice if there was a command that could read the known ENV var and report back the amount of time left.

say

vaulted time-remaining then I can use that value in my various prompts.

function _vaulted_status() {
  if [ -z ${VAULTED_ENV+x} ]; then
    echo ""
  else
    current_time=$(date +"%s")
    expire_time=$(date -j -f "%C%y-%m-%dT%H:%M:%SZ" "${VAULTED_ENV_EXPIRATION}" +"%s")
    secs=$(echo "$expire_time - $current_time" | bc)
    if (( secs > 0 )); then
      remaining="($(printf '%dh:%dm:%ds\n' $(($secs/3600)) $(($secs%3600/60)) $(($secs%60))))"
    else
      remaining="expired"
    fi
    echo -n "[$VAULTED_ENV $remaining] "
  fi
}
drusellers commented 4 years ago

Could help with #107 and #134