Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

public_ip on MacOS with GNU CoreUtils installed problem with file-stat #1373

Open
rmpel opened this issue Oct 11, 2019 · 2 comments
Open

public_ip on MacOS with GNU CoreUtils installed problem with file-stat #1373

rmpel opened this issue Oct 11, 2019 · 2 comments

Comments

@rmpel
Copy link

rmpel commented Oct 11, 2019

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.

prompt_public_ip:15: bad math expression: operand expected at `"/tmp/p9k_...'

Have you tried to debug or fix it?

disabling the stat -f version and using the date -r version solves the problem

in 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 versions

I 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.

  • What version of ZSH are you using? You can use zsh --version to see this.
    zsh 5.7.1 (x86_64-apple-darwin19.0)
  • Do you use a ZSH framework (e.g., Oh-My-ZSH, Antigen)?
    Oh-My-ZSH
  • How did you install P9k (cloning the repo, by tarball, a package from your OS, etc.,)?
    git clone
  • What version of P9k are you using?
    v0.6.7
  • Which terminal emulator do you use?
    macOS built-in Terminal.app

GNU CoreUtils installed with brew install coreutils
$ which stat
/usr/local/opt/coreutils/libexec/gnubin/stat

@onaforeignshore
Copy link
Contributor

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
    ;;
    ...

@rmpel
Copy link
Author

rmpel commented Oct 14, 2019

Noice! thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants