working version after refactor

This commit is contained in:
2025-12-21 15:59:56 +03:00
parent 27c7677100
commit f5c0480f88
5 changed files with 220 additions and 399 deletions

36
TODO.md
View File

@@ -1,49 +1,49 @@
How this must work.
1. On first launch themere reads ~/.config/themer/config and aquires list of apps it should manage
2. Themer backs up whole config directories to ~/.config/themer so further manipulations are safe
Default name is themer/original, but user can provide a different name from command line.
1. On first launch userctx reads ~/.config/userctx/config and aquires list of apps it should manage
2. userctx backs up whole config directories to ~/.config/userctx so further manipulations are safe
Default name is userctx/original, but user can provide a different name from command line.
example:
themer backup [--name <name>] [--apps TODO]
userctx backup [--name <name>] [--apps TODO]
default name is "original"
default apps list is read from config. command line overrides config completely, no merging.
Backup algorithm:
- If directory ~/.config/sway does not exist or is empty will do nothing
- if directory exists AND not empty then create directory ~/.config/themer/original/sway
- copy contents of all files AND direcotries in it to ~/.config/themer/original/sway
- if any file failed to copy - rollback and remove ~/.config/themer/original/sway
- if directory exists AND not empty then create directory ~/.config/userctx/original/sway
- copy contents of all files AND direcotries in it to ~/.config/userctx/original/sway
- if any file failed to copy - rollback and remove ~/.config/userctx/original/sway
- remove original files (and directories) from ~/.config/sway
- create symlinks to copied files in ~/.config/sway
3. Swithing algorithm:
User requests theme change with:
themer apply <theme>
userctx apply <theme>
Themer tries to apply configs as follows:
userctx tries to apply configs as follows:
- looks up a list of apps it should manage; if list is empty - return non-zero
- looks up requested theme name in ~/.config/themer/<name>; if not found - return non-zero
- looks up config dir ~/.config/themer/<theme>/<app>; if none found - return non-zero
- for each <filename> in ~/.config/themer/<theme>/<app> themer does
- looks up requested theme name in ~/.config/userctx/<name>; if not found - return non-zero
- looks up config dir ~/.config/userctx/<theme>/<app>; if none found - return non-zero
- for each <filename> in ~/.config/userctx/<theme>/<app> userctx does
```
mkdir -p ~/.config/<app> # creates app config directory if it does not exist (else no-op)
rm -f ~/.config/<app>/<filename> # tries to delete the config if it exists (else no-op)
ln -s ~/.config/themer/<theme>/<app>/<filename> ~/.config/<app>/<filename> # symlinks the file from requested theme user dir
ln -s ~/.config/userctx/<theme>/<app>/<filename> ~/.config/<app>/<filename> # symlinks the file from requested theme user dir
```
- after creating symlinks themer tries to let the app know that config changed
- after creating symlinks userctx tries to let the app know that config changed
- if app has hot-reload (niri, alacritty, hyprland) - do nothing
- if app re-reads configs on start (fuzzel, wofi) - do nothing
- if app obeys USR1/URS2 - issue the signal
- if app is a systemd service - exec systemctl --user restart <app>
This way a single copy of config files are kept in ~/.config/themer.
This way user can choose which files to manage themselves and which themer
This way a single copy of config files are kept in ~/.config/userctx.
This way user can choose which files to manage themselves and which userctx
should manage.
4. cli interface
themer list - returns newline-separated list (suitable for dmenu)
themer apply $(themer list | fuzzel -d) - a usable way to select theme with dmenu-like apps
userctx list - returns newline-separated list (suitable for dmenu)
userctx apply $(userctx list | fuzzel -d) - a usable way to select theme with dmenu-like apps
TODO: