Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to render flavor config to raw tmux config? #146

Open
pentago opened this issue Feb 29, 2024 · 3 comments
Open

Is there a way to render flavor config to raw tmux config? #146

pentago opened this issue Feb 29, 2024 · 3 comments

Comments

@pentago
Copy link

pentago commented Feb 29, 2024

I really like the colors and everything but the plugin messes up with my existing configuration (like placing status centered at the top, with a transparent background and additional status beneath that I use as a margin to separate the prompt.

I don't really want to dig into figuring out templating to be able to construct what I'm after so if possible, I'd like a way to render mocha flavor config to tmux config, without any plugins, that I can tweak to get precisely what I like and possibly play with the colors of my own.

Hopefully, a script that does this already exists and I'd appreciate having it if possible :)

@sgoudham
Copy link
Contributor

sgoudham commented Mar 7, 2024

Hey 👋

I'm not a tmux user but just from browsing the repository, I can see that we have .tmuxtheme files which essentially hold the colour definitions:

E.g. Mocha

# NOTE: you can use vars with $<var> and ${<var>} as long as the str is double quoted: ""
# WARNING: hex colors can't contain capital letters
# --> Catppuccin (Mocha)
thm_bg="#1e1e2e"
thm_fg="#cdd6f4"
thm_cyan="#89dceb"
thm_black="#181825"
thm_gray="#313244"
thm_magenta="#cba6f7"
thm_pink="#f5c2e7"
thm_red="#f38ba8"
thm_green="#a6e3a1"
thm_yellow="#f9e2af"
thm_blue="#89b4fa"
thm_orange="#fab387"
thm_black4="#585b70"

And diving into the catppuccin.tmux file, we can see that the "chosen" flavour's properties are set in a while loop:

tmux/catppuccin.tmux

Lines 297 to 315 in 219ff43

local theme
theme="$(get_tmux_option "@catppuccin_flavour" "mocha")"
# Aggregate all commands in one array
local tmux_commands=()
# NOTE: Pulling in the selected theme by the theme that's being set as local
# variables.
# shellcheck source=catppuccin-frappe.tmuxtheme
# https://github.com/dylanaraps/pure-sh-bible#parsing-a-keyval-file
while IFS='=' read -r key val; do
# Skip over lines containing comments.
# (Lines starting with '#').
[ "${key##\#*}" ] || continue
# '$key' stores the key.
# '$val' stores the value.
eval "local $key"="$val"
done < "${PLUGIN_DIR}/catppuccin-${theme}.tmuxtheme"

And then later on in the catppuccin.tmux file, we can see that the variables can be used when wrapped with ${}:

set status-bg "${thm_bg}"

From reading the code above, I think you'd be able to:

  1. Download your chosen .tmuxtheme file(s)
  2. "Import" the colours using a while loop or equivalent in your .tmux file.
  3. Begin using the colours in your .tmux file, without any additional plugins installed.

Let me know if this works or if I've completely missed the mark 😄

@vdbe
Copy link
Collaborator

vdbe commented Mar 9, 2024

Another option it to print what the plugin does and copy the parts that you need:

diff --git a/catppuccin.tmux b/catppuccin.tmux
index be45bb5..26e7820 100755
--- a/catppuccin.tmux
+++ b/catppuccin.tmux
@@ -26,12 +26,14 @@ get_tmux_option() {
 set() {
   local option=$1
   local value=$2
+  echo set-option -gq "$option" "$value" ";" >&2
   tmux_commands+=(set-option -gq "$option" "$value" ";")
 }
 
 setw() {
   local option=$1
   local value=$2
+  echo set-window-option -gq "$option" "$value" ";" >&2
   tmux_commands+=(set-window-option -gq "$option" "$value" ";")
 }
$ bash catppuccin.tmux
set-option -gq status on ;
set-option -gq status-bg #1e1e2e ;
set-option -gq status-justify left ;
set-option -gq status-left-length 100 ;
set-option -gq status-right-length 100 ;
set-option -gq message-style fg=#89dceb,bg=#313244,align=centre ;
set-option -gq message-command-style fg=#89dceb,bg=#313244,align=centre ;
set-window-option -gq pane-border-status off ;
set-window-option -gq pane-active-border-style #{?pane_in_mode,fg=#f9e2af,#{?pane_synchronized,fg=#cba6f7,fg=#fab387}} ;
set-window-option -gq pane-border-style fg=#313244 ;
set-window-option -gq pane-border-format  ;
set-window-option -gq window-status-activity-style fg=#cdd6f4,bg=#1e1e2e,none ;
set-window-option -gq window-status-separator  ;
set-window-option -gq window-status-style fg=#cdd6f4,bg=#1e1e2e,none ;
set-window-option -gq window-status-format #[fg=#89b4fa,bg=#1e1e2e]█#[fg=#313244,bg=#89b4fa]#I#[fg=#89b4fa,bg=#313244,nobold,nounderscore,noitalics]█ #[fg=#cdd6f4,bg=#313244]#{window_name} #{?window_activity_flag,󱐋 ,}#{?window_bell_flag,󰂞 ,}#{?window_silence_flag,󰂠 ,}#{?window_active, ,}#{?window_last_flag, ,}#{?window_marked_flag,󰃀 ,}#{?window_zoomed_flag, ,}#[fg=#313244,bg=#1e1e2e,nobold,nounderscore,noitalics]█ ;
set-window-option -gq window-status-current-format #[fg=#fab387,bg=#1e1e2e]█#[fg=#1e1e2e,bg=#fab387]#I#[fg=#fab387,bg=#1e1e2e,nobold,nounderscore,noitalics]█ #[fg=#cdd6f4,bg=#1e1e2e]#{window_name} #{?window_activity_flag,󱐋 ,}#{?window_bell_flag,󰂞 ,}#{?window_silence_flag,󰂠 ,}#{?window_active, ,}#{?window_last_flag, ,}#{?window_marked_flag,󰃀 ,}#{?window_zoomed_flag, ,}#[fg=#1e1e2e,bg=#1e1e2e,nobold,nounderscore,noitalics]█ ;
set-option -gq status-left  ;
set-option -gq status-right #[fg=#f5c2e7,bg=#1e1e2e,nobold,nounderscore,noitalics]█#[fg=#1e1e2e,bg=#f5c2e7,nobold,nounderscore,noitalics] #[fg=#cdd6f4,bg=#313244] #W#[fg=#313244,bg=#313244,nobold,nounderscore,noitalics]█#[fg=#{?client_prefix,#f38ba8,#a6e3a1},bg=#313244,nobold,nounderscore,noitalics]█#[fg=#1e1e2e,bg=#{?client_prefix,#f38ba8,#a6e3a1},nobold,nounderscore,noitalics] #[fg=#cdd6f4,bg=#313244] #S#[fg=#313244,bg=#313244,nobold,nounderscore,noitalics]█ ;
set-window-option -gq clock-mode-colour #89b4fa ;
set-window-option -gq mode-style fg=#f5c2e7 bg=#585b70 bold ;

@sgoudham
Copy link
Contributor

sgoudham commented Mar 9, 2024

Re-reading this issue again and yup, I completely misunderstood it.

I actually really like this approach @vdbe, I think it totally makes sense to put it under a -v flag so that it doesn't flood the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants