Skip to content

Instantly share code, notes, and snippets.

@joanbono
Created February 21, 2020 23:24
Show Gist options
  • Save joanbono/fd81a061e16260aab4b95936f5ad0fda to your computer and use it in GitHub Desktop.
Save joanbono/fd81a061e16260aab4b95936f5ad0fda to your computer and use it in GitHub Desktop.
My BitBar plugins.

BitBar plugins

Taking code from here and there

Temperature

osx-cpu-temp.10s.sh

#!/bin/bash

# osx-cpu-temp -- https://github.com/lavoiesl/osx-cpu-temp
# brew install osx-cpu-temp

CELSIUS=$(/usr/local/bin/osx-cpu-temp)

echo "${CELSIUS}"

Bandwith

bandwidth.1s.sh

#!/bin/bash

# ifstat -- http://gael.roualland.free.fr/ifstat
# brew install ifstat

INTERFACE="en0"


if [ ! -e /usr/local/bin/ifstat ]; then
    echo "Please install ifstat or change the path to it in the script."
    exit 1
fi

function kilo_to_mega {
  printf "%0.2f\n" "$(bc -q <<< scale=2\;"${1}"/1000)"
}

function get_ifstat {
    interface=$1
    /usr/local/bin/ifstat -n -w -i "${interface}" -b 0.5 1 | tail -n 1
}

function print_ifstat {
    kbits_in=$(echo "$1" | awk '{ print $1 }')
    kbits_out=$(echo "$1" | awk '{ print $2 }')
    mbits_in=$(kilo_to_mega "$kbits_in")
    mbits_out=$(kilo_to_mega "$kbits_out")
    echo "$mbits_in - $mbits_out"

}

print_ifstat "$(get_ifstat ${INTERFACE}) | dropdown=false"

IP Info

ipinfo.5m.js

#!/usr/bin/env /usr/local/bin/node

var url = 'http://ip-api.com/json';
const https = require('http');

https.get(url, (resp) => {
	let data = '';

	resp.on('data', (chunk) => {
		data += chunk;
	});

	resp.on('end', () => {
		CountryCode = JSON.parse(data).countryCode
		Flag=CountryCode.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0)+127397));
		console.log(JSON.parse(data).query, Flag);
		console.log("---")
		console.log("City: ", JSON.parse(data).city);
		console.log("Timezone: ",JSON.parse(data).timezone);
		console.log("ISP: ",JSON.parse(data).isp);
	});

}).on("error", (err) => {
		console.log("127.0.0.1 🏴‍☠️ | dropdown=false");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment