dmenium

small collection of dmenu scripts
git clone git://edryd.org/dmenium
Log | Files | Refs | LICENSE

calc (502B)


      1 #!/usr/bin/env bash
      2 # Calculator using dmenu as an interface
      3 
      4 dmenucmd="dmenu -p Calc $@"
      5 
      6 # run dmenu calculator while the result is not empty
      7 while : ; do
      8     # use contents of clipboard as option, pass into bc to be calculated
      9     result=$(xsel -o -b | $dmenucmd | xargs echo | bc -l 2>&1)
     10     if [[ $result ]]; then # if result is empty (the last one), don't copy it to clipboard
     11         printf "$result" | xsel -b
     12     fi
     13     [[ $result ]] || break # if result is empty, break from while loop
     14 done