add os config

This commit is contained in:
ant 2025-05-21 22:58:44 +02:00
parent d8d692d313
commit 33bf5ec883
30 changed files with 271 additions and 5 deletions

35
home/bin/dark.fish Executable file
View file

@ -0,0 +1,35 @@
if test -e $XDG_STATE_HOME/darkmode
rm $XDG_STATE_HOME/darkmode
set LIGHT 1
else
echo > $XDG_STATE_HOME/darkmode
set LIGHT 0
end
if test $LIGHT = 1;
notify-send "Light mode"
rm -f ~/.config/kitty/colors.conf
ln -rs ~/.config/kitty/light.conf ~/.config/kitty/colors.conf
kill -SIGUSR1 $(pgrep kitty) # reload kitty config
rm -f ~/.local/share/bg/*
ln -rs ~/.local/share/bg-light.* ~/.local/share/bg/
hyprctl reload
rm -f ~/.config/rofi/colors-current.rasi
ln -rs ~/.config/rofi/colors-light.rasi ~/.config/rofi/colors-current.rasi
else
notify-send "Dark mode"
rm -f ~/.config/kitty/colors.conf
ln -rs ~/.config/kitty/dark.conf ~/.config/kitty/colors.conf
kill -SIGUSR1 $(pgrep kitty) # reload kitty config
rm -f ~/.local/share/bg/*
ln -rs ~/.local/share/bg-dark.* ~/.local/share/bg/
hyprctl reload
rm -f ~/.config/rofi/colors-current.rasi
ln -rs ~/.config/rofi/colors-dark.rasi ~/.config/rofi/colors-current.rasi
end

46
home/bin/dark.nix Executable file
View file

@ -0,0 +1,46 @@
{ pkgs, ... } :
pkgs.writers.writeFish "dark" ''
if test -e $XDG_STATE_HOME/darkmode
rm $XDG_STATE_HOME/darkmode
set LIGHT 1
else
echo > $XDG_STATE_HOME/darkmode
set LIGHT 0
end
if test $LIGHT = 1;
${pkgs.libnotify}/bin/notify-send "Light mode"
rm -f ~/.config/kitty/colors.conf
ln -rs ~/.config/kitty/light.conf ~/.config/kitty/colors.conf
kill -SIGUSR1 $(pgrep kitty) # reload kitty config
kill -SIGUSR1 $(pgrep st) # reload st config
rm -f ~/.local/share/bg/*
ln -rs ~/.local/share/bg-light.* ~/.local/share/bg/
${pkgs.hyprland}/bin/hyprctl reload
rm -f ~/.config/rofi/colors-current.rasi
ln -rs ~/.config/rofi/colors-light.rasi ~/.config/rofi/colors-current.rasi
${pkgs.dconf}/bin/dconf write /org/gnome/desktop/interface/color-scheme "'prefer-light'"
else
${pkgs.libnotify}/bin/notify-send "Dark mode"
rm -f ~/.config/kitty/colors.conf
ln -rs ~/.config/kitty/dark.conf ~/.config/kitty/colors.conf
kill -SIGUSR1 $(pgrep kitty) # reload kitty config
kill -SIGUSR1 $(pgrep st) # reload st config
rm -f ~/.local/share/bg/*
ln -rs ~/.local/share/bg-dark.* ~/.local/share/bg/
${pkgs.hyprland}/bin/hyprctl reload
rm -f ~/.config/rofi/colors-current.rasi
ln -rs ~/.config/rofi/colors-dark.rasi ~/.config/rofi/colors-current.rasi
${pkgs.dconf}/bin/dconf write /org/gnome/desktop/interface/color-scheme "'prefer-dark'"
end
''

72
home/bin/notifications Executable file
View file

@ -0,0 +1,72 @@
#!/bin/env python
import os, sys
# take at most n elements
def take(it, n):
for i, x in enumerate(it):
if i == n:
break
yield x
# above an example of the format
def parse(s):
def split():
i, j = 0, 0
level = 0
while i < len(s):
if s[i] == '{':
if level == 0:
j = i
level += 1
elif s[i] == '}':
level -= 1
if level == 0:
yield s[j:i+1]
i += 1
def section_to_dict(section):
d = {}
for line in section.split('\n'):
line_stripped = line.strip()
if ':' in line_stripped:
k, v = line_stripped.split(':', 1)
if k in ['appname', 'summary', 'body', 'urgency']:
if k in ['appname', 'summary', 'body']:
d[k] = v.strip().strip("'")
if k == 'urgency':
d[k] = v.strip()
return d
return map(section_to_dict, reversed(list(split())))
def pretty_print(notification):
colors_from_urgency = { # posix escape codes
"NORMAL": (2, None),
"URGENT": (1, 7),
}
def enclose_color(s, fg, bg):
def color_code(c):
if c is not None:
return f"\033[38;5;{c}m"
return ""
return f"{color_code(fg)}{color_code(bg)}{s}\033[0m"
#]] nvim's python parser if fucked without this
fg, bg = colors_from_urgency[notification['urgency']]
return f"{enclose_color(notification['summary'], fg, bg)} :: {notification['body']}"
with open(os.path.expanduser("~/.local/state/notifications-history"), "r") as f:
s = f.read()
notifications = parse(s)
if len(sys.argv) == 2:
try:
notifications = take(notifications, int(sys.argv[1]))
except ValueError as e:
print("Argument must be the number of notifications to show", file=sys.stderr)
raise e
for notification in notifications:
print(pretty_print(notification))

3
home/bin/ocrzone Executable file
View file

@ -0,0 +1,3 @@
f=$(mktemp --suffix .png)
${pkgs.sway-contrib.grimshot}/bin/grimshot save area $f
${pkgs.tesseract}/bin/tesseract -l fra "$f" - | wl-copy

19
home/bin/quickrun.fish Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env nix-shell
#!nix-shell -i fish
#!nix-shell -p fish gcc
set file (realpath $argv[1])
set workdir (mktemp -d)
cd $workdir
set extension (string match -r '\.([a-z]+)$' $file | head -n 1)
switch $extension
case ".c"
gcc -o a.out $file
./a.out
case ".py"
python $file
end

1
home/bin/runmenu Executable file
View file

@ -0,0 +1 @@
${pkgs.rofi-wayland}/bin/rofi -matching normal -sort -show run

47
home/bin/screenshot.nix Executable file
View file

@ -0,0 +1,47 @@
{ pkgs, ... }:
pkgs.writers.writePython3 "screenshot" { flakeIgnore = [ "E501" ];} ''
import subprocess
import re
options = """\
a selected area (copy)
current window (copy)
full screen (copy)
a selected area
current window
full screen
viewer
"""
cmd = '${pkgs.rofi-wayland}/bin/rofi -dmenu -location 2 -l 7 -i -p "Screenshot which area?"'
result = subprocess.run(cmd,
input=options,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
text=True)
if result.returncode != 0:
exit(1)
choice = result.stdout.strip()
cmd = "${pkgs.pkgs.sway-contrib.grimshot}/bin/grimshot "
if choice == "viewer":
filename = subprocess.getoutput("mktemp")
cmd += f"save area {filename}"
else:
cmd += "copy " if re.match(".*(copy)", choice) else "save "
for k, v in {"a selected area.*": "area ",
"current window.*": "active ",
"current screen.*": "output ",
"all screens.*": "screen "}.items():
if re.match(k, choice):
cmd += v
subprocess.call(cmd,
shell=True)
if choice == "viewer":
subprocess.run(f"nsxiv -b {filename}", shell=True)
''

6
home/bin/window_dir Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
PID=$(hyprctl activewindow | grep pid | cut -d' ' -f 2)
PID=$(echo $(ps --ppid $PID -o pid | tail -n1))
cwd=$(readlink /proc/"$PID"/cwd)
echo "$cwd"

29
home/bin/wl Executable file
View file

@ -0,0 +1,29 @@
#!/bin/sh
cd ~
# Log WLR errors and logs to the hyprland log. Recommended
export HYPRLAND_LOG_WLR=1
# Tell XWayland to use a cursor theme
export XCURSOR_THEME=Bibata-Modern-Classic
# Set a cursor size
export XCURSOR_SIZE=24
# Example IME Support: fcitx
# export GTK_IM_MODULE=fcitx
# export QT_IM_MODULE=fcitx
# export XMODIFIERS=@im=fcitx
# export SDL_IM_MODULE=fcitx
# export GLFW_IM_MODULE=ibus
export WLR_NO_HARDWARE_CURSORS=1
if lsmod | grep nvidia; then
export LIBVA_DRIVER_NAME=nvidia
export XDG_SESSION_TYPE=wayland
# export GBM_BACKEND=nvidia-drm
export __GLX_VENDOR_LIBRARY_NAME=nvidia
fi
exec Hyprland