first commit

This commit is contained in:
Paul Wilde 2022-02-06 20:10:06 +00:00
commit bc5084df13
6 changed files with 310 additions and 0 deletions

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# ignore all
*
# unignore all with extensions
!*.*
# unignore directories
!*/

38
i3bar_base.nim Normal file
View file

@ -0,0 +1,38 @@
import marshal
import argparse
type
i3BarData* = object
full_text*: string
short_text*: string
color*: string
border*: string
const background* = "#000000"
const backgroundalt* = "#bb222222"
const backgroundalt2* = "#bb333333"
const foreground* = "#dfdfdf"
const foregroundalt* = "#777"
const foregroundalt2* = "#ccc"
const yellow* = "#ffb52a"
const red* = "#e60053"
const purple* = "#9f78e1"
const blue* = "#0a6cf5"
const lightblue* = "#7296EF"
const lighterblue* = "#B5DDF7"
const green* = "#4b9901"
const lightgreen* = "#00ff00"
const grey* = "#dfdfdf"
const darkgrey* = "#444"
const primary* = yellow
const secondary* = red
const alert* = "#bd2c40"
proc getArguments*(): seq[string] =
let args = commandLineParams()
return args
proc outputJSON*(data: i3barData) =
echo $$data

54
i3bar_brightness.nim Normal file
View file

@ -0,0 +1,54 @@
import std/os
import strutils
import std/osproc
import std/math
import i3bar_base
proc getLimit(): int
let limit = getLimit()
let args = getArguments()
proc getLimit(): int =
let limit = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/max_brightness")))
return limit
proc getDesign(pcnt: float): string =
var icon = "🌑"
case pcnt:
of 85..100:
icon = "🌕"
of 75..85:
icon = "🌖"
of 50..75:
icon = "🌗"
of 35..50:
icon = "🌘"
else:
icon = "🌑"
let percent = toInt(round(pcnt,0))
let text = icon & " " & $percent & "%"
return text
proc getBrightness() =
let current = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/actual_brightness")))
let pcnt = (current/limit)*100
let text = getDesign(pcnt)
let data = i3barData(
full_text: text,
color: foreground,
border: yellow
)
outputJSON(data)
proc main() =
if len(args) > 0:
if args[0] == "4":
discard execCmd("xbacklight -inc 5")
elif args[0] == "5":
discard execCmd("xbacklight -dec 5")
getBrightness()
main()

64
i3bar_date.nim Normal file
View file

@ -0,0 +1,64 @@
import std/os
import std/times
import std/osproc
import i3bar_base
let args = getArguments()
proc getObject(date: string): i3barData =
let data = i3barData(
full_text: date,
color: foreground,
border: blue
)
return data
proc openCalendar() =
let cmd = "~/Nextcloud/Backups/Linux/dotFiles/scripts/popup-calendar.sh"
discard execCmd(cmd)
proc getDate() =
let now = now()
let d = now.format("yyyy-MM-dd")
let data = getObject(d)
outputJSON(data)
proc main() =
if len(args) == 0:
#while true:
getDate()
# sleep(5000)
else:
if args[0] == "1":
openCalendar()
getDate()
main()
#BAR_HEIGHT=28 # polybar height
#BORDER_SIZE=1 # border size from your wm settings
#YAD_WIDTH=222 # 222 is minimum possible value
#YAD_HEIGHT=193 # 193 is minimum possible value
#DATE="$(date +"%a %d %H:%M")"
#if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
# exit 0
#fi
#eval "$(xdotool getmouselocation --shell)"
#eval "$(xdotool getdisplaygeometry --shell)"
## X
#if [ "$((X + YAD_WIDTH / 2 + BORDER_SIZE))" -gt "$WIDTH" ]; then #Right side
# : $((pos_x = WIDTH - YAD_WIDTH - BORDER_SIZE))
#elif [ "$((X - YAD_WIDTH / 2 - BORDER_SIZE))" -lt 0 ]; then #Left side
# : $((pos_x = BORDER_SIZE))
#else #Center
# : $((pos_x = X - YAD_WIDTH / 2))
#fi
## Y
#if [ "$Y" -gt "$((HEIGHT / 2))" ]; then #Bottom
# : $((pos_y = HEIGHT - YAD_HEIGHT - BAR_HEIGHT - BORDER_SIZE))
#else #Top
# : $((pos_y = BAR_HEIGHT + BORDER_SIZE))
#fi
#yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \
# --width="$YAD_WIDTH" --height="$YAD_HEIGHT" --posx="$pos_x" --posy="$pos_y" \
# --title="yad-calendar" --borders=0 >/dev/null &

