5

I like using bc in interactive mode as a calculator. However, it only accepts the period (.) as decimal separator but I am using the a German keyboard layout, so I only have the comma (,) available on the numpad. This is quite inconvenient when using bc single handed on the numpad, because I have to move my hand and search for the period key when entering decimal fractions.

So I am looking for a simple way to use bc on the numpad only.

Some possibilities I see right now:

  • Changing keyboard layout to English for bc
  • Replacing comma with period during input
  • Changing the decimal separator in bc

I would be grateful for any ideas.

Mq_
  • 153

2 Answers2

3

this is my alias as replacement for bc:

sh -c "sed -u 's/,/./g' | bc -l"

And this shortcut under my window manager:

urxvt -e sh -c "sed -u 's/,/./g' | bc -l"

Good luck!

2

My variant, that doesn't break all the readline functions in bc:

alias bcl='xmodmap -e "keycode 91 mod2 = KP_Delete period"; bc -l; xmodmap -e "keycode 91 mod2 = KP_Delete comma"'

This remaps the keypad's Delete/Comma key to Delete/Period before starting bc, and maps it back to Comma after bc exits.