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

Feat/tmux native/status modules #315

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion catppuccin_tmux.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
source -F "#{d:current_file}/themes/catppuccin_#{@catppuccin_flavor}_tmux.conf"
source -F "#{d:current_file}/status/*.conf"

source -F "#{d:current_file}/status/application.conf"
source -F "#{d:current_file}/status/battery.conf"
source -F "#{d:current_file}/status/clima.conf"
source -F "#{d:current_file}/status/cpu.conf"
source -F "#{d:current_file}/status/load.conf"
kjnsn marked this conversation as resolved.
Show resolved Hide resolved

set status-left-length "100"
set status-right-length "100"
Expand Down
3 changes: 3 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ set -Eeuo pipefail
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)

"${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/default_options.sh --expected "${script_dir}"/tests/default_options_expected.txt "$@"

"${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 /dev/null "$@"
"${script_dir}"/tests/harness.sh --test "${script_dir}"/tests/cpu_module.sh --expected /dev/null "$@"
28 changes: 5 additions & 23 deletions status/application.conf
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
# vim:set ft=tmux:
set -ogq @catppuccin_application_icon ""
set -ogqF @catppuccin_application_color "#{E:@thm_pink}"
%hidden MODULE_NAME="application"

# Add the left separator. Background is none (switched off).
set -gF @catppuccin_status_application \
"#[fg=#{@catppuccin_application_color},bg=default,nobold,nounderscore,noitalics] #{@catppuccin_status_left_separator}"

# Add the icon. Background is the color, and foreground is crust.
set -agF @catppuccin_status_application \
"#[fg=#{@thm_crust},bg=#{@catppuccin_application_color}]#{@catppuccin_application_icon} "

%if "#{==:#{@catppuccin_status_fill},icon}"
# Switch the background to surface1 and the text to foreground.
set -agF @catppuccin_status_application \
"#[fg=#{@thm_fg},bg=#{@thm_surface_1},nobold] "
%endif

set -ag @catppuccin_status_application "#{pane_current_command}"

%if "#{==:#{@catppuccin_status_fill},icon}"
set -agF @catppuccin_status_application "#[fg=#{@thm_surface_1},bg=default]#{@catppuccin_status_right_separator}"
%else
set -agF @catppuccin_status_application "#[fg=#{@catppuccin_application_color},bg=default]#{@catppuccin_status_right_separator}"
%endif
set -ogq "@catppuccin_${MODULE_NAME}_icon" ""
set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_pink}"
set -ogq "@catppuccin_${MODULE_NAME}_text" "#{pane_current_command}"

source -F "#{d:current_file}/../utils/status_module.conf"
22 changes: 22 additions & 0 deletions status/battery.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vim:set ft=tmux:
%hidden MODULE_NAME="battery"

set -ogq @batt_icon_charge_tier8 "󰁹"
set -ogq @batt_icon_charge_tier7 "󰂁"
set -ogq @batt_icon_charge_tier6 "󰁿"
set -ogq @batt_icon_charge_tier5 "󰁾"
set -ogq @batt_icon_charge_tier4 "󰁽"
set -ogq @batt_icon_charge_tier3 "󰁼"
set -ogq @batt_icon_charge_tier2 "󰁻"
set -ogq @batt_icon_charge_tier1 "󰁺"
set -ogq @batt_icon_status_charged "󰚥"
set -ogq @batt_icon_status_charging "󰂄"
set -ogq @batt_icon_status_discharging "󰂃"
set -ogq @batt_icon_status_unknown "󰂑"
set -ogq @batt_icon_status_attached "󱈑"

set -ogq "@catppuccin_${MODULE_NAME}_icon" "#{battery_icon}"
set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_yellow}"
set -ogq "@catppuccin_${MODULE_NAME}_text" "#{battery_percentage}"

source -F "#{d:current_file}/../utils/status_module.conf"
30 changes: 0 additions & 30 deletions status/battery.sh

This file was deleted.

9 changes: 9 additions & 0 deletions status/clima.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# vim:set ft=tmux:
# Requires https://github.com/vascomfnunes/tmux-clima
%hidden MODULE_NAME="clima"