87
i3bar_fuzzytime.nim Normal file
View file

@ -0,0 +1,87 @@
import std/times
import std/os
import i3bar_base
proc get_hour(hr: int): string
proc get_minute(min: int): string
proc get_fuzzytime(): string =
let tm = now()
var hr = tm.hour()
let min = tm.minute()
var link = "past"
if min > 32 :
link = "to"
hr = hr + 1
if min >= 58 or min <= 02:
return get_hour(hr) & " " & get_minute(min)
else:
return get_minute(min) & " " & link & " " & get_hour(hr)
proc get_hour(hr: int): string =
case hr:
of 1, 13:
return "one"
of 2, 14:
return "two"
of 3, 15:
return "three"
of 4, 16:
return "four"
of 5, 17:
return "five"
of 6, 18:
return "six"
of 7, 19:
return "seven"
of 8, 20:
return "eight"
of 9, 21:
return "nine"
of 10, 22:
return "ten"
of 11, 23:
return "eleven"
of 0, 12, 24:
return "twelve"
else:
return "error"
proc get_minute(min: int): string =
case min:
of 58,59,0,1,2:
return "o'clock"
of 3,4,5,6,7,53,54,55,56,57:
return "five"
of 8,9,10,11,12,48,49,50,51,52:
return "ten"
of 13,14,15,16,17,43,44,45,46,47:
return "quarter"
of 18,19,20,21,22,38,39,40,41,42:
return "twenty"
of 23,24,25,26,27,33,34,35,36,37:
return "twenty-five"
of 28,29,30,31,32:
return "half"
else:
return "error"
proc getObject(time: string): i3barData =
let data = i3barData(
full_text: time,
color: foreground,
border: lightblue,
)
return data
proc main() =
while true:
let time = get_fuzzytime()
let data = getObject(time)
outputJSON(data)
sleep(10000)
main()

59
i3bar_temperature.nim Normal file
View file

@ -0,0 +1,59 @@
import std/os
import std/re
import std/math
import strutils
import i3bar_base
proc getThermalZones(): seq[string] =
var zones: seq[string] = @[]
let dirname = re("thermal_zone[\\d]+")
for file in walkDir("/sys/class/thermal/"):
if contains(file.path,dirname):
let state = readFile(file.path & "/mode")
if contains(state,re"enabled"):
zones.add(file.path)
return zones
proc getTemp(zone: string): int =
let temp = strip(readFile(zone & "/temp"))
return parseInt(temp)
proc getAverageTemp(zones: seq[string]): int =
var temps: int = 0
for zone in zones:
let temp = getTemp(zone)
temps += temp
let avgtemp = ceil((temps / len(zones))/1000)
return toInt(round(avgtemp,0))
proc getObject(temp: int): i3barData =
var icon = ""
var colour = foreground
case temp:
of 40..59:
colour = yellow
icon = ""
of 60.. 200:
colour = red
icon = ""
else:
colour = green
icon = ""
let text = "<span foreground='" & colour & "'>" & icon & "</span> " & $temp & "°C"
let data = i3barData(
full_text: text,
color: foreground,
border: colour
)
return data
proc main() =
let zones = getThermalZones()
while true:
let temp = getAverageTemp(zones)
let data = getObject(temp)
outputJSON(data)
sleep(10000)
main()