mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
* usr/lib/byobu/cpu_freq, usr/lib/byobu/date, usr/lib/byobu/entropy,
usr/lib/byobu/include/shutil, usr/lib/byobu/ip_address, usr/lib/byobu/load_average, usr/lib/byobu/memory, usr/lib/byobu/menu, usr/lib/byobu/processes, usr/lib/byobu/time, usr/lib/byobu/time_utc, usr/lib/byobu/uptime, usr/lib/byobu/users: - finally got my hands on a Mac OS X box! - fixed a bunch of status scripts to work on Mac OS X
This commit is contained in:
commit
bfdf46b3e1
14 changed files with 94 additions and 45 deletions
7
debian/changelog
vendored
7
debian/changelog
vendored
|
@ -2,6 +2,13 @@ byobu (5.29) unreleased; urgency=low
|
||||||
|
|
||||||
* README:
|
* README:
|
||||||
- update build docs referencing git repo
|
- update build docs referencing git repo
|
||||||
|
* usr/lib/byobu/cpu_freq, usr/lib/byobu/date, usr/lib/byobu/entropy,
|
||||||
|
usr/lib/byobu/include/shutil, usr/lib/byobu/ip_address,
|
||||||
|
usr/lib/byobu/load_average, usr/lib/byobu/memory,
|
||||||
|
usr/lib/byobu/menu, usr/lib/byobu/processes, usr/lib/byobu/time,
|
||||||
|
usr/lib/byobu/time_utc, usr/lib/byobu/uptime, usr/lib/byobu/users:
|
||||||
|
- finally got my hands on a Mac OS X box!
|
||||||
|
- fixed a bunch of status scripts to work on Mac OS X
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Tue, 15 Jan 2013 19:26:40 -0600
|
-- Dustin Kirkland <kirkland@ubuntu.com> Tue, 15 Jan 2013 19:26:40 -0600
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ __cpu_freq() {
|
||||||
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
||||||
fpdiv $hz "1000000" 1 # 1Ghz
|
fpdiv $hz "1000000" 1 # 1Ghz
|
||||||
freq="$_RET"
|
freq="$_RET"
|
||||||
else
|
elif [ -r "/proc/cpuinfo" ]; then
|
||||||
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
||||||
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
||||||
else
|
else
|
||||||
|
@ -38,6 +38,9 @@ __cpu_freq() {
|
||||||
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
|
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
|
||||||
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
|
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
|
||||||
fi
|
fi
|
||||||
|
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null); then
|
||||||
|
fpdiv $hz "1000000000" 1 # 1Ghz
|
||||||
|
freq="$_RET"
|
||||||
fi
|
fi
|
||||||
[ -n "$freq" ] || return
|
[ -n "$freq" ] || return
|
||||||
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --
|
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --
|
||||||
|
|
|
@ -25,14 +25,14 @@ __date_detail() {
|
||||||
|
|
||||||
__date() {
|
__date() {
|
||||||
case "$BYOBU_BACKEND" in
|
case "$BYOBU_BACKEND" in
|
||||||
tmux)
|
|
||||||
date +"%Y-%m-%d "
|
|
||||||
;;
|
|
||||||
screen)
|
screen)
|
||||||
bd=$(date "+%m%d")
|
bd=$(date "+%m%d")
|
||||||
[ "$bd" = "0320" ] && msg="$(printf "%s" SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" && $BYOBU_BACKEND -X -S "byobu" at "*" echo "[$msg]"
|
[ "$bd" = "0320" ] && msg="$(printf "%s" SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" && $BYOBU_BACKEND -X -S "byobu" at "*" echo "[$msg]"
|
||||||
color none; printf "\005Y-\005m-\005d"; color --
|
color none; printf "\005Y-\005m-\005d"; color --
|
||||||
;;
|
;;
|
||||||
|
tmux|*)
|
||||||
|
date +"%Y-%m-%d "
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,15 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__entropy_detail() {
|
__entropy_detail() {
|
||||||
cat /proc/sys/kernel/random/entropy_avail
|
cat /proc/sys/kernel/random/entropy_avail 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
__entropy() {
|
__entropy() {
|
||||||
|
if [ -r /proc/sys/kernel/random/entropy_avail ]; then
|
||||||
local e=$(cat /proc/sys/kernel/random/entropy_avail)
|
local e=$(cat /proc/sys/kernel/random/entropy_avail)
|
||||||
[ -n "$e" ] || return
|
[ -n "$e" ] || return
|
||||||
color K Y; printf "e%s" "$e"; color --
|
color K Y; printf "e%s" "$e"; color --
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# vi: syntax=sh ts=4 noexpandtab
|
# vi: syntax=sh ts=4 noexpandtab
|
||||||
|
|
|
@ -301,7 +301,7 @@ get_network_interface() {
|
||||||
[ "$Mask" = "00000000" ] && break
|
[ "$Mask" = "00000000" ] && break
|
||||||
done < /proc/net/route
|
done < /proc/net/route
|
||||||
_RET="$Iface"
|
_RET="$Iface"
|
||||||
elif $BYOBU_TEST route >/dev/null; then
|
elif $BYOBU_TEST route >/dev/null 2>&1; then
|
||||||
# Route command on path
|
# Route command on path
|
||||||
_RET=$(route get default|grep interface:|awk '{print $2}')
|
_RET=$(route get default|grep interface:|awk '{print $2}')
|
||||||
elif [ -x "/sbin/route" ]; then
|
elif [ -x "/sbin/route" ]; then
|
||||||
|
|
|
@ -21,8 +21,10 @@
|
||||||
|
|
||||||
__ip_address_detail() {
|
__ip_address_detail() {
|
||||||
[ -x /sbin/ifconfig ] && /sbin/ifconfig
|
[ -x /sbin/ifconfig ] && /sbin/ifconfig
|
||||||
|
if [ -x /sbin/ip ]; then
|
||||||
/sbin/ip -4 addr list
|
/sbin/ip -4 addr list
|
||||||
/sbin/ip -6 addr list
|
/sbin/ip -6 addr list
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__ip_address() {
|
__ip_address() {
|
||||||
|
@ -44,7 +46,12 @@ __ip_address() {
|
||||||
sleep 0.02
|
sleep 0.02
|
||||||
else
|
else
|
||||||
# Background an update
|
# Background an update
|
||||||
|
if [ -x /sbin/ip ]; then
|
||||||
LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global >"$cache" 2>/dev/null &
|
LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global >"$cache" 2>/dev/null &
|
||||||
|
elif $BYOBU_TEST ifconfig >/dev/null 2>&1; then
|
||||||
|
LC_ALL=c ifconfig "$interface" | grep "inet6 " | awk '{print $2}' | sed "s/%.*//" >"$cache" 2>/dev/null &
|
||||||
|
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
[ -s "$cache" ] && read ipaddr < "$cache"
|
[ -s "$cache" ] && read ipaddr < "$cache"
|
||||||
# Print 'None' if we have no global address
|
# Print 'None' if we have no global address
|
||||||
|
@ -63,9 +70,13 @@ __ip_address() {
|
||||||
sleep 0.02
|
sleep 0.02
|
||||||
[ -s "$cache" ] && read ipaddr < "$cache"
|
[ -s "$cache" ] && read ipaddr < "$cache"
|
||||||
else
|
else
|
||||||
|
if [ -x /sbin/ip ]; then
|
||||||
ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global 2>/dev/null)
|
ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global 2>/dev/null)
|
||||||
ipaddr=${ipaddr#* inet }
|
ipaddr=${ipaddr#* inet }
|
||||||
ipaddr=${ipaddr%%/*}
|
ipaddr=${ipaddr%%/*}
|
||||||
|
elif $BYOBU_TEST ifconfig >/dev/null 2>&1; then
|
||||||
|
ipaddr=$(ifconfig "$interface" | grep "inet " | awk '{print $2}')
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# load_average: grab the current load average
|
# load_average: grab the current load average
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,11 @@ __load_average_detail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__load_average() {
|
__load_average() {
|
||||||
|
if [ -r "/proc/loadavg" ]; then
|
||||||
read one five fifteen other < /proc/loadavg
|
read one five fifteen other < /proc/loadavg
|
||||||
|
else
|
||||||
|
one=$(uptime | sed -e "s/.*://" | awk '{print $1}')
|
||||||
|
fi
|
||||||
[ -n "$one" ] || return
|
[ -n "$one" ] || return
|
||||||
color Y k; printf "$one"; color --
|
color Y k; printf "$one"; color --
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ __memory() {
|
||||||
__memory() {
|
__memory() {
|
||||||
local free="" total="" buffers="" cached=""
|
local free="" total="" buffers="" cached=""
|
||||||
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
||||||
|
if [ -r /proc/meminfo ]; then
|
||||||
while read tok val unit; do
|
while read tok val unit; do
|
||||||
case "$tok" in
|
case "$tok" in
|
||||||
MemTotal:) total=${val};;
|
MemTotal:) total=${val};;
|
||||||
|
@ -35,6 +36,18 @@ __memory() {
|
||||||
esac
|
esac
|
||||||
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||||
done < /proc/meminfo
|
done < /proc/meminfo
|
||||||
|
elif $BYOBU_TEST vm_stat >/dev/null 2>&1; then
|
||||||
|
# MacOS support
|
||||||
|
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857
|
||||||
|
free_blocks=$(vm_stat | grep free | awk '{ print $3 }' | sed 's/\.//')
|
||||||
|
inactive_blocks=$(vm_stat | grep inactive | awk '{ print $3 }' | sed 's/\.//')
|
||||||
|
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed 's/\.//')
|
||||||
|
free=$((($free_blocks+speculative_blocks)*4))
|
||||||
|
inactive=$(($inactive_blocks*4))
|
||||||
|
total=$((($free+$inactive)))
|
||||||
|
buffers=0
|
||||||
|
cached=0
|
||||||
|
fi
|
||||||
kb_main_used=$(($total-$free))
|
kb_main_used=$(($total-$free))
|
||||||
buffers_plus_cached=$(($buffers+$cached))
|
buffers_plus_cached=$(($buffers+$cached))
|
||||||
# "free output" buffers and cache (output from 'free')
|
# "free output" buffers and cache (output from 'free')
|
||||||
|
|
|
@ -35,7 +35,7 @@ __menu() {
|
||||||
else
|
else
|
||||||
key="F9"
|
key="F9"
|
||||||
fi
|
fi
|
||||||
text=$(gettext "Menu")
|
text=$(gettext "Menu" 2>/dev/null) || text="Menu"
|
||||||
color k w; printf "%s:<" "$text"; color -; color b k w; printf "%s" "$key"; color k w; printf ">"
|
color k w; printf "%s:<" "$text"; color -; color b k w; printf "%s" "$key"; color k w; printf ">"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,16 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__processes_detail() {
|
__processes_detail() {
|
||||||
ps -ejH
|
ps -ej
|
||||||
}
|
}
|
||||||
|
|
||||||
__processes() {
|
__processes() {
|
||||||
local count=$(ls -d /proc/[0-9]* 2>/dev/null| wc -l)
|
local count=
|
||||||
|
if [ -r /proc ]; then
|
||||||
|
count=$(ls -d /proc/[0-9]* 2>/dev/null| wc -l)
|
||||||
|
else
|
||||||
|
count=$(ps -ef | wc -l | awk '{print $1}')
|
||||||
|
fi
|
||||||
[ -n "$count" ] || return
|
[ -n "$count" ] || return
|
||||||
color b y w; printf "%s" "$count"; color -; color y w; printf "&"; color --
|
color b y w; printf "%s" "$count"; color -; color y w; printf "&"; color --
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,12 +25,12 @@ __time_detail() {
|
||||||
|
|
||||||
__time() {
|
__time() {
|
||||||
case "$BYOBU_BACKEND" in
|
case "$BYOBU_BACKEND" in
|
||||||
tmux)
|
|
||||||
date +"%H:%M:%S"
|
|
||||||
;;
|
|
||||||
screen)
|
screen)
|
||||||
printf "\0050c:\005s"
|
printf "\0050c:\005s"
|
||||||
;;
|
;;
|
||||||
|
tmux|*)
|
||||||
|
date +"%H:%M:%S"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ __time_utc_detail() {
|
||||||
|
|
||||||
__time_utc() {
|
__time_utc() {
|
||||||
d=$(date -u +%H:%M)
|
d=$(date -u +%H:%M)
|
||||||
color invert; printf "%s UTC" "$d"; color --
|
color invert; printf "%sUTC" "$d"; color --
|
||||||
}
|
}
|
||||||
|
|
||||||
# vi: syntax=sh ts=4 noexpandtab
|
# vi: syntax=sh ts=4 noexpandtab
|
||||||
|
|
|
@ -26,7 +26,8 @@ __uptime_detail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__uptime() {
|
__uptime() {
|
||||||
local u idle str
|
local u= idle= str=
|
||||||
|
if [ -r /proc/uptime ]; then
|
||||||
read u idle < /proc/uptime
|
read u idle < /proc/uptime
|
||||||
u=${u%.*}
|
u=${u%.*}
|
||||||
if [ "$u" -gt 86400 ]; then
|
if [ "$u" -gt 86400 ]; then
|
||||||
|
@ -38,6 +39,9 @@ __uptime() {
|
||||||
else
|
else
|
||||||
str="${u}s"
|
str="${u}s"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
str=$(uptime | sed -e "s/.* up *//" -e "s/ days, /d/" -e "s/:/h/" -e "s/,.*/m/")
|
||||||
|
fi
|
||||||
[ -n "$str" ] || return
|
[ -n "$str" ] || return
|
||||||
color w b; printf "%s" "${str}"; color --
|
color w b; printf "%s" "${str}"; color --
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ __users_detail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__users() {
|
__users() {
|
||||||
local count
|
local count=0
|
||||||
if [ "$USERS_DISTINCT" = "1" ]; then
|
if [ "$USERS_DISTINCT" = "1" ]; then
|
||||||
count=$(pgrep -fl 'sshd:.*@' | cut -f3 -d\ | cut -f1 -d@ | sort -u | wc -l)
|
count=$(pgrep -fl 'sshd:.*@' | cut -f3 -d\ | cut -f1 -d@ | sort -u | wc -l)
|
||||||
else
|
else
|
||||||
# Note: we'd like to use pgrep -c, however, this isn't available in
|
# Note: we'd like to use pgrep -c, however, this isn't available in
|
||||||
# busybox and some distro's pgrep (and it doesn't exit non-zero).
|
# busybox and some distro's pgrep (and it doesn't exit non-zero).
|
||||||
count=$(pgrep -f "^sshd:.*@" | wc -l) || return
|
count=$(pgrep -f "^sshd:.*@|^/usr/sbin/sshd -i" | wc -l) || return
|
||||||
fi
|
fi
|
||||||
if [ $count -gt 0 ]; then
|
if [ $count -gt 0 ]; then
|
||||||
color b w r; printf "%d" "$count"; color -; color w r; printf "#"; color --
|
color b w r; printf "%d" "$count"; color -; color w r; printf "#"; color --
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue