diff --git a/catppuccin_tmux.conf b/catppuccin_tmux.conf index a4cc5403..07a6f5c8 100644 --- a/catppuccin_tmux.conf +++ b/catppuccin_tmux.conf @@ -1,3 +1,5 @@ +set -gF @catppuccin_tmux_directory "#{d:current_file}" + source -F "#{d:current_file}/themes/catppuccin_#{@catppuccin_flavor}_tmux.conf" %if "#{==:#{@catppuccin_status_background},default}" @@ -34,6 +36,10 @@ source -F "#{d:current_file}/status/uptime.conf" source -F "#{d:current_file}/status/user.conf" source -F "#{d:current_file}/status/weather.conf" +%if "#{!=:#{@catppuccin_user_status_directory},}" +source -F "#{E:@catppuccin_user_status_directory}/*.conf" +%endif + # messages set -gF message-style "fg=#{@thm_teal},bg=$CTP_MESSAGE_BACKGROUND,align=centre" set -gF message-command-style "fg=#{@thm_teal},bg=$CTP_MESSAGE_BACKGROUND,align=centre" diff --git a/docs/tutorials/02-custom-status.md b/docs/tutorials/02-custom-status.md index 618a6d58..78321e26 100644 --- a/docs/tutorials/02-custom-status.md +++ b/docs/tutorials/02-custom-status.md @@ -24,18 +24,58 @@ set -ag status-right "#[fg=#{@thm_fg},bg=#{@thm_mantle}] #(memory_pressure | awk ![Example of the custom ram module](../../assets/ram-example.webp) -To use the status module formatting that catppuccin uses, do the following: +To use the status module formatting that catppuccin uses, create a directory that contains the custom status modules. Then point `@catppuccin_user_status_directory` at that directory: ```sh -# In ~/.tmux.conf, after the catppuccin plugin has been loaded. +# In ~/.tmux.conf, before loading the catppuccin plugin +set -gF @catppuccin_user_status_directory "~/.config/tmux/custom" + +# Apply your custom module in status-right +set -g status-right "#{E:@catpuccin_status_application}#{E:@catppuccin_status_my_custom_module}" +``` + +Then in the `~/.config/tmux/custom` directory, you can create custom status modules (which must have `.conf` file extension) like this: + +```sh +# my_custom.conf %hidden MODULE_NAME="my_custom_module" -set -ogq "@catppuccin_${MODULE_NAME}_icon" " " +set -ogq "@catppuccin_${MODULE_NAME}_icon" " " set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_pink}" -set -ogq "@catppuccin_${MODULE_NAME}_text" "#{pane_current_command}" +set -ogq "@catppuccin_${MODULE_NAME}_text" "#{pane_current_command}" -source "/utils/status_module.conf" +source -F "#{@catppuccin_tmux_directory}/utils/status_module.conf" -set -g status-right "#{E:@catpuccin_status_application}#{E:@catppuccin_status_my_custom_module}" +``` + +More than one custom status module can be defined. A practical use-case is to have both CPU and RAM usage such as: +```sh +# In ~/.tmux.conf, before loading the catppuccin plugin +set -gF @catppuccin_user_status_directory "~/.config/tmux/custom" + +# Apply your custom module in status-right +set -g status-right "#{E:@catpuccin_status_application}#{E:@catppuccin_status_cpu}#{E:@catppuccin_status_ram}" +``` + +Then create `~/.config/tmux/custom/ram.conf`: + +```sh +%hidden MODULE_NAME="ram" + +set -ogq @ram_low_fg_color "#{E:@thm_fg}" +set -ogq @ram_medium_fg_color "#{E:@thm_fg}" +set -ogq @ram_high_fg_color "#{E:@thm_crust}" + +set -ogq @ram_low_bg_color "#{E:@catppuccin_status_module_text_bg}" +set -ogq @ram_medium_bg_color "#{E:@catppuccin_status_module_text_bg}" +set -ogq @ram_high_bg_color "#{E:@thm_red}" + +set -ogq "@catppuccin_${MODULE_NAME}_icon" "#{l:#{ram_icon}} " +set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_blue}" +set -ogq "@catppuccin_status_${MODULE_NAME}_text_fg" "#{l:#{ram_fg_color}}" +set -ogq "@catppuccin_status_${MODULE_NAME}_text_bg" "#{l:#{ram_bg_color}}" +set -ogq "@catppuccin_${MODULE_NAME}_text" " #{l:#{ram_percentage}}" + +source -F "#{@catppuccin_tmux_directory}/utils/status_module.conf" ``` diff --git a/run_tests.sh b/run_tests.sh index 4f3d7ed5..3cddaf04 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -10,4 +10,5 @@ script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) "${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/application_module.sh --expected "${script_dir}"/tests/application_module_expected.txt "$@" "${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/battery_module.sh --expected "${script_dir}"/tests/battery_module_expected.txt "$@" "${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/cpu_module.sh --expected "${script_dir}"/tests/cpu_module_expected.txt "$@" +"${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/custom_status.sh --expected "${script_dir}"/tests/custom_status_expected.txt "$@" "${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/pane_styling.sh --expected "${script_dir}"/tests/pane_styling_expected.txt "$@" diff --git a/tests/custom_status.sh b/tests/custom_status.sh new file mode 100644 index 00000000..5be744af --- /dev/null +++ b/tests/custom_status.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) +# shellcheck disable=SC1091 +source "${script_dir}/helpers.sh" + +tmux set -g @catppuccin_user_status_directory "${script_dir}/userdefined" +# Tests that the default options are set correctly +tmux source "${script_dir}/../catppuccin_options_tmux.conf" +tmux source "${script_dir}/../catppuccin_tmux.conf" + +print_option E:@catppuccin_status_ram diff --git a/tests/custom_status_expected.txt b/tests/custom_status_expected.txt new file mode 100644 index 00000000..9afe2908 --- /dev/null +++ b/tests/custom_status_expected.txt @@ -0,0 +1 @@ +E:@catppuccin_status_ram #[fg=#89b4fa]#[fg=#11111b,bg=#89b4fa]#{ram_icon} #[fg=#{ram_fg_color},bg=#{ram_bg_color}] #{ram_percentage}#[reverse]█#[noreverse] diff --git a/tests/userdefined/ram.conf b/tests/userdefined/ram.conf new file mode 100644 index 00000000..aeaf9bf6 --- /dev/null +++ b/tests/userdefined/ram.conf @@ -0,0 +1,19 @@ +# vim:set ft=tmux: +%hidden MODULE_NAME="ram" + +set -ogq @ram_low_fg_color "#{E:@thm_fg}" +set -ogq @ram_medium_fg_color "#{E:@thm_fg}" +set -ogq @ram_high_fg_color "#{E:@thm_crust}" + +set -ogq @ram_low_bg_color "#{E:@catppuccin_status_module_text_bg}" +set -ogq @ram_medium_bg_color "#{E:@catppuccin_status_module_text_bg}" +set -ogq @ram_high_bg_color "#{E:@thm_red}" + +set -ogq "@catppuccin_${MODULE_NAME}_icon" "#{l:#{ram_icon}} " +set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_blue}" +set -ogq "@catppuccin_status_${MODULE_NAME}_text_fg" "#{l:#{ram_fg_color}}" +set -ogq "@catppuccin_status_${MODULE_NAME}_text_bg" "#{l:#{ram_bg_color}}" +set -ogq "@catppuccin_${MODULE_NAME}_text" " #{l:#{ram_percentage}}" + +source -F "#{@catppuccin_tmux_directory}/utils/status_module.conf" +