Skip to content

Commit

Permalink
fix: misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Nov 29, 2023
1 parent 37619ce commit 8fa0a7f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
1 change: 1 addition & 0 deletions home/.config/autoimport/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
"dataclass" = "from dataclasses import dataclass"
"sleep" = "from time import sleep"
"Path" = "from pathlib import Path"
"pytest" = "import pytest"
2 changes: 2 additions & 0 deletions home/.config/fish/config.fish
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ end

#source /opt/anaconda/etc/fish/conf.d/conda.fish

set -x EDITOR nvim

# Set FREESURFER_HOME for easier surfin'
set FREESURFER_HOME /opt/freesurfer

Expand Down
3 changes: 2 additions & 1 deletion home/.config/i3/config
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,14 @@ assign [class="Logseq"] $ws4

# Audio/music on workspace 5
assign [class="Pavucontrol"] $ws5
assign [class="Blueman-manager"] $ws5
for_window [class="Spotify"] move to workspace $ws5

# Chat on workspace 6
assign [class="discord"] $ws6

# Steam on workspace 8
assign [class="Steam"] $ws8
assign [class="steam"] $ws8


####################
Expand Down
49 changes: 35 additions & 14 deletions home/.config/i3status/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# This script is a simple wrapper which prefixes each i3status line with custom
# information. It is a python reimplementation of:
# http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.pl
Expand All @@ -23,30 +22,32 @@
# the terms of the Do What The Fuck You Want To Public License (WTFPL), Version
# 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
# details.

import sys
import json
import subprocess
import glob
import requests
import json
import logging

import subprocess
import sys
from datetime import datetime, timedelta
from pathlib import Path
from typing import Optional

import requests

logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger(__name__)


def get_governor():
""" Get the current governor for cpu0, assuming all CPUs use the same. """
"""Get the current governor for cpu0, assuming all CPUs use the same."""
with open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor") as fp:
return fp.readlines()[0].strip()


def get_idletime() -> int:
p = subprocess.run("xprintidle", capture_output=True)
try:
p = subprocess.run("xprintidle", capture_output=True)
except FileNotFoundError:
return 666 * 24 * 60 * 60
return int(round(int(str(p.stdout, "ascii").strip()) / 1000))


Expand Down Expand Up @@ -80,6 +81,18 @@ def get_power_draw() -> float:
return 0


def format_idle_time(idle_time: int) -> str:
idlestr = ""
if idle_time > 60 * 60 * 24:
idlestr += f"{idle_time // (60 * 60 * 24)}d "
if idle_time > 60 * 60:
idlestr += f"{idle_time // (60 * 60) % 24}h "
if idle_time > 60:
idlestr += f"{idle_time // 60 % 60}m "
idlestr += f"{idle_time % 60}s"
return idlestr


gasPricePath = Path("/tmp/gasPrice.json")
ethPricePath = Path("/tmp/ethPrice.json")
APIKEY = "8AKPUEVKW3UNFKIXRTS5HW5WMWG1UX68QH"
Expand Down Expand Up @@ -140,17 +153,17 @@ def get_eth_price():

with open(ethPricePath, "r") as f:
d = json.load(f)
return float(d["result"]["ethusd"])
return round(float(d["result"]["ethusd"]))


def print_line(message):
""" Non-buffered printing to stdout. """
"""Non-buffered printing to stdout."""
sys.stdout.write(message + "\n")
sys.stdout.flush()


def read_line():
""" Interrupted respecting reader for stdin. """
"""Interrupted respecting reader for stdin."""
# try reading a line, removing any extra whitespace
try:
line = sys.stdin.readline().strip()
Expand Down Expand Up @@ -276,10 +289,18 @@ def colorpick(

idletime = get_idletime()
idlecolor = colorpick(
idletime, max_value=3 * 60, max_color="#AAAAAA", above_max_color="#FF5500"
idletime,
max_value=3 * 60,
max_color="#AAAAAA",
above_max_color="#FF5500",
)
j.insert(
0, {"full_text": "💤 %ss" % idletime, "name": "idle", "color": idlecolor}
0,
{
"full_text": "💤 %s" % format_idle_time(idletime),
"name": "idle",
"color": idlecolor,
},
)

# and echo back new encoded json
Expand Down
2 changes: 1 addition & 1 deletion home/.vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
" - Fix proper pane/window/buffer config
" - Split into seperate files: one base, one for keys, one for theme, one for syntax, one for plugins
" - Make pageup/pagedown move half page and center view
"

" Set leader key to space
let mapleader = "\<Space>"
Expand Down Expand Up @@ -326,6 +325,7 @@ call plug#end()
let g:copilot_filetypes = {
\ 'markdown': v:true,
\ 'vue': v:true,
\ 'yml': v:true,
\}

" Set up vim-js-file-import
Expand Down

0 comments on commit 8fa0a7f

Please sign in to comment.