Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

After some trial and error, I was able to make the following bash script, which will take the X clipboard selection (containing math operations you want to perform), run it through bc (to do the math), replace the X clipboard with the result, and paste it, overwriting the previous result:

    output=$(echo "$(xclip -o)" | bc) # take the X clipboard and run it through bc
    sleep 0.2s # wait before continuing or else this won't work
    xdotool key BackSpace # clear the selection
    printf $output | xclip -i # write the output to the X clipboard
    xdotool click 2 # paste the result by clicking the middle button
I set this as Super-E on my computer and probably will use it every once in a while for programs which don't implement math input.

In other words, with this you can select text containing mathematical operations, press a key combination, and the selected text will be replaced by the result of the math.

Improvements welcome. There probably are better ways to do this.



One disadvantage of this approach is that the mouse needs to be over the text area that's being pasted in to.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: