Skip to content

Instantly share code, notes, and snippets.

@johndrinkwater
Created July 30, 2015 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johndrinkwater/17a403b605480f4d7d6a to your computer and use it in GitHub Desktop.
Save johndrinkwater/17a403b605480f4d7d6a to your computer and use it in GitHub Desktop.
GNU units is awesome, but you have to fight the frontend to get the answers.
john@joran ~ ❯ units "50 sq metres" feet
Unknown unit 'sq'
john@joran ~ ❯ units "50 square metres" feet
Error in '50 square metres': Parse error
john@joran ~ ❯ units "50 square metres" in feet
Too many arguments (maybe you need quotes).
Try 'units --help' for more information.
john@joran ~ ❯ units "50 metres2" feet
conformability error
50 m^2
0.3048 m
john@joran ~ ❯ units "50 metres2" feet2
* 538.19552
/ 0.0018580608
john@joran ~ ❯ units "50 metres^2" feet^2
* 538.19552
/ 0.0018580608
john@joran ~ ❯ units -1 "50 metres^2" feet^2
* 538.19552
@johndrinkwater
Copy link
Author

also these mixed prefixes are derp: brgallon, britishpound (lb), greatbritainpound (£), UKmile (which is the legacy unit, you want mile, but only if your locale is en_GB, or you force it with UNITS_ENGLISH=GB)

And units defaults to US outside of UK, which kinda fucks over most Commonwealth countries that have metric and British Imperial heritage.

@johndrinkwater
Copy link
Author

john@joran ~ ❯ units "77 kg" "stone;pound"
12 stone + 1.7559419 pound
Decimals pounds? this ought to be in 1/14 by default → needs work on making ‘Human’ output for legacy humans
john@joran ~ ❯ units -1t "1.7m" "ft;in;1|8 in"
5;6;7.4330709
-terse mode is reasonable, ; needs quoting, | needs quoting, would be nice to see optional fraction output: ⅞, & glyph support, ie:

5′ 6″

@johndrinkwater
Copy link
Author

More lols, seee british/britain
john@joran ~/desktop ❯ units -1 "hapenny"
Definition: ha'penny = halfbrpenny = 0.5 brpenny = 0.0083152436 US$
john@joran ~/desktop ❯ units -1 "hapenny" pounds
conformability error
0.0083152436 US$
0.45359237 kg
john@joran ~/desktop ❯ units -1 "hapenny" brpounds
Unknown unit 'brpounds'
john@joran ~/desktop ❯ units -1 "hapenny" britishpounds
conformability error
0.0083152436 US$
0.45359158 kg
john@joran ~/desktop ❯ units -1 "hapenny" greatbritishpounds
Unknown unit 'greatbritishpounds'
john@joran ~/desktop ❯ units -1 "hapenny" greatbritainpounds
* 0.005
john@joran ~/desktop ❯ units -1 "hapenny" gbp
Unknown unit 'gbp'
john@joran ~/desktop ❯ units -1 "hapenny" GBP
* 0.005

@johndrinkwater
Copy link
Author

Shell escapement 101: try stuff to see how it works: (noted in defined that ' ' should have worked, query)

john@joran ~/desktop ❯ units "4'"
        Definition: 0.0011635528 radian
john@joran ~/desktop ❯ units "4""
> ^C
john@joran ~/desktop ❯ units "4\""
        Definition: 1.9392547e-05 radian
john@joran ~/desktop ❯ units 4\"
        Definition: 1.9392547e-05 radian
john@joran ~/desktop ❯ units 4"
> ^C
john@joran ~/desktop ❯ units 4'
> ^C
john@joran ~/desktop ❯ units '4''
> ^C
john@joran ~/desktop ❯ units '4\''
> ^C
john@joran ~/desktop ❯ units '4'''
        Definition: 4
john@joran ~/desktop ❯ units 4''
        Definition: 4
john@joran ~/desktop ❯ units 4''''
        Definition: 4
john@joran ~/desktop ❯ units 4"
> ^C
john@joran ~/desktop ❯ units 4\"
        Definition: 1.9392547e-05 radian
john@joran ~/desktop ❯ units 4\'
        Definition: 0.0011635528 radian

@johndrinkwater
Copy link
Author

john@joran ~ ❯ units -1 "100F" C
conformability error
    100 A^2 s^4 / kg m^2
    1 A s
john@joran ~ ❯ units -1 "100F" celsius
Unknown unit 'celsius'
john@joran ~ ❯ units -1 "100F" °C
conformability error
    100 A^2 s^4 / kg m^2
    1 K
john@joran ~ ❯ units -1 "100 F" °C
conformability error
    100 A^2 s^4 / kg m^2
    1 K
john@joran ~ ❯ units -1 "100 Fahrenheit" °C
Unknown unit 'Fahrenheit'
john@joran ~ ❯ units -1 "100 °F" °C
    * 55.555556

(checking /usr/share/units/definitions.units, degC and degcelsius are valid)
Sadly for my parents, there is no synonym for centigrade

@johndrinkwater
Copy link
Author

They really need to get into Unicode.

john@joran /mnt/editing ❯ units -1 "50 metres^2" feet^2
	* 538.19552
john@joran /mnt/editing ❯ units -1 "50 metres^2" feet²
Unknown unit 'feet²'
john@joran /mnt/editing ❯ units -1 "50 metres^2" ft²
Unknown unit 'ft²'
john@joran /mnt/editing ❯ units -1 "50 metres^2" ft^2
	* 538.19552
john@joran /mnt/editing ❯ units -1 "50 m^2" ft^2
	* 538.19552
john@joran /mnt/editing ❯ units -1 "50m^2" ft^2
	* 538.19552
john@joran /mnt/editing ❯ units -1 50m^2 ft^2
	* 538.19552

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment