From 4223b3da68fc301710b4ef07bc5efa4c240bbf0b Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 8 Jan 2017 18:31:55 -0800 Subject: [PATCH] deal with BC_LINE_LENGTH not being honored FreeBSD 12, Dragonfly BSD, and presumably other BSDs don't recognize the BC_LINE_LENGTH env var and might split the output at 70 chars. Fixes #3414 --- share/functions/math.fish | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/share/functions/math.fish b/share/functions/math.fish index 0ec0e3d6a..584d1b27d 100644 --- a/share/functions/math.fish +++ b/share/functions/math.fish @@ -22,11 +22,14 @@ function math --description "Perform math calculations in bc" end # Set BC_LINE_LENGTH to a ridiculously high number so it only uses one line for most results. - # Results with more digits than that are basically never used anyway. # We can't use 0 since some systems (including macOS) use an ancient bc that doesn't support it. - # 32767 should still work on 2-byte int systems, though this is untested. - set -lx BC_LINE_LENGTH 32767 + # We also can't count on this being recognized since some BSD systems don't recognize this env + # var at all and limit the line length to 70. + set -lx BC_LINE_LENGTH 500 set -l out (echo "scale=$scale; $argv" | bc) + if set -q out[2] + set out (string join '' (string replace \\ '' $out)) + end switch "$out" case '' # No output indicates an error occurred.