From 3927ebaafa11f8b21d929e3ac7c234c45a10ec88 Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Mon, 4 Nov 2024 23:03:49 -0600 Subject: [PATCH] fix wezterm --- src/home/default.nix | 2 + src/home/email/mailcap.nix | 37 +++--- src/home/gui/wezterm.nix | 226 ++++++++++++++++++++++++++++++-- src/home/shell/tmux/default.nix | 25 +++- src/home/shell/tmux/tmux.conf | 3 +- src/home/wm/common-i3.nix | 4 + src/home/wm/i3.nix | 3 +- src/home/wm/sway.nix | 3 +- src/nixos/default.nix | 1 + src/nixos/gnupg.nix | 11 +- 10 files changed, 279 insertions(+), 36 deletions(-) diff --git a/src/home/default.nix b/src/home/default.nix index 9f4ea36..9813248 100644 --- a/src/home/default.nix +++ b/src/home/default.nix @@ -25,6 +25,8 @@ username = user; homeDirectory = "/home/${user}"; activation = { }; + + sessionVariables.EDITOR = lib.getExe pkgs.vim; }; programs.home-manager.enable = true; diff --git a/src/home/email/mailcap.nix b/src/home/email/mailcap.nix index 6657539..116eaf9 100644 --- a/src/home/email/mailcap.nix +++ b/src/home/email/mailcap.nix @@ -1,9 +1,15 @@ -{ pkgs, lib, config, ... }: +{ + pkgs, + lib, + config, + ... +}: let w3m = lib.getExe pkgs.w3m; zathura = lib.getExe config.programs.zathura.package; - kitty = lib.getExe config.programs.kitty.package; + # term = lib.getExe config.programs.kitty.package; + term = lib.getExe config.programs.wezterm.package; in { home.packages = with pkgs; [ @@ -12,22 +18,23 @@ in home.file.".mailcap" = { text = '' -# HTML -# text/html; ${w3m} -sixel -o tmp_dir=~/.cache/w3m -o auto_image=TRUE -o display_image=1 -T text/html %s; nametemplate=%s.html -text/html; ${w3m} -o inline_img_protocol=4 -o tmp_dir=~/.cache/w3m -o auto_image=TRUE -o display_image=1 -T text/html %s; nametemplate=%s.html + # HTML + text/html; ${w3m} -sixel -o tmp_dir=~/.cache/w3m -o auto_image=TRUE -o display_image=1 -T text/html %s; nametemplate=%s.html + # text/html; ${w3m} -o inline_img_protocol=4 -o tmp_dir=~/.cache/w3m -o auto_image=TRUE -o display_image=1 -T text/html %s; nametemplate=%s.html -# This second one is chosen by auto_view due to the copiousoutput tag -text/html; ${w3m} -I %{charset} -T text/html -cols 140 -o tmp_dir=~/.cache/w3m -o display_link_number=1 -dump; copiousoutput -text/plain; $EDITOR %s + # This second one is chosen by auto_view due to the copiousoutput tag + text/html; ${w3m} -I %{charset} -T text/html -cols 140 -o tmp_dir=~/.cache/w3m -o display_link_number=1 -dump; copiousoutput + text/plain; vim %s -#PDFs -application/x-pdf; ${zathura} '%s'; test=test -n "$DISPLAY" -application/pdf; ${zathura} '%s'; test=test -n "$DISPLAY" + #PDFs + application/x-pdf; ${zathura} '%s'; test=test -n "$DISPLAY" + application/pdf; ${zathura} '%s'; test=test -n "$DISPLAY" -#Images -# image/png; /usr/bin/feh %s -# image/jpeg; /usr/bin/feh %s -image/*; (clear && ${kitty} +kitten icat %s); needsterminal + #Images + # image/png; /usr/bin/feh %s + # image/jpeg; /usr/bin/feh %s + # image/*; (clear && ${term} +kitten icat %s); needsterminal + image/*; (clear && ${term} imgcat %s); needsterminal ''; }; } diff --git a/src/home/gui/wezterm.nix b/src/home/gui/wezterm.nix index f90f7c2..02b79c9 100644 --- a/src/home/gui/wezterm.nix +++ b/src/home/gui/wezterm.nix @@ -1,12 +1,220 @@ -{ pkgs, ... }: { - programs.wezterm = { - enable = true; - extraConfig = '' - return { - -- enable_wayland = false - } - ''; + pkgs, + config, + lib, + ... +}: + +let + colors = config.lib.stylix.colors.withHashtag; + tomlFormat = pkgs.formats.toml { }; + shellIntegrationStr = '' + source "${pkgs.wezterm}/etc/profile.d/wezterm.sh" + ''; +in +{ + home.packages = with pkgs; [ + wezterm + ]; + + programs.bash.initExtra = shellIntegrationStr; + programs.zsh.initExtra = shellIntegrationStr; + + xdg.configFile."wezterm/colors/stylix.toml".source = tomlFormat.generate "stylix.toml" { + colors = with colors; { + ansi = [ + base00 + base08 + base0B + base0A + base0D + base0E + base0C + base05 + ]; + brights = [ + base03 + base08 + base0B + base0A + base0D + base0E + base0C + base07 + ]; + background = base00; + cursor_bg = base05; + cursor_fg = base00; + compose_cursor = base06; + foreground = base05; + scrollbar_thumb = base01; + selection_bg = base05; + selection_fg = base00; + split = base03; + visual_bell = base09; + tab_bar = { + background = base01; + inactive_tab_edge = base01; + active_tab = { + bg_color = base00; + fg_color = base05; + }; + inactive_tab = { + bg_color = base03; + fg_color = base05; + }; + inactive_tab_hover = { + bg_color = base05; + fg_color = base00; + }; + new_tab = { + bg_color = base03; + fg_color = base05; + }; + new_tab_hover = { + bg_color = base05; + fg_color = base00; + }; + }; + }; }; - stylix.targets.wezterm.enable = true; + + xdg.configFile."wezterm/wezterm.lua".text = + with colors; + with config.stylix.fonts; + lib.mkForce '' + local wezterm = require 'wezterm' + local io = require 'io' + local os = require 'os' + local act = wezterm.action + + wezterm.add_to_config_reload_watch_list(wezterm.config_dir) + + local config = wezterm.config_builder() + + config.front_end = "WebGpu" + config.enable_wayland = true + + config.enable_kitty_keyboard = true + config.enable_csi_u_key_encoding = true + + config.window_padding = { + left = 0, + right = 0, + top = 0, + bottom = 0, + } + + config.inactive_pane_hsb = { + saturation = 0.7, + brightness = 0.5, + } + + config.exit_behavior = 'Close' + config.hide_tab_bar_if_only_one_tab = true + config.use_fancy_tab_bar = false + config.tab_bar_at_bottom = false + + wezterm.on('trigger-vim-with-scrollback', function(window, pane) + -- Retrieve the text from the pane + local text = pane:get_lines_as_text(pane:get_dimensions().scrollback_rows) + + -- Create a temporary file to pass to vim + local name = os.tmpname() + local f = io.open(name, 'w+') + f:write(text) + f:flush() + f:close() + + -- Open a new window running vim and tell it to open the file + window:perform_action( + act.SpawnCommandInNewWindow { + args = { 'nvim', name }, + }, + pane + ) + + -- Wait "enough" time for vim to read the file before we remove it. + -- The window creation and process spawn are asynchronous wrt. running + -- this script and are not awaitable, so we just pick a number. + -- + -- Note: We don't strictly need to remove this file, but it is nice + -- to avoid cluttering up the temporary directory. + wezterm.sleep_ms(1000) + os.remove(name) + end) + + config.keys = { + { + key = 'Semicolon', + mods = 'CTRL|SHIFT', + action = act.EmitEvent 'trigger-vim-with-scrollback', + }, + } + + -- Generated by Stylix + config.color_scheme = "stylix" + config.font = wezterm.font_with_fallback { + "${monospace.name}", + "${emoji.name}", + } + config.font_size = ${builtins.toString sizes.terminal} + config.window_background_opacity = ${builtins.toString config.stylix.opacity.terminal} + config.window_frame = { + active_titlebar_bg = "${base03}", + active_titlebar_fg = "${base05}", + active_titlebar_border_bottom = "${base03}", + border_left_color = "${base01}", + border_right_color = "${base01}", + border_bottom_color = "${base01}", + border_top_color = "${base01}", + button_bg = "${base01}", + button_fg = "${base05}", + button_hover_bg = "${base05}", + button_hover_fg = "${base03}", + inactive_titlebar_bg = "${base01}", + inactive_titlebar_fg = "${base05}", + inactive_titlebar_border_bottom = "${base03}", + } + config.colors = { + tab_bar = { + background = "${base01}", + inactive_tab_edge = "${base01}", + active_tab = { + bg_color = "${base00}", + fg_color = "${base05}", + }, + inactive_tab = { + bg_color = "${base03}", + fg_color = "${base05}", + }, + inactive_tab_hover = { + bg_color = "${base05}", + fg_color = "${base00}", + }, + new_tab = { + bg_color = "${base03}", + fg_color = "${base05}", + }, + new_tab_hover = { + bg_color = "${base05}", + fg_color = "${base00}", + }, + }, + } + config.command_palette_bg_color = "${base01}" + config.command_palette_fg_color = "${base05}" + config.command_palette_font_size = ${builtins.toString sizes.popups} + return config + ''; + # programs.wezterm = { + # enable = true; + # extraConfig = '' + # return { + # front_end = "WebGpu", + # enable_wayland = true, + # } + # ''; + # }; + # stylix.targets.wezterm.enable = true; } diff --git a/src/home/shell/tmux/default.nix b/src/home/shell/tmux/default.nix index 9469160..a66c6ab 100644 --- a/src/home/shell/tmux/default.nix +++ b/src/home/shell/tmux/default.nix @@ -1,13 +1,26 @@ { pkgs, ... }: -{ - home.packages = with pkgs; [ - tmux - ]; - xdg.configFile."tmux/tmux.conf" = { - source = ./tmux.conf; +let + tmux-conf = ./tmux.conf; +in +{ + # home.packages = with pkgs; [ + # tmux + # ]; + + programs.tmux = { + enable = true; + sensibleOnTop = false; + extraConfig = '' + source-file ${tmux-conf} + ''; }; + stylix.targets.tmux.enable = true; + # xdg.configFile."tmux/tmux.conf" = { + # source = ./tmux.conf; + # }; + custom.persist = { home.directories = [ ".tmux" diff --git a/src/home/shell/tmux/tmux.conf b/src/home/shell/tmux/tmux.conf index 6b0ceff..61c8b9e 100644 --- a/src/home/shell/tmux/tmux.conf +++ b/src/home/shell/tmux/tmux.conf @@ -23,6 +23,7 @@ set-option -g status-position bottom # top set-option -g default-terminal 'screen-256color' set-option -sa terminal-features ',xterm-kitty:RGB' +set-option -as terminal-features ',screen-256color:clipboard' set -ga terminal-overrides ',xterm*:Tc' # https://github.com/folke/tokyonight.nvim#making-undercurls-work-properly-in-tmux @@ -181,4 +182,4 @@ bind-key -T copy-mode-vi 'C-\' if-shell "$is_vim_emacs" "send-keys C-\\\\" "sele # Browse tmux pane in nvim # bind [ run-shell 'kitty @ kitten ~/.local/share/nvim/lazy/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --env "TMUX=$TMUX" --env "TMUX_PANE=#{pane_id}"' -bind [ run-shell 'tmux-vim-pager' +# bind [ run-shell 'tmux-vim-pager' diff --git a/src/home/wm/common-i3.nix b/src/home/wm/common-i3.nix index b16c29d..c770d0e 100644 --- a/src/home/wm/common-i3.nix +++ b/src/home/wm/common-i3.nix @@ -165,6 +165,10 @@ in "XF86AudioPause" = "exec --no-startup-id ${playerctl} play-pause"; "XF86AudioNext" = "exec --no-startup-id ${playerctl} next"; "XF86AudioPrev" = "exec --no-startup-id ${playerctl} previous"; + + "${modifier}+b" = "exec ${terminal} bash -c yazi"; + "${modifier}+m" = "exec ${terminal} bash -c neomutt"; + "${modifier}+c" = "exec ${terminal} bash -c calcure"; }; modes = diff --git a/src/home/wm/i3.nix b/src/home/wm/i3.nix index 474a193..030249f 100644 --- a/src/home/wm/i3.nix +++ b/src/home/wm/i3.nix @@ -14,7 +14,8 @@ let menu = lib.getExe' pkgs.dmenu "dmenu_run"; terminal = if config.programs.kitty.enable then - lib.getExe' config.programs.kitty.package "kitty" + # lib.getExe' config.programs.kitty.package "kitty" + lib.getExe' config.programs.wezterm.package "wezterm" else lib.getExe' pkgs.xterm "xterm"; }; diff --git a/src/home/wm/sway.nix b/src/home/wm/sway.nix index d106c1c..97b38e8 100644 --- a/src/home/wm/sway.nix +++ b/src/home/wm/sway.nix @@ -15,7 +15,8 @@ let menu = lib.getExe' config.programs.bemenu.package "bemenu-run"; terminal = if config.programs.kitty.enable then - lib.getExe' config.programs.kitty.package "kitty" + # lib.getExe' config.programs.kitty.package "kitty" + lib.getExe' config.programs.wezterm.package "wezterm" else lib.getExe' pkgs.foot "foot"; }; diff --git a/src/nixos/default.nix b/src/nixos/default.nix index c28cb31..28076c0 100644 --- a/src/nixos/default.nix +++ b/src/nixos/default.nix @@ -63,6 +63,7 @@ config = { environment = { + variables.EDITOR = lib.getExe pkgs.vim; systemPackages = with pkgs; [ diff --git a/src/nixos/gnupg.nix b/src/nixos/gnupg.nix index b345c09..f924fd5 100644 --- a/src/nixos/gnupg.nix +++ b/src/nixos/gnupg.nix @@ -1,4 +1,9 @@ -{ pkgs, config, lib, ... }: +{ + pkgs, + config, + lib, + ... +}: { programs.gnupg = { @@ -6,11 +11,11 @@ enable = true; enableSSHSupport = true; }; - }; + }; custom.persist = { home.directories = [ - ".gnupg" + ".gnupg" ]; }; }