Much better this way instead of having them written inside nix files.
G37S7SNBZOENYHQ4BUJFJCVERK2UIEHMHP2XIUCK7M533BTYANKQC RQPVT3ZCBSHX3G4MSHNZIRQOH6USU7ORK5NH7KGGA4BWNY4NFLTAC BHIAZJSYUKCZ5IEK6UGND323S5VET6DIHZ7WJNL2EZKPHU7EBU2QC HYWEG52CLGAF54BUZO53SGBVT6UKVPMW2BN5WX35OJSJ4RW4F6RAC 56Y2LW23MBWE32GB4CG6M3HFMXYVV2CA35D3CMJZ2OUUMYTOVJDQC 2JY3U267UGSQIRWAA5SRMZFXG63GE7YKPQIRC7VJGPJBRFWBQKMAC VMXFJWDNNALYIQN2IKBCKBS3IJYWUMCOF662YVOCY65QSMZLVP3QC HQPNOOD4GP64H6SP5MQ4LS7CPE3ECPXXJWGEW6MEUS6IEF7WHYBQC XA5LGQOD57DPTH236X5URXVPJIXJKKKYE2KXMRLRHAJCUUQAZUDAC OR3HZBQULJZGQDIKRP4NC32KGOIHFOPKHY5BYKROGBSSCLOOXL6QC XDQJIGSQQ4UIPBO3QCJI73QU3UY4ORJOQXBMR5LSBZ72MBXSNPJAC CG4ND52NJKGW4ZWDVJTNEL63CFPMLUVFXCDZFBQSRIO5QMBQVVXAC WYLRCRR3GKEEFDE333WOMPWUZ2K5BX7KCU35MDHZVGFVBRGU7GWQC YVII7NUI5Z6DPUDQZG2ZVJ6QNQRCEUYX5547IYCMPZI7GJ3GDZQAC L65HGT7CTSNIYIWGYIXPOWCXZZSNHXV5AV3TUBTTDBBPCYLSN4OQC X4ZFOU74NCNVUCNV2EJLKOTNXQK6EFX7MYOH7W4ZI45QD7SKTRPQC RTBMBSBABSGTRICJ4AWBKWO3JJHBRKV6FGOMYPDD7X6SS6X35ZIQC pickWallpaper = pkgs.writeScriptBin "pick-wallpaper" /* nu */ ''#!/usr/bin/env nudef main [] {let wallpaper_dir = $"($env.HOME)/wallpapers"mkdir $wallpaper_dirlet wallpapers = (ls $wallpaper_dir | where type == file | where name =~ '\.(jpg|png|jpeg|webp|gif)$')if ($wallpapers | is-empty) {print $"No wallpapers found in ($wallpaper_dir)"exit 1}let selected = ($wallpapers| get name| str join "\n"| ${pkgs.fzf}/bin/fzf --preview $"${pkgs.chafa}/bin/chafa --size 40x20 {}" --preview-window=right:50% --prompt="Select wallpaper: ")if not ($selected | is-empty) {${pkgs.swww}/bin/swww img $selected o+e>| ignoreprint $"Wallpaper set: (($selected | path basename))"let theme_config = try {open $"($env.HOME)/nixos/modules/theme.json"} catch {{ mode: "light", scheme: "pywal" }}let using_pywal = $theme_config.scheme == "pywal"if $using_pywal {print "Regenerating pywal colors..."let is_dark = $theme_config.mode == "dark"try {rm -rf ~/.cache/wallet base_args = ["-n" "--backend" "wal" "-i" $selected]let mode_args = if $is_dark {["--saturate" "0.5"]} else {["--saturate" "0.75" "-l"]}${pkgs.pywal}/bin/wal ...($base_args | append $mode_args) err> /dev/nullcp ~/.cache/wal/colors.json $"($env.HOME)/nixos/modules/theme-pywal-colors.json"print "Colors regenerated!"try { /home/jam/nixos/rebuild.nu } catch { exit 1 }print "Rebuilt system to apply colors."} catch { |e|print $"Warning: Failed to regenerate colors: ($e.msg)"}}}}'';# Theme toggle scriptthemeToggleScript = pkgs.writeScriptBin "tt" /* nu */ ''#!${pkgs.nushell}/bin/nudef print-notify [message: string, progress: int = -1] {print $"(ansi purple)[Theme Switcher](ansi rst) ($message)"${pkgs.libnotify}/bin/notify-send "Theme Switcher" $"($message)"}
let base_args = ["-n" "--backend" "wal" "-i" $wallpaper]let mode_args = if $is_dark {["--saturate" "0.5"]} else {["--saturate" "0.75" "-l"]}${pkgs.pywal}/bin/wal ...($base_args | append $mode_args) err> /dev/null${pkgs.coreutils}/bin/cp ~/.cache/wal/colors.json $"($env.HOME)/nixos/modules/theme-pywal-colors.json"}def reload-applications [] {print-notify "Reloading applications to apply themes..."try {niri msg action do-screen-transition --delay-ms 0 | complete# pkill -USR2 waybar | completepkill -USR1 kitty | completepkill -USR2 ghostty | completepkill -USR1 hx | completesystemctl --user restart mako | completemakoctl reload | complete# pkill -SIGTERM ashell | complete # Need to check if necessary for reloading.pkill -SIGTERM brave | completesleep 1secniri msg action do-screen-transition --delay-ms 500 | complete# niri msg action spawn -- ashell | completeniri msg action spawn -- brave | complete} catch {|e|print $e.msg}}def toggle-theme [theme?: string] {let theme_config = try {open $"($env.HOME)/nixos/modules/theme.json"} catch {{ mode: "light", scheme: "pywal" }}let current_theme = $theme_config.modelet using_pywal = $theme_config.scheme == "pywal"let new_theme = if $theme != null {if $theme in ["light", "dark"] {$theme} else {print-notify $"Invalid theme: '($theme)'. Use 'light' or 'dark'."return}} else {print-notify "Theme argument required. Use 'light' or 'dark'."return}print-notify $"Switching to ($new_theme) theme."if $using_pywal {print-notify "Regenerating pywal colors..."let wallpaper = try {${pkgs.swww}/bin/swww query | lines | first | parse "{monitor}: image: {path}" | get path.0} catch {null}if $wallpaper != null and ($wallpaper | path exists) {try {generate-pywal-colors $wallpaper ($new_theme == "dark")print-notify $"Regenerated ($new_theme) mode pywal colors."} catch { |e|print-notify $"Warning: Failed to regenerate pywal colors: ($e.msg)"}} else {print-notify "Warning: Could not detect current wallpaper"}}print-notify "Updating theme configuration..."$env.THEME_MODE = $new_themelet theme_json = $"($env.HOME)/nixos/modules/theme.json"{ mode: $new_theme, scheme: $theme_config.scheme } | to json | save $theme_json --forceprint-notify $"($new_theme | str capitalize) mode activated."print-notify $"Rebuilding configuration to apply ($new_theme) theme."try { /home/jam/nixos/rebuild.nu } catch { exit 1 }print-notify $"Switch to the ($new_theme) theme completed!"reload-applications}def switch-scheme [scheme: string] {if $scheme not-in ["pywal", "gruvbox"] {print-notify $"Invalid scheme: '($scheme)'. Use 'pywal' or 'gruvbox'."return}print-notify $"Switching to ($scheme) color scheme."let theme_config = try {open $"($env.HOME)/nixos/modules/theme.json"} catch {{ mode: "light", scheme: "pywal" }}if $scheme == "pywal" {print-notify "Generating pywal colors from current wallpaper..."let is_dark = $theme_config.mode == "dark"let wallpaper = try {${pkgs.swww}/bin/swww query | lines | first | parse "{monitor}: image: {path}" | get path.0} catch {null}if $wallpaper != null and ($wallpaper | path exists) {try {generate-pywal-colors $wallpaper $is_darkprint-notify "Generated pywal colors."} catch { |e|print-notify $"Warning: Failed to generate colors: ($e.msg)"}} else {print-notify "Warning: Could not detect current wallpaper"}}$env.THEME_SCHEME = $schemelet theme_json = $"($env.HOME)/nixos/modules/theme.json"{ mode: $theme_config.mode, scheme: $scheme } | to json | save $theme_json --forceprint $"Updated THEME_SCHEME to ($scheme)"print-notify $"Rebuilding configuration to apply ($scheme) scheme..."try { /home/jam/nixos/rebuild.nu } catch { exit 1 }print-notify $"Switch to ($scheme) scheme completed!"reload-applications}def --wrapped main [arg?: string...rest: string]: nothing -> nothing {if $arg == null {print "Usage: tt <dark|light|pywal|gruvbox|reload>"return}match $arg {"dark" | "light" => { toggle-theme $arg }"pywal" | "gruvbox" => { switch-scheme $arg }"reload" => {reload-applicationstry { /home/jam/nixos/rebuild.nu } catch { exit 1 }}_ => { print $"Invalid option: '($arg)'. Use: dark, light, pywal, gruvbox or reload." }}}'';
themeToggleScript = pkgs.writeScriptBin "tt" (readFile ./nushell.toggle-theme.nu);
processKiller = pkgs.writeScriptBin "process-killer" /* nu */ ''#!${pkgs.nushell}/bin/nudef get_processes [] {let nu_pids = ps | where name == "nu" | get pidlet filter_pids = if ($nu_pids | is-empty) { [] } else { $nu_pids }ps| where pid not-in $filter_pids| where cpu != null and mem != null and name != null| sort-by cpu| reverse| select pid cpu mem name| each { |p|try {$"($p.name) (CPU: ($p.cpu | math round -p 1)%, MEM: ($p.mem | math round -p 1)%) [PID: ($p.pid)]"} catch {$"($p.name) [PID: ($p.pid)]"}}| where ($it | str length) > 0}def extract_pid [choice: string] {$choice | parse "{name} [PID: {pid}]" | get pid.0? | into int}
inherit (lib) readFile;inherit (lib.lists) singleton;
def fuzzel_select [items: list<string>, prompt: string] {$items | str join "\n" | ${pkgs.fuzzel}/bin/fuzzel --dmenu --prompt $prompt}def notify [title: string, message: string] {^${pkgs.libnotify}/bin/notify-send $title $message}def kill_process [pid: int] {try {kill $pidtrue} catch {false}}def main [] {let processes = get_processesif ($processes | is-empty) {notify "Error" "No processes found"return}let choice = fuzzel_select $processes "Kill process: "if ($choice | is-empty) {return}let pid = extract_pid $choiceif ($pid | is-empty) {notify "Error" "Could not extract PID"return}let process_name = get_process_name $pidif ($process_name | is-empty) {notify "Error" "Process not found"return}let confirm = fuzzel_select ["Yes" "No"] ($"Kill ($process_name) \(PID: ($pid | into string)\)? ")if $confirm == "Yes" {if (kill_process $pid) {notify "Process Killed" ($"Killed ($process_name) \(PID: ($pid | into string)\)")} else {notify "Failed" ($"Could not kill ($process_name) \(PID: ($pid | into string)\)")}}}'';
processMonitor = pkgs.writeScriptBin "process-monitor" /* nu */ ''#!${pkgs.nushell}/bin/nulet niri_bin = (try { (which niri | get 0.path) } catch { null })let class_name = "btop-popup"let compositor = if $niri_bin != null {"niri"} else {"unknown"}
processMonitor =pkgs.writeScriptBin "process-monitor" # nu''#!${pkgs.nushell}/bin/nuconst CLASS_NAME = "btop-popup"
let windows = if $compositor == "niri" {try { ^$niri_bin msg --json windows | from json } catch { [] }} else {[]}
let existing = try {niri msg --json windows| from json| where app_id? == $CLASS_NAME} catch { return }
if ($existing | is-empty) {^${pkgs.kitty}/bin/kitty --detach --class $class_name --title "Process Monitor" --override remember_window_size=no --override initial_window_width=44c --override initial_window_height=16c --override window_padding_width=${toString config.theme.padding.small} ${pkgs.btop}/bin/btop --config ${processMonitorConfig}} else if $compositor == "niri" and $niri_bin != null {let id = ($existing | first | get id?)if $id != null { ^$niri_bin msg action close-window --id $id }}'';
if ($existing | is-not-empty) {niri msg action close-window --id $existing} else {(kitty--detach--class $CLASS_NAME--title "Process Monitor"--override remember_window_size=no--override initial_window_width=44c--override initial_window_height=16c--override window_padding_width=${toString config.theme.padding.small}btop--config ${processMonitorConfig})}'';
#!/usr/bin/env nuconst THEME_CONFIG = "/home/jam/nixos/modules/theme.json"const THEME_PYWAL = "/home/jam/nixos/modules/theme-pywal-colors.json"const PYWAL_CONFIG = "/home/jam/.cache/wal/colors.json"const REBUILD_SCRIPT = "/home/jam/nixos/rebuild.nu"const HIGH_SAT = 0.75const MID_SAT = 0.5def print-notify [message: string]: nothing -> nothing {print $"(ansi purple)[Theme Switcher](ansi rst) ($message)"try { notify-send "Theme Switcher" $message }}def get-current-wallpaper []: nothing -> string {let wallpaper = swww query| lines| first| parse "{monitor}: image: {path}"| get --optional path.0if ($wallpaper | path exists) {$wallpaper} else {""}}def save-theme-config [mode: string, scheme: string] {{mode: $mode scheme: $scheme}| to json| save --force $THEME_CONFIG}def load-theme-config []: nothing -> nothing {try {open $THEME_CONFIG} catch {print-notify "Failed to load default config, falling back to light/gruvbox"{mode: light, scheme: gruvbox}}}def generate-pywal-colors [wallpaper: stringis_dark: bool]: nothing -> nothing {rm --recursive --force ($PYWAL_CONFIG | path dirname)let mode_args = if $is_dark {[ "--saturate" $MID_SAT ]} else {[ "--saturate" $HIGH_SAT "-l" ]}let args = [ "-n" "--backend" wal "-i" $wallpaper ] | append mode_argswal ...$args | ignorecp $PYWAL_CONFIG $THEME_PYWAL}def toggle-theme [theme: string] {let theme_config = load-theme-configprint-notify $"Switching to ($theme) theme."if $theme_config.scheme == pywal {print-notify "Regenerating pywal colors..."let wallpaper = get-current-wallpaperif ($wallpaper | is-not-empty) {generate-pywal-colors $wallpaper ($theme == dark)} else {print-notify "Warning: Could not detect current wallpaper"}}print-notify "Updating theme configuration..."$env.THEME_MODE = $themesave-theme-config $theme $theme_config.schemeprint-notify $"Rebuilding configuration to apply ($theme) theme."do { $REBUILD_SCRIPT }print-notify $"Switch to the ($theme) theme completed!"}def switch-scheme [scheme: string] {print-notify $"Switching to ($scheme) color scheme."let theme_config = load-theme-configif $scheme == pywal {print-notify "Generating pywal colors from current wallpaper..."let wallpaper = get-current-wallpaperif ($wallpaper | is-not-empty) {generate-pywal-colors $wallpaper ($theme_config.mode == dark)} else {print-notify "Warning: Could not detect current wallpaper"}}$env.THEME_SCHEME = $schemesave-theme-config $theme_config.mode $schemeprint-notify $"Rebuilding configuration to apply ($scheme) scheme..."do { $REBUILD_SCRIPT }print-notify $"Switch to ($scheme) scheme completed!"}def reload-applications []: nothing -> nothing {print-notify "Reloading applications..."niri msg action do-screen-transition --delay-ms 0 | ignorepkill -USR1 kitty | ignorepkill -USR2 ghostty | ignorepkill -USR1 hx | ignoresystemctl --user restart mako | ignoremakoctl reload | ignorepkill -SIGTERM brave | ignoresleep 1secniri msg action do-screen-transition --delay-ms 500 | ignoreniri msg action spawn -- brave | ignore}def main [arg: string, # Theme-related action.]: nothing -> nothing {match $arg {"dark" | "light" => {toggle-theme $argreload-applications}"pywal" | "gruvbox" => {switch-scheme $argreload-applications}"reload" => {do { $REBUILD_SCRIPT }reload-applications}_ => {print $"Invalid option: '($arg)'. Use: dark, light, pywal, gruvbox or reload."}}}
#!/usr/bin/env nudef launcher-select [prompt: string]: list<string> -> string {str join "\n"| tofi --prompt-text $prompt}def notify []: string -> nothing {try { notify-send "Process Killer" $in }if $in =~ Error { exit 1 } # nu-lint-ignore: exit_only_in_main}let all_procs = pslet procs = $all_procs| where name != null| reverse| select pid name| each {|p| $"($p.name) [PID: ($p.pid)]" }if ($procs | is-empty) { "Error: No processes found" | notify }let pid = $procs| launcher-select "[pkill]"| parse "{name} [PID: {pid}]"| get --optional pid.0| into intif ($pid | is-empty) { "Error: Could not extract PID" | notify }let process_name = $all_procs| where pid == $pid| get --optional name.0if ($process_name | is-empty) { "Error: Process not found" | notify }let confirm = [Yes No] | launcher-select $"Kill ($process_name) \(PID: ($pid)\)? "if $confirm == Yes {try {kill $pid$"Killed ($process_name) \(PID: ($pid)\)" | notify} catch {$"Could not kill ($process_name) \(PID: ($pid)\)" | notify}}
#!/usr/bin/env nulet wallpaper_dir = $"($env.HOME)/wallpapers"try { mkdir $wallpaper_dir }let wallpapers = (try {ls $wallpaper_dir| where type == file| where name =~ '\.(jpg|png|jpeg|webp|gif)$'} catch {print --stderr "Failed to list wallpapers"exit 1})if ($wallpapers | is-empty) {print --stderr $"No wallpapers found in ($wallpaper_dir)"exit 1}let selected = $wallpapers| get name| str join "\n"| (fzf--preview"chafa --size 40x20 {}"--preview-window=right:50%--prompt="Select wallpaper: ")if ($selected | is-not-empty) {swww img $selected | ignore # nu-lint-ignore: redundant_ignoreprint $"Wallpaper set: \(($selected | path basename)\)"let theme_config = try {open $"($env.HOME)/nixos/modules/theme.json"} catch {{mode: light, scheme: gruvbox}}if $theme_config.scheme == pywal {print "Regenerating pywal colors..."try {rm --recursive --force ~/.cache/wallet base_args = ["-n" "--backend" wal "-i" $selected]let mode_args = if $theme_config.mode == dark {["--saturate" "0.5"]} else {["--saturate" "0.75" "-l"]}wal ...($base_args | append $mode_args) | ignore # nu-lint-ignore: redundant_ignorecp ~/.cache/wal/colors.json $"($env.HOME)/nixos/modules/theme-pywal-colors.json"print "Colors regenerated!"try { /home/jam/nixos/rebuild.nu } catch { exit 1 }print "Rebuilt system to apply colors."} catch {|e| print $"Warning: Failed to regenerate colors: ($e.msg)" }}}