File tree Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Original file line number Diff line number Diff line change 11# shellcheck shell=bash
22
33tp_cpu_temp_value () {
4+ local temp
5+
46 if tp_shell_is_macos; then
5- smctemp -c | bc -l
7+ temp= $( smctemp -c | bc -l)
68 elif tp_shell_is_linux; then
7- sensors \
9+ temp= $( sensors \
810 | grep " $TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER " -m 1 \
9- | sed -e ' s/[^+]*+\([\s0-9\.]*\).*/\1/' | bc -l
11+ | sed -e ' s/[^+]*+\([\s0-9\.]*\).*/\1/' | bc -l)
1012 fi
13+
14+ tp_round " $temp " 0
1115}
1216
1317tp_cpu_temp_at_least () {
14- echo " $( tp_cpu_temp_value) >= $1 " | bc -l
18+ local threshold_temp=" $1 "
19+
20+ echo " $( tp_cpu_temp_value) >= $threshold_temp " | bc -l
1521}
1622
Original file line number Diff line number Diff line change @@ -47,12 +47,12 @@ __tp_mem_used_info() {
4747
4848tp_mem_used_gigabytes () {
4949 read -r mem_used_bytes mem_total_bytes < <( __tp_mem_used_info)
50- __round " $( echo " $mem_used_bytes / 1073741824" | bc -l) " 2
50+ tp_round " $( echo " $mem_used_bytes / 1073741824" | bc -l) " 2
5151}
5252
5353tp_mem_used_megabytes () {
5454 read -r mem_used_bytes mem_total_bytes < <( __tp_mem_used_info)
55- __round " $( echo " $mem_used_bytes / 1048576" | bc -l) " 0
55+ tp_round " $( echo " $mem_used_bytes / 1048576" | bc -l) " 0
5656}
5757
5858tp_mem_used_percentage_at_least () {
@@ -61,13 +61,3 @@ tp_mem_used_percentage_at_least() {
6161 echo " ($mem_used_bytes / $mem_total_bytes ) * 100 >= $threshold_percentage " | bc -l
6262}
6363
64- # source https://askubuntu.com/a/179949
65- # Rounds positive numbers up to the number of digits to the right of the decimal point.
66- # Example: "__round 1.2345 3" -> "((1000 * 1.2345) + 0.5) / 1000" -> "1.235"
67- __round () {
68- local number=" $1 "
69- local digits=" $2 "
70-
71- env printf " %.${digits} f" " $( echo " scale=${digits} ;(((10^${digits} )*${number} )+0.5)/(10^${digits} )" | bc) "
72- };
73-
Original file line number Diff line number Diff line change @@ -66,3 +66,14 @@ tp_err_seg() {
6666 # TMUX_POWERLINE_CUR_SEGMENT_NAME is being set before each segment run
6767 tp_err " ${TMUX_POWERLINE_CUR_SEGMENT_NAME:- unknown_segment} " " $* "
6868}
69+
70+ # source https://askubuntu.com/a/179949
71+ # Rounds positive numbers up to the number of digits to the right of the decimal point.
72+ # Example: "tp_round 1.2345 3" -> "((1000 * 1.2345) + 0.5) / 1000" -> "1.235"
73+ tp_round () {
74+ local number=" $1 "
75+ local digits=" $2 "
76+
77+ env printf " %.${digits} f" " $( echo " scale=${digits} ;(((10^${digits} )*${number} )+0.5)/(10^${digits} )" | bc) "
78+ };
79+
You can’t perform that action at this time.
0 commit comments