Open rmpel opened 5 years ago
We already have a test in Next
for this situation:
function __p9k_detect_os() {
typeset -g __P9K_OS __P9K_OS_ID
case $(uname) in
Darwin)
__P9K_OS='OSX'
__P9K_OS_ID="$(uname -r)"
[[ "$(which stat)" != "/usr/bin/stat" ]] && __P9K_OSX_COREUTILS=true || __P9K_OSX_COREUTILS=false
;;
...
Noice! thanks :)
Describe Your Issue
When using the prompt-part 'public_ip' the first display is ok (it will refresh the IP and cache in /tmp/p9k_public_ip). The second time the theme will
stat -f "%m" /tmp/p9k_public_ip
to find the last-modified stamp. On macOS with GNU CoreUtils installed, this will fail.Have you tried to debug or fix it?
disabling the
stat -f
version and using thedate -r
version solves the problemin function prompt_public_ip:
if [[ "$OS" == "OSX" ]]; then
timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE)))
else
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
fi
becomes
#if [[ "$OS" == "OSX" ]]; then
# timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE)))
# else
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
# fi
or
if [[ "$OS" == "OSX" ]] && [[ "gnubin" != "$(basename $(dirname $(which stat)))" ]]; then
timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE)))
else
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
fi
this last one tests stat for being in the
gnubin
subfolder, but I doubt this is universal over all macOS version and/or brew versions and/or coreutils versionsI know this is is a one in thousands situation, but at least now it is known and people with the same problem know how to fix it :)
Environment Information
This information will help us understand your configuration.
zsh --version
to see this. zsh 5.7.1 (x86_64-apple-darwin19.0)GNU CoreUtils installed with
brew install coreutils
$ which stat
/usr/local/opt/coreutils/libexec/gnubin/stat