set -ogq "@catppuccin_${MODULE_NAME}_icon" ""
set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_yellow}"
set -ogq "@catppuccin_${MODULE_NAME}_text" "#{clima}"

source -F "#{d:current_file}/../utils/status_module.conf"
16 changes: 0 additions & 16 deletions status/clima.sh

This file was deleted.

8 changes: 8 additions & 0 deletions status/cpu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# vim:set ft=tmux:
%hidden MODULE_NAME="cpu"

set -ogq "@catppuccin_${MODULE_NAME}_icon" ""
set -ogq "@catppuccin_${MODULE_NAME}_color" "#{cpu_bg_color}"
set -ogq "@catppuccin_${MODULE_NAME}_text" "#{cpu_percentage}"

source -F "#{d:current_file}/../utils/status_module.conf"
20 changes: 0 additions & 20 deletions status/cpu.sh

This file was deleted.

28 changes: 5 additions & 23 deletions status/load.conf
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
# vim:set ft=tmux:
%hidden MODULE_NAME="load"

set -ogq @catppuccin_load_icon "󰊚"
set -ogqF @catppuccin_load_color "#{E:@thm_blue}"
set -ogq "@catppuccin_${MODULE_NAME}_icon" "󰊚"
set -ogqF "@catppuccin_${MODULE_NAME}_color" "#{E:@thm_blue}"
set -ogq "@catppuccin_${MODULE_NAME}_text" "#{load_full}"

# Add the left separator. Background is none (switched off).
set -gF @catppuccin_status_load \
"#[fg=#{@catppuccin_load_color},bg=default,nobold,nounderscore,noitalics] #{@catppuccin_status_left_separator}"

# Add the icon. Background is the color, and foreground is crust.
set -agF @catppuccin_status_load \
"#[fg=#{@thm_crust},bg=#{@catppuccin_load_color}]#{@catppuccin_load_icon} "

%if "#{==:#{@catppuccin_status_fill},icon}"
# Switch the background to surface1 and the text to foreground.
set -agF @catppuccin_status_load \
"#[fg=#{@thm_fg},bg=#{@thm_surface_1},nobold] "
%endif

set -ag @catppuccin_status_load "#{load_full}"

%if "#{==:#{@catppuccin_status_fill},icon}"
set -agF @catppuccin_status_load "#[fg=#{@thm_surface_1},bg=default]#{@catppuccin_status_right_separator}"
%else
set -agF @catppuccin_status_load "#[fg=#{@catppuccin_load_color},bg=default]#{@catppuccin_status_right_separator}"
%endif
source -F "#{d:current_file}/../utils/status_module.conf"
10 changes: 9 additions & 1 deletion tests/application_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ source "${script_dir}/helpers.sh"
tmux source "${script_dir}/../catppuccin_options_tmux.conf"
tmux source "${script_dir}/../catppuccin_tmux.conf"

print_option @catppuccin_status_application | sed -E 's/\b(bash|fish|zsh)\b/<application>/'
application_text=$(get_option @catppuccin_application_text)

print_option @catppuccin_status_application | grep -q "$application_text" ||
echo "@catppuccin_status_application expanded @catppuccin_application_text more than once"

print_option @catppuccin_status_application | grep -q "@thm_" &&
echo "@catppuccin_status_application did not expand all colors"

print_option E:@catppuccin_status_application | sed -E 's/\b(bash|fish|zsh)\b/<application>/'
2 changes: 1 addition & 1 deletion tests/application_module_expected.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@catppuccin_status_application #[fg=#f5c2e7,bg=default,nobold,nounderscore,noitalics] #[fg=#11111b,bg=#f5c2e7] #[fg=#cdd6f4,bg=#45475a,nobold] <application>#[fg=#45475a,bg=default]█
E:@catppuccin_status_application #[fg=#f5c2e7,bg=default,nobold,nounderscore,noitalics] #[fg=#11111b,bg=#f5c2e7] #[fg=#cdd6f4,bg=#45475a,nobold] <application>#[fg=#45475a,bg=default]█
12 changes: 12 additions & 0 deletions tests/battery_module.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"

