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

Extension to support user custom status modules #416

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions catppuccin_tmux.conf
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down Expand Up @@ -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"
Expand Down
52 changes: 46 additions & 6 deletions docs/tutorials/02-custom-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<path to catppuccin plugin>/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"
```
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
12 changes: 12 additions & 0 deletions tests/custom_status.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/custom_status_expected.txt
Original file line number Diff line number Diff line change
@@ -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]
19 changes: 19 additions & 0 deletions tests/userdefined/ram.conf
Original file line number Diff line number Diff line change
@@ -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"