From ebe5b4d8df1888d5c6296fb04a21d7ea72b43928 Mon Sep 17 00:00:00 2001 From: pagedmov Date: Sun, 24 Nov 2024 14:25:17 -0500 Subject: [PATCH] kitty now changes color scheme inside of nix-shell --- flake.lock | 26 +++--- modules/home/environment/starship.nix | 7 +- modules/home/environment/userpkgs.nix | 1 + modules/home/environment/zsh/extraconfig.nix | 11 ++- modules/home/files.nix | 81 ++++++++++++++----- .../home/programs/nixvim/plugins/default.nix | 1 + .../home/programs/nixvim/plugins/plugins.nix | 1 - .../programs/nixvim/plugins/rustaceanvim.nix | 10 +++ overlay/scripts/nix/nsp.nix | 5 +- 9 files changed, 103 insertions(+), 40 deletions(-) create mode 100644 modules/home/programs/nixvim/plugins/rustaceanvim.nix diff --git a/flake.lock b/flake.lock index 317b593..38d328c 100755 --- a/flake.lock +++ b/flake.lock @@ -125,11 +125,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1732030699, - "narHash": "sha256-SBosboLvLqDv+7mNgRTIYDQbHE61rDDkXTJWiRX3PPo=", + "lastModified": 1732109232, + "narHash": "sha256-iYh6h8yueU8IyOfNclbiBG2+fBFcjjUfXm90ZBzk0c0=", "owner": "nix-community", "repo": "disko", - "rev": "da52cf40206d7d1a419d07640eb47b2fb9ac2c21", + "rev": "a0c384e0a3b8bcaed30a6bcf3783f8a7c8b35be4", "type": "github" }, "original": { @@ -490,11 +490,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1731978971, - "narHash": "sha256-P9DXCxDvjFt4aMc2x67hvSpNvSqX18X840w6cEVZXoo=", + "lastModified": 1732100541, + "narHash": "sha256-vFeNbKUstvSZbe9TD4bDYozZd+A/bKD+fxCye+p/Mp8=", "ref": "refs/heads/main", - "rev": "67cee430061626ccd73dc6d30eed9db289053608", - "revCount": 5480, + "rev": "940f7aa990dbc99815bab8d355999d8277534b17", + "revCount": 5484, "submodules": true, "type": "git", "url": "https://github.com/hyprwm/Hyprland" @@ -886,11 +886,11 @@ }, "nur": { "locked": { - "lastModified": 1732045661, - "narHash": "sha256-SJW1HVIbav/8NlEFMqfiqrhaKcpbMqMFCTZ0cOikXgA=", + "lastModified": 1732117323, + "narHash": "sha256-QtvUTcCAfocg18O2V4VcnKn42tRooSuVC2S4s1rD8ek=", "owner": "nix-community", "repo": "NUR", - "rev": "8ee137273e4a24ac661b43a195848beac5b3bd04", + "rev": "aa6fc91ec7d36fbd6c44f63e16cfbc89a993a3b8", "type": "github" }, "original": { @@ -969,11 +969,11 @@ ] }, "locked": { - "lastModified": 1731989835, - "narHash": "sha256-Y1S+x2jWLQB9hn4aG04/213ZlTp+30itKe9KcSsrFgw=", + "lastModified": 1732076204, + "narHash": "sha256-FnPuD4CnVos1vlHcLceBvv4hHkv2zHive7OzC4xy6ys=", "owner": "gerg-l", "repo": "spicetify-nix", - "rev": "aac6c81489f61034916efa4ed62840dc1d72c413", + "rev": "62ac6a2953a8bdfe7a0f7451f8a76ca1d73a6c9f", "type": "github" }, "original": { diff --git a/modules/home/environment/starship.nix b/modules/home/environment/starship.nix index 63fbfe0..82e3b6f 100755 --- a/modules/home/environment/starship.nix +++ b/modules/home/environment/starship.nix @@ -12,7 +12,7 @@ right_format = "($custom)"; format = lib.concatStrings [ - "($ssh_symbol)($username)($hostname)(bold white)($cmd_duration)($character)" + "($ssh_symbol)($username)($hostname)($nix_shell)(bold white)($cmd_duration)($character)" "($git_branch)($git_status)($rust)($nix-shell)" "($directory)" "$line_break[ > ](bold #89b4fa)" @@ -59,6 +59,11 @@ format = "[@](bold blue)[$hostname](bold red)"; }; + nix_shell = { + format = " via [$symbol]($style)"; + symbol = " "; + }; + custom.shellver = { command = "zsh --version"; when = ''test $SHELL = "/run/current-system/sw/bin/zsh"''; diff --git a/modules/home/environment/userpkgs.nix b/modules/home/environment/userpkgs.nix index 567c396..d82aa20 100755 --- a/modules/home/environment/userpkgs.nix +++ b/modules/home/environment/userpkgs.nix @@ -48,6 +48,7 @@ in { gtrash ripgrep toilet + vkbasalt ] ++ scripts; }; } diff --git a/modules/home/environment/zsh/extraconfig.nix b/modules/home/environment/zsh/extraconfig.nix index ef534d5..a33499d 100644 --- a/modules/home/environment/zsh/extraconfig.nix +++ b/modules/home/environment/zsh/extraconfig.nix @@ -20,6 +20,11 @@ in export RESULT echo "\$RESULT = $RESULT" } + nix-shell() { + # set an environment variable to track if you're in a nix shell or not + trap 'NIX_SHELL=false kitty_theme' EXIT + NIX_SHELL=true command nix-shell "$@" --run zsh + } nvim() { ${shellsound} ${sndpath}/nvim.wav command nvim "$@" @@ -29,9 +34,11 @@ in command ssh "$@" kitty_ssh_theme } - kitty_ssh_theme() { + kitty_theme() { if [ -n "$SSH_CONNECTION" ]; then kitty @ set-colors -a ~/.config/kitty/ssh-theme.conf + elif [ "$name" = "nix-shell-env" ] || [ "$NIX_SHELL" = "true" ]; then + kitty @ set-colors -a ~/.config/kitty/nix-shell-theme.conf else kitty @ set-colors -a ~/.config/kitty/default-theme.conf fi @@ -154,7 +161,7 @@ in autoload -U down-line-or-beginning-search; zle -N down-line-or-beginning-search bindkey -v - kitty_ssh_theme + kitty_theme type starship_zle-keymap-select >/dev/null || \ { eval "$(starship init zsh)" diff --git a/modules/home/files.nix b/modules/home/files.nix index 3c7bf73..5affb30 100755 --- a/modules/home/files.nix +++ b/modules/home/files.nix @@ -3,28 +3,34 @@ # This folder is for programs that do not have existing configuration modules in NixOS. # Basically a to-do list for stuff I need to write my own modules for. let - # Custom theme that activates in ssh - ssh_base16 = "atelier-cave"; + # Extract color scheme from base_16 yaml file + extractSchemeFromYaml = base16_scheme: let + scheme_path = "${pkgs.base16-schemes}/share/themes/${base16_scheme}.yaml"; + scheme_string = builtins.readFile scheme_path; + scheme_list = lib.splitString "\n" scheme_string; + colors = + lib.filter (line: builtins.match "^ *base[0-9A-F]{2}: .*" line != null) + scheme_list; + parsed_scheme = lib.lists.foldl' (acc: line: + let + splitLine = lib.splitString ": " line; + key = builtins.elemAt splitLine 0; + value = builtins.elemAt splitLine 1; + trimmedKey = lib.trim key; + cleanValue_step1 = lib.splitString " " value; + cleanValue_step2 = builtins.elemAt cleanValue_step1 0; + cleanValue_final = + builtins.substring 1 (builtins.stringLength cleanValue_step2 - 2) + cleanValue_step2; + in acc // { "${trimmedKey}" = cleanValue_final; }) { } colors; + in parsed_scheme; + + ssh_scheme = extractSchemeFromYaml "atelier-cave" ; + nix-shell_scheme = extractSchemeFromYaml "apathy"; def_scheme = config.lib.stylix.colors; - scheme_path = "${pkgs.base16-schemes}/share/themes/${ssh_base16}.yaml"; - scheme_string = builtins.readFile scheme_path; - scheme_list = lib.splitString "\n" "${scheme_string}"; - colors = - lib.filter (line: builtins.match "^ *base[0-9A-F]{2}: .*" line != null) - scheme_list; - ssh_scheme = lib.lists.foldl' (acc: line: - let - splitLine = lib.splitString ": " line; - key = builtins.elemAt splitLine 0; - value = builtins.elemAt splitLine 1; - trimmedKey = lib.trim key; - cleanValue_step1 = lib.splitString " " value; - cleanValue_step2 = builtins.elemAt cleanValue_step1 0; - cleanValue_final = - builtins.substring 1 (builtins.stringLength cleanValue_step2 - 2) - cleanValue_step2; - in acc // { "${trimmedKey}" = cleanValue_final; }) { } colors; + + # Custom theme for nix-shell in { options = { movOpts.homeFiles.enable = @@ -210,6 +216,41 @@ in { color14 #${ssh_scheme.base0F} color15 #${ssh_scheme.base07} ''; + ".config/kitty/nix-shell-theme.conf".text = '' + background #${nix-shell_scheme.base00} + foreground #${nix-shell_scheme.base05} + selection_background #${nix-shell_scheme.base05} + selection_foreground #${nix-shell_scheme.base00} + url_color #${nix-shell_scheme.base04} + cursor #${nix-shell_scheme.base05} + active_border_color #${nix-shell_scheme.base03} + inactive_border_color #${nix-shell_scheme.base01} + active_tab_background #${nix-shell_scheme.base00} + active_tab_foreground #${nix-shell_scheme.base05} + inactive_tab_background #${nix-shell_scheme.base01} + inactive_tab_foreground #${nix-shell_scheme.base04} + tab_bar_background #${nix-shell_scheme.base01} + + # normal + color0 #${nix-shell_scheme.base01} + color1 #${nix-shell_scheme.base08} + color2 #${nix-shell_scheme.base0B} + color3 #${nix-shell_scheme.base0A} + color4 #${nix-shell_scheme.base0D} + color5 #${nix-shell_scheme.base0E} + color6 #${nix-shell_scheme.base0C} + color7 #${nix-shell_scheme.base05} + + # bright + color8 #${nix-shell_scheme.base03} + color9 #${nix-shell_scheme.base09} + color10 #${nix-shell_scheme.base01} + color11 #${nix-shell_scheme.base02} + color12 #${nix-shell_scheme.base04} + color13 #${nix-shell_scheme.base06} + color14 #${nix-shell_scheme.base0F} + color15 #${nix-shell_scheme.base07} + ''; }; }; } diff --git a/modules/home/programs/nixvim/plugins/default.nix b/modules/home/programs/nixvim/plugins/default.nix index 2d2335e..8a7c7b1 100755 --- a/modules/home/programs/nixvim/plugins/default.nix +++ b/modules/home/programs/nixvim/plugins/default.nix @@ -9,6 +9,7 @@ ./barbar.nix ./cmp.nix ./lsp.nix + ./rustaceanvim.nix ./fidget.nix ./lualine.nix ./nvim-lightbulb.nix diff --git a/modules/home/programs/nixvim/plugins/plugins.nix b/modules/home/programs/nixvim/plugins/plugins.nix index 86bf70c..77d4bab 100755 --- a/modules/home/programs/nixvim/plugins/plugins.nix +++ b/modules/home/programs/nixvim/plugins/plugins.nix @@ -20,7 +20,6 @@ nvim-surround.enable = true; rainbow-delimiters.enable = true; render-markdown.enable = true; - rustaceanvim.enable = true; treesitter.enable = true; trim.enable = true; trouble.enable = true; diff --git a/modules/home/programs/nixvim/plugins/rustaceanvim.nix b/modules/home/programs/nixvim/plugins/rustaceanvim.nix new file mode 100644 index 0000000..f0f730a --- /dev/null +++ b/modules/home/programs/nixvim/plugins/rustaceanvim.nix @@ -0,0 +1,10 @@ +{ ... }: + +{ + programs.nixvim.plugins.rustaceanvim = { + enable = true; + settings = { + server.auto_attach = true; + }; + }; +} diff --git a/overlay/scripts/nix/nsp.nix b/overlay/scripts/nix/nsp.nix index 9affeb2..3483da0 100755 --- a/overlay/scripts/nix/nsp.nix +++ b/overlay/scripts/nix/nsp.nix @@ -2,8 +2,7 @@ pkgs.writeShellApplication { name = "nsp"; text = '' - #!/run/current-system/sw/bin/bash - - nix-shell -p "$@" --run zsh + trap 'NIX_SHELL=false kitty_theme' exit + NIX_SHELL=true command nix-shell -p "$@" --run zsh ''; }