# 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 @catppuccin_battery_icon | grep -q "#{battery_icon}" ||
echo "@catppuccin_status_battery expanded #{battery_icon} in @catppuccin_battery_icon"
12 changes: 12 additions & 0 deletions tests/cpu_module.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"

# 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 @catppuccin_status_cpu | grep -q "#{cpu_bg_color}" ||
echo "@catppuccin_status_cpu expanded #{cpu_bg_color} in @catppuccin_cpu_color"
6 changes: 3 additions & 3 deletions tests/default_options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source "${script_dir}/helpers.sh"
tmux source "${script_dir}/../catppuccin_options_tmux.conf"
tmux source "${script_dir}/../catppuccin_tmux.conf"

print_option @catppuccin_flavor
print_option @catppuccin_menu_selected_style
print_option @catppuccin_pane_active_border_style
print_option E:@catppuccin_flavor
print_option E:@catppuccin_menu_selected_style
print_option E:@catppuccin_pane_active_border_style
6 changes: 3 additions & 3 deletions tests/default_options_expected.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@catppuccin_flavor mocha
@catppuccin_menu_selected_style fg=#313244,bg=#f9e2af
@catppuccin_pane_active_border_style fg=#b4befe
E:@catppuccin_flavor mocha
E:@catppuccin_menu_selected_style fg=#313244,bg=#f9e2af
E:@catppuccin_pane_active_border_style fg=#b4befe
5 changes: 5 additions & 0 deletions tests/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ run_test() {
local output
# shellcheck disable=SC1090
output=$(source "${test_script}")
test_exit_code="$?"

if test $test_exit_code -ne 0; then
die "\n${RED}Test ${script_name} exited with code $test_exit_code ${NOFORMAT}"
fi

echo -e "${output}" | diff -aB --color=${DIFFCOLORS} "${expected_output}" -

Expand Down
20 changes: 17 additions & 3 deletions tests/helpers.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/usr/bin/env bash

# Returns the value of given tmux option.
# First argument is the option name, e.g. @catppuccin_flavor.
#
# Usage: `get_option @catppuccin_flavor`
# Would return: `mocha`
#
# The option is given as a format string.
get_option() {
local option
option=$1

tmux display-message -p "#{${option}}"
}

# Prints the given tmux option to stdout.
# First argument is the option name, e.g. @catppuccin_flavor.
#
# Usage: `print-option @catppuccin_flavor`
# Usage: `print_option @catppuccin_flavor`
# Would print: `@catppuccin_flavor mocha`
#
# The variable given is expanded as a format string.
# The option is given as a format string.
print_option() {
local option
option=$1

printf "\n%s " "${option}"
tmux display-message -p "#{E:${option}}"
get_option "$option"
}
24 changes: 24 additions & 0 deletions utils/status_module.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vim:set ft=tmux:

# Add the left separator. Background is none (switched off).
set -gF "@catppuccin_status_${MODULE_NAME}" \
"#[fg=#{@catppuccin_${MODULE_NAME}_color},bg=default,nobold,nounderscore,noitalics] #{@catppuccin_status_left_separator}"

# Add the icon. Background is the color, and foreground is crust.
set -agF "@catppuccin_status_${MODULE_NAME}" \
"#[fg=#{@thm_crust},bg=#{@catppuccin_${MODULE_NAME}_color}]#{@catppuccin_${MODULE_NAME}_icon} "

%if "#{==:#{@catppuccin_status_fill},icon}"
# Switch the background to surface1 and the text to foreground.
set -agF "@catppuccin_status_${MODULE_NAME}" \
"#[fg=#{@thm_fg},bg=#{@thm_surface_1},nobold] "
%endif

set -agF "@catppuccin_status_${MODULE_NAME}" "#{@catppuccin_${MODULE_NAME}_text}"

%if "#{==:#{@catppuccin_status_fill},icon}"
set -agF "@catppuccin_status_${MODULE_NAME}" "#[fg=#{@thm_surface_1},bg=default]#{@catppuccin_status_right_separator}"
%else
set -agF "@catppuccin_status_${MODULE_NAME}" "#[fg=#{@catppuccin_${MODULE_NAME}_color},bg=default]#{@catppuccin_status_right_separator}"
%endif