#!/bin/ksh # Colors _pink="%{F#FF00B6}" _purple="%{F#7C00FF}" _cyan="%{F#00F0FF}" _blue="%{F#002EFF}" _orange="%{F#FF9E00}" _green="%{F#00FF00}" _red="%{F#FF0000}" _yellow="%{F#FFF000}" # Functions ## Define OS version _os_type(){ _net=$(ifconfig trunk0 | grep active | head -1 | awk '{print $1}') case "${_net}" in "em0") _os="Open${_orange}BSD%{F-} ${_cyan}$(sysctl -n kern.osrelease)%{F-} ${_red}$(sysctl -n kern.osversion)%{F-}" ;; "iwn0") _os="${_cyan}$(sysctl -n kern.osrelease)%{F-} ${_red}$(sysctl -n kern.osversion)%{F-}" ;; esac echo "| ${_os}" } ## Thelemic date _thelemic_date(){ # Vars _dayw=$(date "+%a") ## Day of the week _daym=$(date "+%d") ## Day of the mounth _mounth=$(date "+%m") ## Mounth number _year=$(date "+%Y") ## Current year _year_zero="1904" _year_diff="$(echo "${_year} - ${_year_zero}" | bc)" _year_cicles="$(echo "scale=0; ${_year_diff} / 22" | bc)" _year_cur_cicle="$(echo "${_year_diff} - (${_year_cicles} * 22)" | bc)" #_zone="-z -3" ## Time zone _lat="-20.351034" _log="-40.284485" #_coord="-zl ${_log} ${_lat}" _sun="$(astrolog -n ${_zone} ${_coord} | head -4 | tail -1 | awk '{print $3}' | sed 's/[0-9]//g')" _sun_pos="$(astrolog -n ${_zone} ${_coord} | head -4 | tail -1 | awk '{print $3}' | ghead -c 2 | sed 's/[A-Z]//')" _moon="$(astrolog -n ${_zone} ${_coord} | head -5 | tail -1 | awk '{print $2}' | sed 's/[0-9]//g')" _moon_pos="$(astrolog -n ${_zone} ${_coord} | head -5 | tail -1 | awk '{print $2}' | ghead -c 2 | sed 's/[A-Z]//')" _net="$(ifconfig trunk0 | grep active | head -1 | awk '{print $1}')" case $_sun in "Aqu") _sun_done="Aquarii";; "Gem") _sun_done="Geminorum";; "Sag") _sun_done="Sagittarii";; "Tau") _sun_done="Tauri";; "Ari") _sun_done="Arietis";; "Pis") _sun_done="Piscis";; "Cap") _sun_done="Capricorni";; "Can") _sun_done="Cancri";; "Sco") _sun_done="Scorpii";; "Lib") _sun_done="Librae";; "Leo") _sun_done="Leonis";; "Vir") _sun_done="Virginis";; esac case $_moon in "Aqu") _moon_done="Aquarii";; "Gem") _moon_done="Geminorum";; "Sag") _moon_done="Sagittarii";; "Tau") _moon_done="Tauri";; "Ari") _moon_done="Arietis";; "Pis") _moon_done="Piscis";; "Cap") _moon_done="Capricorni";; "Can") _moon_done="Cancri";; "Sco") _moon_done="Scorpii";; "Lib") _moon_done="Librae";; "Leo") _moon_done="Leonis";; "Vir") _moon_done="Virginis";; esac case $_dayw in "Sun") _dayw_done="Solis";; "Mon") _dayw_done="Lunae";; "Tue") _dayw_done="Martis";; "Wed") _dayw_done="Mercurii";; "Thu") _dayw_done="Jovis";; "Fri") _dayw_done="Veneris";; "Sat") _dayw_done="Saturnis";; esac case $_net in "em0") _date="Sol in ${_sun_pos}° ${_sun_done} : Luna in ${_moon_pos}° ${_moon_done} : Dies ${_dayw_done} : Anno Vviii e.l." ;; "iwn0") _date="Sol in ${_sun_pos}° ${_sun_done} Luna in ${_moon_pos}° ${_moon_done} Dies ${_dayw_done} Anno Vviii e.l." ;; esac # Main function echo "$_date" # echo " # ☉︎ in ${_sun_pos}° ${_sun_done} # ☽︎ in ${_moon_pos}° ${_moon_done} # Dies ${_dayw_done} # Anno V:viii a.n. #" } ## Show current group _grp(){ _cur_grp="$(xprop -root _NET_CURRENT_DESKTOP | awk -F '=' '{print $2}' | sed 's/ //')" echo "[${_cur_grp}]" } ## Show memory usage _mem(){ _smt="$(sysctl -n hw.smt)" ### Define number of threads if [ "$_smt" = "0" ]; then _h="7" elif [ "$_smt" = "1" ]; then _h="11" fi ### Get memory usage _memo="$(top -d1 | \ head -n "${_h}" | \ tail -1 | \ awk '{print $3}' | \ awk -F / '{print $1}')" # _memo="1111M" _dig="$(printf '%s' $_memo | sed s/[0-9]*//)" _mem_use="$(printf '%s' $_memo | sed s/[A-Z]*//g)" if [ "${_dig}" = "M" ]; then echo "${_blue}Ram:%{F-} ${_green}$(echo "scale=2; $_mem_use / 1024" | bc)G/16G%{F-}" else echo "${_blue}Ram:%{F-} ${_green}${_mem_use}G/16G%{F-}" fi } ## Define cpu clock rate _cpu_clock(){ _CSPEED="$(sysctl -n hw.cpuspeed)" _CP="$(echo "scale=2; $_CSPEED / 1024" | bc)" echo "${_orange}CPU:%{F-} ${_green}${_CP}Ghz%{F-}" } ## Get hardware temperatures _temp(){ ### Some limits y=60 r=70 ### Get cpu temp _cpu_temp="$(sysctl -n hw.sensors.cpu0.temp0 | awk '{print $1}' | awk -F '.' '{print $1}')" ### Get acpitz temp _acpitz_temp="$(sysctl -n hw.sensors.acpitz0.temp0 | awk '{print $1}' | awk -F '.' '{print $1}')" ### Correct bug temperature _temp_c="$(echo "scale=0; $_cpu_temp - 15" | bc)" _temp_a="$(echo "scale=0; $_acpitz_temp - 15" | bc)" ### Some color acording to temperature if [ "$_temp_c" -ge "$r" ]; then _tempc="${_red}${_cpu_temp}ºC%{F-}" elif [ "$_temp_c" -ge "$y" ]; then _tempc="%{F#FFF000}${_temp_c}ºC%{F-}" else _tempc="${_green}${_temp_c}ºC%{F-}" fi if [ "$_temp_a" -ge "$r" ]; then _tempa="${_red}${_temp_a}ºC%{F-}" elif [ "$_temp_a" -ge "$y" ]; then _tempa="%{F#FFF000}${_temp_a}ºC%{F-}" else _tempa="${_green}${_temp_a}ºC%{F-}" fi ### Build output echo "${_orange}CPU:%{F-} ${_tempc} ${_purple}ACPITZ:%{F-} ${_tempa}" } _fan_speed(){ _fspeed="$(sysctl -n hw.sensors.acpithinkpad0.fan0 | awk '{print $1}')" _fp="$(echo "scale=2; $_fspeed / 1024" | bc)" echo -e "${_cyan}FAN:%{F-} ${_green}${_fp}kRPM%{F-}" } _smt_func(){ _smt="$(sysctl -n hw.smt)" echo "${_purple}SMT:%{F-} ${_green}${_smt}%{F-}" } _sec(){ _sec_lvl="$(sysctl -n kern.securelevel)" if [ $_sec_lvl = "1" ]; then _result="${_green}$_sec_lvl%{F-}" elif [ $_sec_lvl = "2" ]; then _result="${_orange}$_sec_lvl%{F-}" else _result="${_red}ERROR!%{F-}" fi echo "${_red}Sec_lvl=%{F-} $_result" } ## PF Status _pf(){ _pf_status="$(rcctl get pf | sed 's/pf=//')" case "$_pf_status" in "YES") echo "${_cyan}PF: %{F-}${_green}ON%{F-}";; "NO") echo "${_cyan}PF: %{F-}${_red}OFF%{F-}";; esac } _rec(){ _audio="$(sysctl -n kern.audio.record)" _video="$(sysctl -n kern.video.record)" if [ $_audio = 0 ]; then _audio_color="${_green}$_audio%{F-}" else _audio_color="${_orange}$_audio%{F-}" fi if [ $_video = 0 ]; then _video_color="${_green}$_video%{F-}" else _video_color="${_orange}$_video%{F-}" fi echo "${_blue}Video:%{F-} $_video_color | ${_pink}Audio:%{F-} $_audio_color" } _network(){ _net="$(ifconfig trunk0 | grep active | head -1 | awk '{print $1}')" _iplocal="$(ifconfig trunk0 | tail -1 | awk '{print $2}')" _wifiname="$(ifconfig iwn0 | tail -1 | awk '{print $3}')" _wifistr="$(ifconfig iwn0 | tail -1 | awk '{print $8}' | sed 's/dBm//')" if [ "$_wifistr" -ge -45 ]; then _wifistr_color="${_green}${_wifistr}dbm%{F-}" elif [ "$_wifistr" -lt -45 ] && [ "$_wifistr" -ge -60 ]; then _wifistr_color="${_orange}${_wifistr}dbm%{F-}" elif [ "$_wifistr" -lt -60 ]; then _wifistr_color="${_red}${_wifistr}dbm%{F-}" fi if [ "$_net" = "em0" ]; then echo "${_pink}${_net}:%{F-} ${_green}${_iplocal}%{F-}" elif [ "$_net" = "iwn0" ]; then echo "${_pink}${_wifiname}:%{F-} ${_green}${_iplocal}%{F-} ${_wifistr_color}" else echo "${_red}No network!%{F-}" fi } _mail(){ _mail_count="$(grep '^To:' /var/mail/puffy | wc -l | sed 's/ //g')" echo "${_cyan}Mail:%{F-}${_green}${_mail_count}%{F-}" } _sound(){ _vol="$(sndioctl -n output.level)" _vol_done="$(echo "scale=0; $_vol * 100" | bc | awk -F'[.=]' '{print $1}')%" echo "${_orange}Sound:%{F-} ${_green}${_vol_done}" } _batt(){ _full="$(sysctl -n hw.sensors.acpibat0.watthour0 | awk '{print $1}')" _real="$(sysctl -n hw.sensors.acpibat0.watthour3 | awk '{print $1}')" _percent="$(echo "scale=2; ${_real} / ${_full} * 100" | bc | awk -F '.' '{print $1}')" _state="$(sysctl -n hw.sensors.acpibat0.raw0 | awk '{print $3}' | sed s/\)\,//)" case $_state in "discharging") _states="dis" ;; "charging") _states="char" ;; "idle") _states="idle" ;; "full") _states="full" ;; esac _y=50 _r=30 if [ "$_percent" -ge "$_y" ]; then _percent_color="${_green}${_percent}%" elif [ "$_percent" -ge "$_r" ]; then _percent_color="${_yellow}${_percent}%" else _percent_color="${_red}${_percent}%" fi echo "${_purple}${_states}:%{F-} ${_percent_color}" } _clock(){ _net="$(ifconfig trunk0 | grep active | head -1 | awk '{print $1}')" _day="$()" case $_net in "em0") _date=$(date "+%a 1%Y-%m-%d e.v. %H:%M:%S") ;; "iwn0") _date=$(date "+%a 1%Y-%m-%d %H:%M:%S") ;; *) _date=$(date "+%a 1%Y-%m-%d e.v. %H:%M:%S") ;; esac echo -n "$_date |" } _space(){ echo " " } # #$(_thelemic_date) \ #$(_sec) | \ #$(_pf) | \ #$(_rec) | \ while true; do echo "%{l}%{+u}%{+o}\ $(_os_type) \ $(_grp) \ $(_space) \ %{c}$(_space) | \ $(_mem) | \ $(_smt_func) | \ $(_fan_speed) | \ (_temp) | \ $(_network) | \ $(_mail) | \ $(_sound) %{F-}| \ $(_batt) %{F-}|\ $(_space) \ %{r}$(_space) \ $(_clock)" sleep 1 done