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 +}