moved all of my config into this nix flake

This commit is contained in:
Sebastian Moser
2023-10-28 19:10:37 +02:00
parent 9facde9d3a
commit 112ef46fd2
46 changed files with 3545 additions and 0 deletions

5
scripts/nav/db Normal file
View File

@@ -0,0 +1,5 @@
* H ~
* / /
~ w ~/work
~/work c config

58
scripts/nav/main.py Normal file
View File

@@ -0,0 +1,58 @@
import shlex
from pathlib import Path
from os import path
import os
DB_FILE = "/home/me/work/config/nav/db"
def main():
pwd = Path(os.getcwd())
db_matches = get_db_matches(pwd)
folder_matches = get_folder_matches(pwd)
print(my_resolve("~/work/config/"))
print("db:", db_matches)
print("folder:", folder_matches)
def get_db_matches(directory):
matches = []
with open(DB_FILE, "r") as file:
for line in file.readlines():
tmp = shlex.split(line)
try:
dir_in = tmp[0]
shortcut = tmp[1]
dest = tmp[2]
except:
continue
if dir_in == "*":
matches.append((shortcut, dest))
if dir_in == "~":
#if directory == Path.home():
matches.append((shortcut, dest))
return matches
def get_folder_matches(directory):
matches = []
ls = os.listdir(directory)
return matches
def my_resolve(path):
if str(path)[0] == "~":
path_as_list = list(str(path))
path_as_list.pop(0)
print("path_as_list:", path_as_list)
return Path(str(Path.home()) + "".join(path_as_list))
return path.resolve()
if __name__ == "__main__":
main()

17
scripts/size.py Normal file
View File

@@ -0,0 +1,17 @@
import sys
s = 0
for line in sys.stdin:
(val, unit) = line.split(" ")
val = float(val)
if "MiB" in unit:
val *= 1000
s += val
print("MB: ", round(s/1000))
print("GB: ", round(s/1000000))

309
scripts/song Executable file
View File

