snippets

fahrenheit and celsius conversion

i write this as my region is in the midst of a record breaking, coldest summer of our lives kinda heat wave. thus, to accurately convey to your friends in different areas how hot it is, this script may be handy!

this script relies on the wonderful gum by charm CLI — check it out to make your scripts cute AF!

(inspired by bread on penguins)

	#!/bin/bash

f_to_c() {
	fah="$(gum input --placeholder 'enter temp in fahrenheit')"
	cel=$(bc <<< "scale=2; ($fah - 32) * 5/9")
	result="$fah°F is equal to $cel°C"
	notify-send "$result" && echo "$result"
}

c_to_f() {
	cel="$(gum input --placeholder 'enter temp in celsius')"
	fah=$(bc <<< "scale=2; ($cel * 9/5) + 32")
	result="$cel°C is equal to $fah°F"
	notify-send "$result" && echo "$result"
}

choice() {
	choose=$(gum choose "fahrenheit to celsius" "celsius to fahrenheit")
	case "$choose" in
		*celsius) f_to_c ;;
		*fahrenheit) c_to_f ;;
		*) exit;;
	esac
}

choice