Adds polybar
This commit is contained in:
parent
56921bfdcc
commit
0f0b9089a4
12 changed files with 1090 additions and 0 deletions
13
.config/polybar/scripts/storage/Display.py
Normal file
13
.config/polybar/scripts/storage/Display.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import string
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
class Display:
|
||||
def __init__(
|
||||
self,
|
||||
drives
|
||||
):
|
||||
pass
|
||||
|
||||
def render(self, displayInterval: timedelta) -> string:
|
||||
pass
|
||||
47
.config/polybar/scripts/storage/SingleDisplay.py
Normal file
47
.config/polybar/scripts/storage/SingleDisplay.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import string
|
||||
from array import array
|
||||
from datetime import timedelta
|
||||
|
||||
from Display import Display
|
||||
from Utils import find_storage_usage
|
||||
|
||||
|
||||
class SingleDisplay(Display):
|
||||
SWITCH_INTERVAL: timedelta = timedelta(seconds=10)
|
||||
drives: array
|
||||
|
||||
maxLabelWidth: int
|
||||
currentTime: float
|
||||
currentIndex: int
|
||||
|
||||
def __init__(self, drives):
|
||||
self.drives = drives
|
||||
self.maxLabelWidth = self.getMaxLabelWidth()
|
||||
self.currentIndex = 0
|
||||
self.currentTime = 0
|
||||
|
||||
def render(self, displayInterval: timedelta) -> string:
|
||||
self.currentTime = self.currentTime + displayInterval.total_seconds()
|
||||
if self.currentTime < self.SWITCH_INTERVAL.total_seconds():
|
||||
return self.renderCurrentDrive()
|
||||
|
||||
self.currentTime = 0
|
||||
self.currentIndex = (self.currentIndex + 1) % len(self.drives)
|
||||
|
||||
return self.renderCurrentDrive()
|
||||
|
||||
def renderCurrentDrive(self):
|
||||
currentDrive = self.drives[self.currentIndex]
|
||||
label = currentDrive['label']
|
||||
path = currentDrive['path']
|
||||
|
||||
usage = find_storage_usage(path)
|
||||
|
||||
formatString = "{:>"+ self.maxLabelWidth.__str__() +"} {}"
|
||||
return formatString.format(label, usage)
|
||||
|
||||
def getMaxLabelWidth(self):
|
||||
maxLabelWidth = 0
|
||||
for i, drive in enumerate(self.drives):
|
||||
maxLabelWidth = max(maxLabelWidth, len(drive['label']))
|
||||
return maxLabelWidth
|
||||
8
.config/polybar/scripts/storage/Utils.py
Normal file
8
.config/polybar/scripts/storage/Utils.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import string
|
||||
import subprocess
|
||||
|
||||
|
||||
def find_storage_usage(path: string) -> string:
|
||||
output = subprocess.check_output(['df', '-h', '--output=pcent', path])
|
||||
percentage: string = output.strip().__str__().split()[1]
|
||||
return percentage.strip("'")
|
||||
18
.config/polybar/scripts/storage/config.json
Normal file
18
.config/polybar/scripts/storage/config.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"label": "Drive",
|
||||
"path": "/"
|
||||
},
|
||||
{
|
||||
"label": "Games",
|
||||
"path": "/mnt/games"
|
||||
},
|
||||
{
|
||||
"label": "Programming",
|
||||
"path": "/mnt/programming"
|
||||
},
|
||||
{
|
||||
"label": "RPI 5",
|
||||
"path": "/mnt/smb/storage"
|
||||
}
|
||||
]
|
||||
5
.config/polybar/scripts/storage/open-ranger.sh
Executable file
5
.config/polybar/scripts/storage/open-ranger.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
startPoint = $1
|
||||
|
||||
xfce4-terminal --window --working-directory="$startPoint" --title="File Manager" -x ranger
|
||||
31
.config/polybar/scripts/storage/overview.py
Executable file
31
.config/polybar/scripts/storage/overview.py
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3 -u
|
||||
import json
|
||||
import time
|
||||
from datetime import timedelta
|
||||
|
||||
import Display
|
||||
import SingleDisplay
|
||||
|
||||
CONFIG_PATH = '/home/michel/.config/polybar/scripts/storage/config.json'
|
||||
REFRESH_INTERVAL: timedelta = timedelta(seconds=1)
|
||||
|
||||
|
||||
def main():
|
||||
with open(CONFIG_PATH) as config:
|
||||
drives = json.load(config)
|
||||
|
||||
isRunning = True
|
||||
|
||||
currentDisplay: Display = SingleDisplay.SingleDisplay(drives)
|
||||
while isRunning:
|
||||
start = time.time()
|
||||
|
||||
renderedText = currentDisplay.render(REFRESH_INTERVAL)
|
||||
print(" " + renderedText)
|
||||
|
||||
duration: float = time.time() - start
|
||||
time.sleep(max(REFRESH_INTERVAL.total_seconds() - duration, 0))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
12
.config/polybar/scripts/storage/storage.sh
Executable file
12
.config/polybar/scripts/storage/storage.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
mountPoint=$1
|
||||
label=$2
|
||||
|
||||
echo Checking mount values for "$1"
|
||||
|
||||
while :
|
||||
do
|
||||
echo $label $(df -h --output=pcent "$mountPoint" | grep "[0-9]%")
|
||||
sleep 5
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue