dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

status-simple.sh (1044B)


      1#!/bin/bash
      2
      3show_unit() {
      4	name="$1"
      5	full_text="$2"
      6	color="$3"
      7	echo -n "{\"name\": \"$name\", \"full_text\": \"$full_text\", \"separator\": false, \"color\": \"$color\", \"border_top\": 0, \"border_bottom\": 0, \"border_left\": 0, \"border_right\": 0, \"separator_block_width\": 0},"
      8}
      9
     10get_rtc() {
     11	# DATE=$(date '+%F %T')
     12	rtc_path="/sys/class/rtc/rtc0"
     13	printf "$(<${rtc_path}/date) $(<${rtc_path}/time)"
     14}
     15
     16get_uptime() {
     17	# UPTIME="$(uptime -p)"
     18	proc_uptime=$(</proc/uptime)
     19	local T=${proc_uptime%%.*}
     20	local D=$((T/60/60/24))
     21	local H=$((T/60/60%24))
     22	local M=$((T/60%60))
     23	local S=$((T%60))
     24	[[ $D > 0 ]] && printf '%d days ' $D
     25	[[ $H > 0 ]] && printf '%02d:' $H
     26	[[ $M > 0 ]] && printf '%02d:' $M
     27	printf '%02d\n' $S
     28}
     29
     30show_status() {
     31	echo '{"version": 1, "click_events": true}'
     32	echo '['
     33	while :; do
     34		#echo '[{"full_text": "25%"}],'
     35		echo -n '['
     36		show_unit date "$(get_rtc) " "#FFA726"
     37		show_unit separator "| " "#c0c0c0"
     38		show_unit uptime "$(get_uptime) " "#43A047"
     39		echo '],'
     40		sleep 2
     41	done
     42	echo ']'
     43}
     44
     45show_status