@@ -0,0 +1,309 @@
#!/usr/bin/env python3
# written while listening to mocking bird on loop
# if you really went through my config in that much detail...
# ... to stumble upon this weired script i wrote a long time ago
# ... please message me on discord (@c2vi) about it!!
from datetime import datetime
import sys
import json
import requests
import base64
import os
with open("~/.mysecrets/spotify-client-id", "r") as file:
CLIENT_ID = file.read()
with open("~/.mysecrets/spotify-client-secret", "r") as file:
CLIENT_SECRET = file.read()
LIST_COUNT = 6
FILL_TO = 45
CONF_PATH = os.getenv("SONG_CONF_PATH")
if CONF_PATH == "":
print("No SONG_CONF_PATH environment variable found")
exit(1)
def get_token():
url = "https://accounts.spotify.com/api/token"
form_data = {"grant_type": "client_credentials"}
message = CLIENT_ID + ":" + CLIENT_SECRET
message_bytes = message.encode('ascii')
base64_bytes = base64.b64encode(message_bytes)
auth_base64 = base64_bytes.decode('ascii')
headers = {
"user-agent": "Hi Spotify.....xD",
"Authorization": f"Basic {auth_base64}",
}
x = requests.post(url, headers=headers, data=form_data)
data = x.json()
return data["access_token"]
def spotify_search(name):
token = get_token()
url = "https://api.spotify.com/v1/search"
headers = {
"user-agent": "Hi Spotify.....xD",
"Authorization": f"Bearer {token}",
}
params = {"q": name, "type": "track"}
x = requests.get(url, headers=headers, params=params)
data = x.json()
count = 0
for track in data["tracks"]["items"]:
count += 1
if count > LIST_COUNT:
break
#print(track.keys())
name = track["name"]
artists = get_artists(track)
out = f"{count}) {name}"
out = fill(out)
out += f"BY: {artists}"
print(out)
try:
number = int(input("NUMBER: "))
return data["tracks"]["items"][number -1]
except:
exit(1)
def get_artists(track):
artists = ""
for artist in track["artists"]:
if artists != "":
artists += " --- " + artist["name"]
else:
artists += artist["name"]
return artists
def add_track(track, pos = None):
# get the track id
# first letter , or first two, ....
count = 1
myid = track["name"][0:count]
while get_track_pos(myid) != -1:
count += 1
myid = track["name"][0:count]
if count == 2000:
print("Count went to 2000 in add_track")
exit(1)
mytrack = {
"id": track["id"],
"name": track["name"],
"artists": get_artists(track),
"myid": myid,
}
if pos == None:
config["now"].append(mytrack)
else:
config["now"].insert(pos -1, mytrack)
config["log"].append({
"type": "add",
"track": mytrack,
"time": now.strftime("%m/%d/%Y-%H:%M:%S"),
})
def set_track(track_id, pos):
mytrack = get_track_from_myid(track_id)
old_pos = get_track_pos(track_id)
config["now"].pop(old_pos)
config["now"].insert(pos, mytrack)
config["log"].append({
"type": "move",
"track": mytrack,
"time": now.strftime("%m/%d/%Y-%H:%M:%S"),
"from": old_pos +1,
"to": pos +1,
})
def get_track_pos(track_or_myid):
id = ""
if type(track_or_myid) == dict:
id = track_or_myid["myid"]
else:
id = track_or_myid
count = 0
for track in config["now"]:
if track["myid"] == id:
return count
count += 1
return -1
def get_track_from_myid(myid):
for track in config["now"]:
if track["myid"] == myid:
return track
print(f"Track {myid} not found")
exit(1)
def remove_track(track_or_myid):
myid = ""
if type(track_or_myid) == dict:
myid = track_or_myid["myid"]
else:
myid = track_or_myid
config["log"].append({
"type": "remove",
"track": get_track_from_myid(myid),
"time": now.strftime("%m/%d/%Y-%H:%M:%S"),
})
new_tracks = []
for track in config["now"]:
if track["myid"] != myid:
new_tracks.append(track)
config["now"] = new_tracks
def list_track():
count = 0
for track in config["now"]:
count += 1
out = str(count) + ") " + track["myid"]
out = fill(out, l=10)
out += track["name"]
out = fill(out)
out += "BY: " + track["artists"]
print(out)
def fill(string, l = FILL_TO):
count = 0
while len(string) < l:
string += " "
count += 1
return string
def log():
for entry in config["log"]:
typ = entry["type"]
name = entry["track"]["name"]
time = entry["time"]
if typ == "move":
fro = entry["from"]
to = entry["to"]
print(f"MOVE \t from {fro} to {to} \t {time} \t {name}")
elif typ == "add":
print(f"ADD \t {time} \t {name}")
elif typ == "remove":
print(f"REMOVE \t {time} \t {name}")
def main():
searh_term = " ".join(args[2:len(args)])
if args[1] == "s":
track = spotify_search(searh_term)
elif args[1] == "a" or args[1] == "add":
try:
pos = int(args[2])
print("Inserting at pos:", pos)
searh_term = " ".join(args[3:len(args)])
track = spotify_search(searh_term)
add_track(track, pos = pos)
except:
track = spotify_search(searh_term)
add_track(track)
elif args[1] == "rm":
remove_track(args[2])
elif args[1] == "l":
list_track()
elif args[1] == "st" or args[1] == "set":
set_track(args[2], int(args[3]) -1)
list_track()
elif args[1] == "up":
pos = get_track_pos(args[2])
delta = 1
try:
delta = int(args[3])
except:
pass
set_track(args[2], pos - delta)
list_track()
elif args[1] == "down" or args[1] == "dn":
pos = get_track_pos(args[2])
delta = 1
try:
delta = int(args[3])
except:
pass
set_track(args[2], pos + delta)
list_track()
elif args[1] == "log" and len(args) >= 3 and args[2] == "rm":
num = 1
try:
num = int(args[3])
except:
pass
config["log"] = config["log"][0:-num]
log()
elif args[1] == "log":
log()
else:
print("Unknown command!")
exit(1)
if __name__ == "__main__":
args = sys.argv
now = datetime.now()
# read config
with open(CONF_PATH, "r") as file:
config = json.loads(file.read())
# init config
if config.get("log", None) == None:
config["log"] = []
if config.get("now", None) == None:
config["now"] = []
main()
# write config
with open(CONF_PATH, "w") as file:
file.write(json.dumps(config))

155
scripts/win Executable file
View File

