Skip to content

Instantly share code, notes, and snippets.

@ngsctt
Last active August 30, 2015 08:22
Show Gist options
  • Save ngsctt/4ce1d8dabc17bcd024ef to your computer and use it in GitHub Desktop.
Save ngsctt/4ce1d8dabc17bcd024ef to your computer and use it in GitHub Desktop.
Snippets of Bash code to use in GeekTool shell widgets
### HARDWARE METRICS
# Note: to use these snippets, you must first
# install the iStats gem with the following code:
sudo gem install iStats
## All metrics:
# with "danger bars":
istats
# without "danger bars":
istats | sed 's/[▁▂▃▅▆▇]//g' | sed 's/\[[0-9;]*[a-zA-Z]//g' | sed 's/[^A-z0-9%-\.°]\{1,\}/ /g'
## CPU temperature
# with "danger bars":
istats | grep "CPU temp"
# temperature only:
istats | grep "CPU temp" | awk '{ print $3 }'
# custom label:
istats | grep "CPU temp" | awk '{ print "<YOUR TEXT HERE>: " $3 }'
## Battery temperature
istats | grep "Battery temp"
# temperature only:
istats | grep "Battery temp" | awk '{ print $3 }'
# custom label:
istats | grep "Battery temp" | awk '{ print "<YOUR TEXT HERE>: " $3 }'

GeekTool Snippets

Bash snippets to use in GeekTool

uptime | awk '{
if ($4=="mins,")
print $3 " minutes since last reboot";
else if ($4=="days," || $4=="day,")
{
sub(",", " minutes", $5);
if ($5 ~ /^1\:/) sub(":", " hour, ", $5); else
sub(":", " hours, ", $5);
print $3 " " $4 " " $5 " since last reboot";
}
else if ($4=="hrs,")
{
sub(" hrs,", "hours", $4);
print $3 " " $4 " since last reboot";
}
else if ($4=="hour,")
{
sub(",", "", $4);
print $3 " " $4 " since last reboot";
}
else
{
sub(",", " minutes", $3);
if ($3 ~ /^1\:*/) sub(":", " hour, ", $3); else
sub(":", " hours, ", $3);
print $3 " since last reboot";
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment