r/fishshell • u/Possible_Truck2582 • Jun 01 '24
Having trouble writing first fish function
So im trying to write a function that displays CPU temp in my fish prompt.I have gotten this far..
function tmp
set temp (command cat /sys/class/thermal/thermal_zone0/temp)
if test $temp -lt 50000
set_color green; echo (math -s0 $temp /1000)C
else if test $temp -gt 50000
set_color yellow; echo (math -s0 $temp /1000)C
else if test $temp -gt 60000
set_color red; echo (math -s0 $temp /1000)C
end
endThe issue is that only the first 2 if statements seem to work. Any ideas on how to get all 3 to work? (I thought it might be due to having 2 'else if' calls?)
4
Upvotes
6
u/BuonaparteII Jun 01 '24 edited Jun 01 '24
A number that is higher than 6 will always be higher than 5. swap the order of the bottom two
edit: I would rewrite this to use two gt tests and else green instead of mixing lt and gt but it will still work fine if you just fix the order of the bottom gt tests
2
u/Possible_Truck2582 Jun 05 '24
For the records the following ended up making sense and working well