shell integration for zsh error "bad floating point constant"

25 views
Skip to first unread message

Nino Santa Rosa

unread,
Nov 19, 2022, 8:47:10 AM11/19/22
to iterm2-discuss
Hello,

by following the instructions to enable the shell integration by hand in zsh, when sourcing the .iterm2_shell_integration.zsh file I encountered the following error:
~/.iterm2_shell_integration.zsh:32: bad floating point constant

I solved it by editing the line number 32 from:
ver=$(printf "%.0f" $(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | sed -e 's/ //g'))

To:
ver=$(printf "%d" $(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | sed -e 's/ //g' | awk -F  '.'  '{print $1}'))

Then, I also noticed that on GitHub the zsh file is different in that point...
 

Richard Mitchell

unread,
Nov 19, 2022, 11:55:09 AM11/19/22
to iterm2-discuss
There must be a reason ver can't be simplified to:

ver=$(printf "%d" $(sw_vers -productVersion ))

Nino Santa Rosa

unread,
Nov 19, 2022, 12:11:16 PM11/19/22
to iterm2-discuss
What do you mean? My fix does not do that. My fix consists in just take the "main"  number of the product version. For instance, if you do:
sw_vers -productVersion 
You obtain a product version having the format of three number having a dot as a separator, e.g., 13.0.1
The line that give me the error was wrong because it would have work for a floating point number, i.e., two numbers separated by a dot, e.g., 13.0, to reduce it in an integer by just taking its integer part through %.0f and obtain, for example, 13.
This is exactly what my fix does through awk. It takes the first one of the three numbers separated by the dot, i.e., 13, which is an integer so that %d is enough.

Richard Mitchell

unread,
Nov 19, 2022, 12:35:21 PM11/19/22
to iterm2-discuss
Sorry, I was questioning grepping for ProductVersion when sw_vers can output only that.  I didn't realize the problem was with an a.b.c style version number.  Does this work there ? (I'm not on the latest OS)

ver=$printf "%d" $(sw_vers -productVersion | sed 's/\..*//')

Nino Santa Rosa

unread,
Nov 19, 2022, 12:46:25 PM11/19/22
to iterm2-discuss
Yeah, it works too :)
Reply all
Reply to author
Forward
0 new messages