diff options
Diffstat (limited to '.functions')
-rw-r--r-- | .functions | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1,3 +1,21 @@ +# Simple calculator +function calc() { + local result="" + result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')" + # └─ default (when `--mathlib` is used) is 20 + # + if [[ "$result" == *.* ]]; then + # improve the output for decimal numbers + printf "$result" | + sed -e 's/^\./0./' `# add "0" for cases like ".5"` \ + -e 's/^-\./-0./' `# add "0" for cases like "-.5"`\ + -e 's/0*$//;s/\.$//' # remove trailing zeros + else + printf "$result" + fi + printf "\n" +} + # Create a new directory and enter it function mkd() { mkdir -p "$@" && cd "$@" |