@@ -0,0 +1,155 @@
#!/bin/bash
#default_vm_name=windp
#default_vm_uuid=12650dba-6232-40d8-9863-6c2bb267a0c9
#default_vm_name=tiny10
#default_vm_uuid=6a412143-871f-4838-bacd-5dcfa5fa95c3
username=me
password=$(cat ~/.mysecrets/win-vm-pwd)
if [ "$1" == "-o" ];then
cmd=$4
default_vm_name=$2
default_vm_uuid=$2
default_vm_ip=$3
else
cmd=$1
fi
#do stuff
if [ "$cmd" == "st" ];then
sudo umount /home/sebastian/winwork
#virsh -c qemu:///system attach-disk 12650dba-6232-40d8-9863-6c2bb267a0c9 /dev/nvme0n1 sdd --targetbus virtio --persistent
virsh -c qemu:///system start $default_vm_uuid
#sleep 30
#sudo mount -t cifs //192.168.122.4/winwork /home/sebastian/winwork -o user=$username -o password=$password -o uid=1000 -o gid=1000
elif [ "$cmd" == "h" ];then
sudo mount /home/sebastian/winwork
elif [ "$cmd" == "c" ];then
virt-manager --connect qemu:///system --show-domain-editor $default_vm_uuid
elif [ "$cmd" == "sm" ];then
sudo umount /home/sebastian/winwork
virsh -c qemu:///system managedsave $default_vm_uuid
elif [ "$cmd" == "s" ];then
virsh -c qemu:///system domstate $default_vm_uuid
elif [ "$cmd" == "ld" ];then
virsh -c qemu:///system domblklist --domain $default_vm_uuid --details
echo ----------------------------------------
virsh -c qemu:///system dumpxml $default_vm_uuid | grep sdd
elif [ "$cmd" == "w" ];then
virsh -c qemu:///system attach-disk $default_vm_uuid /dev/nvme0n1 sdd --targetbus virtio --persistent
sleep 0.5
sudo mount -t cifs //$default_vm_ip/winwork /home/sebastian/winwork -o user=$username -o password=$password -o uid=1000 -o gid=1000
elif [ "$cmd" == "m" ];then
sudo mount -t cifs //$default_vm_ip/winwork /home/sebastian/winwork -o user=$username -o password=$password -o uid=1000 -o gid=1000
elif [ "$cmd" == "u" ];then
virsh -c qemu:///system attach-disk $default_vm_uuid /dev/nvme0n1 sdd --targetbus usb --persistent
sleep 0.5
sudo mount -t cifs //$default_vm_ip/winwork /home/sebastian/winwork -o user=$username -o password=$password -o uid=1000 -o gid=1000
elif [ "$cmd" == "uu" ];then
virsh -c qemu:///system detach-disk $default_vm_uuid /dev/nvme0n1 --persistent
sudo umount /home/sebastian/winwork
elif [ "$cmd" == "uw" ];then
#sudo modprobe shpchp
#sudo modprobe acpiphp
virsh -c qemu:///system detach-disk $default_vm_uuid /dev/nvme0n1 --persistent
virsh -c qemu:///system shutdown $default_vm_uuid
elif [ "$cmd" == "sp" ];then
virsh -c qemu:///system shutdown $default_vm_uuid
virsh -c qemu:///system shutdown $default_vm_uuid
virsh -c qemu:///system shutdown $default_vm_uuid
#sleep 15
#virsh -c qemu:///system detach-disk $default_vm_uuid /dev/nvme0n1 --persistent
#sudo mount /home/sebastian/winwork
elif [ "$cmd" == "p" ];then
sudo umount /home/sebastian/winwork
virsh -c qemu:///system suspend $default_vm_uuid
#sleep 0.2
#kill -SIGSTOP $(pgrep qemu)
elif [ "$cmd" == "up" ];then
#kill -SIGCONT $(pgrep qemu)
#sleep 0.2
virsh -c qemu:///system resume $default_vm_uuid
sleep 0.2
sudo mount -t cifs //$default_vm_ip/winwork /home/sebastian/winwork -o user=$username -o password=$password -o uid=1000 -o gid=1000
elif [ "$cmd" == "f" ];then
RDP_SCALE=100
MULTI_FLAG="span"
RDP_USER=$username
RDP_PASS=$password
RDP_IP=$default_vm_ip
xfreerdp ${RDP_FLAGS} /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} /scale:${RDP_SCALE} /dynamic-resolution +clipboard +auto-reconnect +home-drive /wm-class:"Microsoft Windows" -grab-keyboard 1> /dev/null 2> /dev/null &
#xfreerdp ${RDP_FLAGS} /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} /scale:${RDP_SCALE} /dynamic-resolution +clipboard +auto-reconnect +home-drive /wm-class:"Microsoft Windows" -grab-keyboard
#
elif [ "$cmd" == "fl" ];then
RDP_SCALE=100
MULTI_FLAG="span"
RDP_USER=$username
RDP_PASS=$password
RDP_IP=$default_vm_ip
xfreerdp ${RDP_FLAGS} /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} /scale:${RDP_SCALE} /dynamic-resolution +clipboard +auto-reconnect +home-drive /wm-class:"Microsoft Windows" -grab-keyboard
elif [ "$cmd" == "fup" ];then
#kill -SIGCONT $(pgrep qemu)
#echo cont
#sleep 0.2
virsh -c qemu:///system resume $default_vm_uuid
sleep 0.4
sudo mount -t cifs //$default_vm_ip/winwork /home/sebastian/winwork -o user=$username -o password=$password -o uid=1000 -o gid=1000
sleep 0.2
RDP_SCALE=100
MULTI_FLAG="span"
RDP_USER=$username
RDP_PASS=$password
RDP_IP=$default_vm_ip
xfreerdp ${RDP_FLAGS} /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} /scale:${RDP_SCALE} /dynamic-resolution +clipboard +auto-reconnect +home-drive /wm-class:"Microsoft Windows" -grab-keyboard 1> /dev/null 2> /dev/null &
elif [ "$cmd" == "l" ];then
looking-glass-client -m KEY_END
fi