Skip to content

Soulver-like calculator for the command line.

License

Notifications You must be signed in to change notification settings

shuckster/solv-sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

solv-sh

Soulver-like calculator for the command line, intended for Vim.

Latest version: 1.2.0 (2024-11-30)

Usage:

./solv.sh "a simple sum 1 + 1
           let us multiply that result LINE:-1 * 3
           and sum the previous lines SUM:-2,-1
           as a percentage demo 2 - 1 as % of LINE:+2
           percent off demo (5 * 2) % off 512
           percent of demo 10 % of 256"

# Output
a simple sum 1 + 1                          #= 2
let us multiply that result LINE:-1 * 3     #= 6
and sum the previous lines SUM:-2,-1        #= 8
as a percentage demo 2 - 1 as % of LINE:+2  #= 3.90625
percent off demo (5 * 2) % off 512          #= 460.8
percent of demo 10 % of 256                 #= 25.6

You can pass solv-sh an input that includes previously generated answers and they will be stripped and recalculated.

You can pipe:

echo "1 + 1 - (2 * 2)
      LINE:-1 + 10
      LINE:-1 * 2
      SUM:-2,-1" | ./solv.sh

Supported syntax

solv-sh essentially tries to make its input bc friendly (which it uses internally) while adding support for the following tokens:

  • LINE:relative-line-number
  • SUM:start-of-range,end-of-range
  • X as % of Y
  • X % off Y
  • X % of Y

Both LINE and SUM work with relative line numbers, so LINE:-1 means to replace that token with the calculated value of the line before it, and SUM:-2,-1 means to replace that token with the sum of the two previous lines.

X and Y correspond to any expression you can make with bc, plus the LINE and SUM tokens above.

Vim

As solv-sh works with relative line numbers it's especially handy to use within Vim: You can pipe a VISUAL selection of calculations to solv-sh by hitting ! on your keyboard and entering the path to the script.

Credits

I hope you found it useful! If so, I like coffee ☕️ :)

About

Soulver-like calculator for the command line.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages