From ab869e5704e20f5a7092a51f2ccdea78397fd1e4 Mon Sep 17 00:00:00 2001 From: Valentin Uveges Date: Thu, 10 Aug 2023 08:50:15 +0300 Subject: [PATCH 1/4] feat(custom): add logic to load modules form custom, status and window so that the user cand define it's own modules or override any existing one --- README.md | 10 +++++----- catppuccin.tmux | 36 ++++++++++++++++++++++++++++++------ custom/README.md | 31 +++++++++++++++++++++++++++++++ custom/example.sh | 10 ++++++++++ 4 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 custom/README.md create mode 100644 custom/example.sh diff --git a/README.md b/README.md index ee16b03..93142c8 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ Values: #### Set the module list ```sh -set -g @catppuccin_status_modules" "application session" +set -g @catppuccin_status_modules "application session" ``` Provide a list of modules and the order in which you want them to appear in the status. @@ -229,17 +229,17 @@ Every module (except the module "session") supports the following overrides: #### Override the specific module icon ```sh -set -g @catppuccin_[module_name]_icon" "icon" +set -g @catppuccin_[module_name]_icon "icon" ``` #### Override the specific module color ```sh -set -g @catppuccin_[module_name]_color" "color" +set -g @catppuccin_[module_name]_color "color" ``` #### Override the specific module text ```sh -set -g @catppuccin_[module_name]_text" "text" +set -g @catppuccin_[module_name]_text "text" ``` ### Battery module @@ -260,7 +260,7 @@ set -g @plugin 'tmux-plugins/tmux-battery' Add the battery module to the status modules list. ```sh -set -g @catppuccin_status_modules" "... battery ..." +set -g @catppuccin_status_modules "... battery ..." ``` diff --git a/catppuccin.tmux b/catppuccin.tmux index 4384473..4aa161d 100755 --- a/catppuccin.tmux +++ b/catppuccin.tmux @@ -161,8 +161,11 @@ build_status_module() { load_modules() { local loaded_modules - local modules_path=$1 - local modules_list=$2 + local modules_list=$1 + + local modules_custom_path=$PLUGIN_DIR/custom + local modules_status_path=$PLUGIN_DIR/status + local modules_window_path=$PLUGIN_DIR/window local modules_array read -a modules_array <<< "$modules_list" @@ -171,13 +174,34 @@ load_modules() { local module_name for module_name in ${modules_array[@]} do - local module_path=$modules_path/$module_name.sh + local module_path=$modules_custom_path/$module_name.sh source $module_path if [[ 0 -eq $? ]] then loaded_modules="$loaded_modules$( show_$module_name $module_index )" module_index=$module_index+1 + continue + fi + + local module_path=$modules_status_path/$module_name.sh + source $module_path + + if [[ 0 -eq $? ]] + then + loaded_modules="$loaded_modules$( show_$module_name $module_index )" + module_index=$module_index+1 + continue + fi + + local module_path=$modules_window_path/$module_name.sh + source $module_path + + if [[ 0 -eq $? ]] + then + loaded_modules="$loaded_modules$( show_$module_name $module_index )" + module_index=$module_index+1 + continue fi done @@ -225,8 +249,8 @@ main() { local window_number_position="$(get_tmux_option "@catppuccin_window_number_position" "left")" # right, left local window_status_enable="$(get_tmux_option "@catppuccin_window_status_enable" "no")" # right, left - local window_format=$( load_modules "$PLUGIN_DIR/window" "window_default_format") - local window_current_format=$( load_modules "$PLUGIN_DIR/window" "window_current_format") + local window_format=$( load_modules "window_default_format") + local window_current_format=$( load_modules "window_current_format") setw window-status-format "${window_format}" setw window-status-current-format "${window_current_format}" @@ -238,7 +262,7 @@ main() { local status_fill="$(get_tmux_option "@catppuccin_status_fill" "icon")" local status_modules="$(get_tmux_option "@catppuccin_status_modules" "application session")" - local loaded_modules=$( load_modules "$PLUGIN_DIR/status" "$status_modules") + local loaded_modules=$( load_modules "$status_modules") set status-left "" set status-right "${loaded_modules}" diff --git a/custom/README.md b/custom/README.md new file mode 100644 index 0000000..b3102e0 --- /dev/null +++ b/custom/README.md @@ -0,0 +1,31 @@ +# User defined modules + +## Description + +This folder is used to store user defined modules. +You can use this folder to add a new module or override any existing module. +To override an existing module, make sure you use the same name for your module as the module you want to override. +You can also override the window module for current and default window. + +## Create a new module + +Use the [Module template](#module-template) (or example.sh) as a starting point when creating a new module. +Save the new module under this folder using the module name as the file name and .sh as the extension. +Update the status module list with your module. +```sh +set -g @catppuccin_status_modules "... ..." + +``` + +## Module template + +show_() { # save this module in a file with the name .sh + local index=$1 # this variable is used by the module loader in order to know the position of this module + local icon="$(get_tmux_option "@catppuccin__icon" "")" + local color="$(get_tmux_option "@catppuccin__color" "")" + local text="$(get_tmux_option "@catppuccin__text" "")" + + local module=$( build_status_module "$index" "$icon" "$color" "$text" ) + + echo $module +} diff --git a/custom/example.sh b/custom/example.sh new file mode 100644 index 0000000..89f3e66 --- /dev/null +++ b/custom/example.sh @@ -0,0 +1,10 @@ +show_example() { + local index=$1 + local icon="$(get_tmux_option "@catppuccin_test_icon" "󰙨")" + local color="$(get_tmux_option "@catppuccin_test_color" "$thm_blue")" + local text="$(get_tmux_option "@catppuccin_test_text" "It works!")" + + local module=$( build_status_module "$index" "$icon" "$color" "$text" ) + + echo $module +} From c3e62e21df93d84bbec6a7c5f0f44ba7238c4333 Mon Sep 17 00:00:00 2001 From: Valentin Uveges Date: Thu, 10 Aug 2023 09:03:29 +0300 Subject: [PATCH 2/4] feat(custom): add custom folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e69de29..c19207e 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +custom/ From 9d603b1650d1fa9178a95f2f70dee56441a84795 Mon Sep 17 00:00:00 2001 From: Valentin Uveges Date: Thu, 10 Aug 2023 09:07:20 +0300 Subject: [PATCH 3/4] feat(custom): update git ignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c19207e..0d82d79 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -custom/ +custom From c0a46a26f4f446153d364d6621fb5c762357a209 Mon Sep 17 00:00:00 2001 From: Valentin Uveges Date: Thu, 10 Aug 2023 09:16:06 +0300 Subject: [PATCH 4/4] feat(custom): update docs --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93142c8..7e0ddda 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ 3. [Status](#status) 4. [Customizing modules](#customizing-modules) 5. [Battery module](#battery-module) -5. [Configuration Examples](#configuration-examples) +5. [Custom module](#custom-module) +6. [Configuration Examples](#configuration-examples) 1. [Config 1](#config-1) 2. [Config 2](#config-2) 3. [Config 3](#config-3) @@ -263,6 +264,13 @@ Add the battery module to the status modules list. set -g @catppuccin_status_modules "... battery ..." ``` +## Custom module + +It is possible to add a new custom module or overrite any of the existing modules. + +Look into custom/README.md for more details. + +Any file added to the custom folder will be preserved when updating catppuccin. ## Configuration Examples