-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 414e496
Showing
16 changed files
with
745 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# powertmux | ||
|
||
# Screenshots | ||
|
||
# Requirements | ||
|
||
# Plugin Requirements | ||
|
||
# Installation | ||
|
||
# Configuration | ||
|
||
# Debugging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# LICENSE This code is not under the same license as the rest of the project as it's "stolen". It's cloned from https://github.com/richoH/dotfiles/blob/master/bin/battery and just some modifications are done so it works for my laptop. Check that URL for more recent versions. | ||
|
||
POWERTMUX_SEG_BATTERY_TYPE_DEFAULT="percentage" | ||
POWERTMUX_SEG_BATTERY_NUM_HEARTS_DEFAULT=5 | ||
|
||
HEART_FULL="♥" | ||
HEART_EMPTY="♡" | ||
|
||
run_plugin() { | ||
__process_settings | ||
if shell_is_osx; then | ||
battery_status=$(__battery_osx) | ||
else | ||
battery_status=$(__battery_linux) | ||
fi | ||
[ -z "$battery_status" ] && return | ||
|
||
case "$POWERTMUX_SEG_BATTERY_TYPE" in | ||
"percentage") | ||
output="${HEART_FULL} ${battery_status}%" | ||
;; | ||
"cute") | ||
output=$(__cutinate $battery_status) | ||
esac | ||
if [ -n "$output" ]; then | ||
echo "$output" | ||
fi | ||
} | ||
|
||
__process_settings() { | ||
if [ -z "$POWERTMUX_SEG_BATTERY_TYPE" ]; then | ||
export POWERTMUX_SEG_BATTERY_TYPE="${POWERTMUX_SEG_BATTERY_TYPE_DEFAULT}" | ||
fi | ||
if [ -z "$POWERTMUX_SEG_BATTERY_NUM_HEARTS" ]; then | ||
export POWERTMUX_SEG_BATTERY_NUM_HEARTS="${POWERTMUX_SEG_BATTERY_NUM_HEARTS_DEFAULT}" | ||
fi | ||
} | ||
|
||
__battery_osx() { | ||
ioreg -c AppleSmartBattery -w0 | \ | ||
grep -o '"[^"]*" = [^ ]*' | \ | ||
sed -e 's/= //g' -e 's/"//g' | \ | ||
sort | \ | ||
while read key value; do | ||
case $key in | ||
"MaxCapacity") | ||
export maxcap=$value;; | ||
"CurrentCapacity") | ||
export curcap=$value;; | ||
"ExternalConnected") | ||
export extconnect=$value;; | ||
"FullyCharged") | ||
export fully_charged=$value;; | ||
esac | ||
if [[ -n $maxcap && -n $curcap && -n $extconnect ]]; then | ||
if [[ "$curcap" == "$maxcap" || "$fully_charged" == "Yes" && $extconnect == "Yes" ]]; then | ||
return | ||
fi | ||
charge=$(( 100 * $curcap / $maxcap )) | ||
if [[ "$extconnect" == "Yes" ]]; then | ||
echo "$charge" | ||
else | ||
if [[ $charge -lt 50 ]]; then | ||
echo -n "#[fg=red]" | ||
fi | ||
echo "$charge" | ||
fi | ||
break | ||
fi | ||
done | ||
} | ||
|
||
__battery_linux() { | ||
case "$SHELL_PLATFORM" in | ||
"linux") | ||
BATPATH=/sys/class/power_supply/BAT0 | ||
if [ ! -d $BATPATH ]; then | ||
BATPATH=/sys/class/power_supply/BAT1 | ||
fi | ||
STATUS=$BATPATH/status | ||
BAT_FULL=$BATPATH/charge_full | ||
if [ ! -r $BAT_FULL ]; then | ||
BAT_FULL=$BATPATH/energy_full | ||
fi | ||
BAT_NOW=$BATPATH/charge_now | ||
if [ ! -r $BAT_NOW ]; then | ||
BAT_NOW=$BATPATH/energy_now | ||
fi | ||
|
||
if [ "$1" = `cat $STATUS` -o "$1" = "" ]; then | ||
__linux_get_bat | ||
fi | ||
;; | ||
"bsd") | ||
STATUS=`sysctl -n hw.acpi.battery.state` | ||
case $1 in | ||
"Discharging") | ||
if [ $STATUS -eq 1 ]; then | ||
__freebsd_get_bat | ||
fi | ||
;; | ||
"Charging") | ||
if [ $STATUS -eq 2 ]; then | ||
__freebsd_get_bat | ||
fi | ||
;; | ||
"") | ||
__freebsd_get_bat | ||
;; | ||
esac | ||
;; | ||
esac | ||
} | ||
|
||
__cutinate() { | ||
perc=$1 | ||
inc=$(( 100 / $POWERTMUX_SEG_BATTERY_NUM_HEARTS )) | ||
|
||
|
||
for i in `seq $POWERTMUX_SEG_BATTERY_NUM_HEARTS`; do | ||
if [ $perc -lt 99 ]; then | ||
echo -n $HEART_EMPTY | ||
else | ||
echo -n $HEART_FULL | ||
fi | ||
echo -n " " | ||
perc=$(( $perc + $inc )) | ||
done | ||
} | ||
|
||
__linux_get_bat() { | ||
bf=$(cat $BAT_FULL) | ||
bn=$(cat $BAT_NOW) | ||
echo $(( 100 * $bn / $bf )) | ||
} | ||
|
||
__freebsd_get_bat() { | ||
echo "$(sysctl -n hw.acpi.battery.life)" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Print the current date. | ||
|
||
POWERTMUX_SEG_DATE_FORMAT_DEFAULT="%F" | ||
|
||
__process_settings() { | ||
if [ -z "$POWERTMUX_SEG_DATE_FORMAT" ]; then | ||
export POWERTMUX_SEG_DATE_FORMAT="${POWERTMUX_SEG_DATE_FORMAT_DEFAULT}" | ||
fi | ||
} | ||
|
||
run_plugin() { | ||
__process_settings | ||
date +"$POWERTMUX_SEG_DATE_FORMAT" | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Prints the name of the current day. | ||
|
||
run_plugin() { | ||
date +"%a" | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Prints the hostname. | ||
|
||
POWERTMUX_SEG_HOSTNAME_FORMAT_DEFAULT="short" | ||
|
||
__process_settings() { | ||
if [ -z "$POWERTMUX_SEG_HOSTNAME_FORMAT" ]; then | ||
export POWERTMUX_SEG_HOSTNAME_FORMAT="${POWERTMUX_SEG_HOSTNAME_FORMAT_DEFAULT}" | ||
fi | ||
} | ||
|
||
run_plugin() { | ||
__process_settings | ||
local opts="" | ||
if [ "$POWERTMUX_SEG_HOSTNAME_FORMAT" == "short" ]; then | ||
if shell_is_osx || shell_is_bsd; then | ||
opts="-s" | ||
else | ||
opts="--short" | ||
fi | ||
fi | ||
hostname ${opts} | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Prints the local network IPv4 address for a statically defined NIC or search for an IPv4 address on all active NICs. | ||
|
||
run_plugin() { | ||
if shell_is_bsd || shell_is_osx ; then | ||
all_nics=$(ifconfig 2>/dev/null | awk -F':' '/^[a-z]/ && !/^lo/ { print $1 }') | ||
for nic in ${all_nics[@]}; do | ||
ipv4s_on_nic=$(ifconfig ${nic} 2>/dev/null | awk '$1 == "inet" { print $2 }') | ||
for lan_ip in ${ipv4s_on_nic[@]}; do | ||
[[ -n "${lan_ip}" ]] && break | ||
done | ||
[[ -n "${lan_ip}" ]] && break | ||
done | ||
else | ||
# Get the names of all attached NICs. | ||
all_nics="$(ip addr show | cut -d ' ' -f2 | tr -d :)" | ||
all_nics=(${all_nics[@]//lo/}) # Remove lo interface. | ||
for nic in "${all_nics[@]}"; do | ||
# Parse IP address for the NIC. | ||
lan_ip="$(ip addr show ${nic} | grep '\<inet\>' | tr -s ' ' | cut -d ' ' -f3)" | ||
# Trim the CIDR suffix. | ||
lan_ip="${lan_ip%/*}" | ||
# Only display the last entry | ||
lan_ip="$(echo "$lan_ip" | tail -1)" | ||
|
||
[ -n "$lan_ip" ] && break | ||
done | ||
fi | ||
|
||
echo "ⓛ ${lan_ip-N/a}" | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Print the average load. | ||
|
||
run_plugin() { | ||
uptime | cut -d "," -f 3- | cut -d ":" -f2 | sed -e "s/^[ \t]*//" | ||
exit 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Prints the current time. | ||
|
||
POWERTMUX_SEG_TIME_FORMAT_DEFAULT="%H:%M" | ||
|
||
__process_settings() { | ||
if [ -z "$POWERTMUX_SEG_TIME_FORMAT" ]; then | ||
export POWERTMUX_SEG_TIME_FORMAT="${POWERTMUX_SEG_TIME_FORMAT_DEFAULT}" | ||
fi | ||
} | ||
|
||
run_plugin() { | ||
__process_settings | ||
date +"$POWERTMUX_SEG_TIME_FORMAT" | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Prints tmux session info. | ||
# Assuems that [ -n "$TMUX"]. | ||
|
||
run_plugin() { | ||
tmux display-message -p '#S:#I.#P' | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Prints the uptime. | ||
|
||
run_plugin() { | ||
uptime | grep -PZo "(?<=up )[^,]*" | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Prints the current time in UTC. | ||
|
||
run_plugin() { | ||
date -u +"%H:%M" | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Prints the WAN IP address. The result is cached and updated according to $update_period. | ||
|
||
run_plugin() { | ||
local tmp_file="${POWERTMUX_DIR_TEMPORARY}/wan_ip.txt" | ||
local wan_ip | ||
|
||
if [ -f "$tmp_file" ]; then | ||
if shell_is_osx || shell_is_bsd; then | ||
stat >/dev/null 2>&1 && is_gnu_stat=false || is_gnu_stat=true | ||
if [ "$is_gnu_stat" == "true" ];then | ||
last_update=$(stat -c "%Y" ${tmp_file}) | ||
else | ||
last_update=$(stat -f "%m" ${tmp_file}) | ||
fi | ||
elif shell_is_linux || [ -z $is_gnu_stat]; then | ||
last_update=$(stat -c "%Y" ${tmp_file}) | ||
fi | ||
|
||
time_now=$(date +%s) | ||
update_period=900 | ||
up_to_date=$(echo "(${time_now}-${last_update}) < ${update_period}" | bc) | ||
|
||
if [ "$up_to_date" -eq 1 ]; then | ||
wan_ip=$(cat ${tmp_file}) | ||
fi | ||
fi | ||
|
||
if [ -z "$wan_ip" ]; then | ||
wan_ip=$(curl --max-time 2 -s http://whatismyip.akamai.com/) | ||
if [ "$?" -eq "0" ]; then | ||
echo "${wan_ip}" > $tmp_file | ||
elif [ -f "${tmp_file}" ]; then | ||
wan_ip=$(cat "$tmp_file") | ||
fi | ||
fi | ||
|
||
if [ -n "$wan_ip" ]; then | ||
echo "ⓦ ${wan_ip}" | ||
fi | ||
|
||
return 0 | ||
} |
Oops, something went wrong.