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

Battery status module not working #342

Closed
1 task done
xronin01 opened this issue Oct 2, 2024 · 18 comments · Fixed by #363
Closed
1 task done

Battery status module not working #342

xronin01 opened this issue Oct 2, 2024 · 18 comments · Fixed by #363
Labels
bug Something isn't working

Comments

@xronin01
Copy link

xronin01 commented Oct 2, 2024

Is there an existing issue outlining your problem?

  • I have searched the existing issues and they do not solve my problem.

Describe your problem.

Battery status module not working

Paste your configuration.

### Terminal
set -g default-terminal "tmux-256color"
set -ag terminal-features ",${TERM}:RGB"

### Mouse Support
set -g mouse on

### Status Bar Position
set -g status-position top

### Window Indexing
set -g base-index 1
set -g renumber-windows on

### Keymaps
unbind %
unbind '"'
bind v split-window -h
bind h split-window -v
bind r source-file $HOME/.config/tmux/tmux.conf \; display-message "Settings reloaded!"
# bind-key -n C-h if -F "#{@pane-is-vim}" 'send-keys C-h' 'select-pane -L'
# bind-key -n C-j if -F "#{@pane-is-vim}" 'send-keys C-j' 'select-pane -D'
# bind-key -n C-k if -F "#{@pane-is-vim}" 'send-keys C-k' 'select-pane -U'
# bind-key -n C-l if -F "#{@pane-is-vim}" 'send-keys C-l' 'select-pane -R'
bind-key -n C-Left if -F "#{@pane-is-vim}" 'send-keys C-Left' 'select-pane -L'
bind-key -n C-Down if -F "#{@pane-is-vim}" 'send-keys C-Down' 'select-pane -D'
bind-key -n C-Up if -F "#{@pane-is-vim}" 'send-keys C-Up' 'select-pane -U'
bind-key -n C-Right if -F "#{@pane-is-vim}" 'send-keys C-Right' 'select-pane -R'
# bind-key -n M-h if -F "#{@pane-is-vim}" 'send-keys M-h' 'resize-pane -L 3'
# bind-key -n M-j if -F "#{@pane-is-vim}" 'send-keys M-j' 'resize-pane -D 3'
# bind-key -n M-k if -F "#{@pane-is-vim}" 'send-keys M-k' 'resize-pane -U 3'
# bind-key -n M-l if -F "#{@pane-is-vim}" 'send-keys M-l' 'resize-pane -R 3'
bind-key -n M-Left if -F "#{@pane-is-vim}" 'send-keys M-Left' 'resize-pane -L 3'
bind-key -n M-Down if -F "#{@pane-is-vim}" 'send-keys M-Down' 'resize-pane -D 3'
bind-key -n M-Up if -F "#{@pane-is-vim}" 'send-keys M-Up' 'resize-pane -U 3'
bind-key -n M-Right if -F "#{@pane-is-vim}" 'send-keys M-Right' 'resize-pane -R 3'
bind-key -n C-\\ if -F "#{@pane-is-vim}" 'send-keys C-\\\\' 'select-pane -l'
# bind-key -T copy-mode-vi 'C-h' select-pane -L
# bind-key -T copy-mode-vi 'C-j' select-pane -D
# bind-key -T copy-mode-vi 'C-k' select-pane -U
# bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-Left' select-pane -L
bind-key -T copy-mode-vi 'C-Down' select-pane -D
bind-key -T copy-mode-vi 'C-Up' select-pane -U
bind-key -T copy-mode-vi 'C-Right' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l

### Sesh
bind-key "T" run-shell "sesh connect \"$(
	sesh list | fzf-tmux -p 55%,60% \
		--no-sort --ansi --border-label ' sesh ' --prompt '' \
		--header '  ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \
		--bind 'tab:down,btab:up' \
		--bind 'ctrl-a:change-prompt(⚡  )+reload(sesh list)' \
		--bind 'ctrl-t:change-prompt(🪟  )+reload(sesh list -t)' \
		--bind 'ctrl-g:change-prompt(⚙️  )+reload(sesh list -c)' \
		--bind 'ctrl-x:change-prompt(📁  )+reload(sesh list -z)' \
		--bind 'ctrl-f:change-prompt(🔎  )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
		--bind 'ctrl-d:execute(tmux kill-session -t {})+change-prompt(⚡  )+reload(sesh list)'
)\""

### Plugins
set -g @plugin "tmux-plugins/tpm"
set -g @plugin "catppuccin/tmux"
set -g @plugin "joshmedeski/tmux-nerd-font-window-name"
set -g @plugin "Freed-Wu/tmux-battery#termux"
set -g @plugin "tmux-plugins/tmux-yank"

### Catppuccin Theme Configuration
set -g @catppuccin_flavor "mocha"
set -g @catppuccin_status_background "#11111b"
set -g @catppuccin_application_color "#11111b"
set -g @catppuccin_application_icon ""
set -g @catppuccin_date_time_text "%d-%m-%y %H:%M"
set -g @catppuccin_status_left_separator ""
set -g @catppuccin_status_right_separator ""
set -g status-left ""
set -g status-right "#{E:@catppuccin_status_application}#{E:@catppuccin_status_session}#{E:@catppuccin_status_battery}#{E:@catppuccin_status_date_time}"

### TPM Installation
if "test ! -d $HOME/.config/tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm $HOME/.config/tmux/plugins/tpm && $HOME/.config/tmux/plugins/tpm/bin/install_plugins'"

run "$HOME/.config/tmux/plugins/tpm/tpm"

Attach screenshots.

Screenshot_20241002-140326_Termux

What tmux version are you seeing the issue on?

tmux 3.5

Any additional comments?

No response

@xronin01 xronin01 added the bug Something isn't working label Oct 2, 2024
@kjnsn
Copy link
Collaborator

kjnsn commented Oct 2, 2024

Does it work if you run run "~/.config/tmux/plugins/tpm/tpm" twice? You also need to set status-right and status-left after TPM, or the user options that the plugin sets won't have been added yet.

The battery status works by looking for a string in the status line, and then replaces it in-place. If that string isn't set by the time you run the battery plugin, it won't work. Which is why you need to either run TPM twice, or run catppuccin, set the status, and then load the battery module

@xronin01
Copy link
Author

xronin01 commented Oct 4, 2024

It didn't work

@kjnsn kjnsn mentioned this issue Oct 5, 2024
kjnsn added a commit that referenced this issue Oct 5, 2024
* fix: do not set the status length

This was added a few years ago, and does not seem to have any appreciable affect.
The setting can be set by users if required.

Fixes #356, #342 #347 #345

* fix(status): fix status line modules that need external substitution
@xronin01
Copy link
Author

xronin01 commented Oct 5, 2024

Screenshot_20241005-150654_Termux

@davidfmatheson
Copy link
Contributor

I see the same behavior, complete with #{battery_percentage} in the status bar.

@kjnsn
Copy link
Collaborator

kjnsn commented Oct 6, 2024

That makes sense, as you are only running tpm once. The status line is expanded by tmux, which will include the string the battery plugin is looking for.

You need to expand it correctly and then load the battery plugin. Please see that plugins docs for more information.

But this is working as intended from the perspective of this plugin

@kjnsn kjnsn closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2024
@davidfmatheson
Copy link
Contributor

It appears that the battery plugin is loaded correctly, if I replace my status line config with

set -g status-right "#{E:@catppuccin_status_directory}#{E:@catppuccin_status_date_time}#{battery_percentage}"

I do get the right number (the faint 73% on the end):

image

This is something that previously worked in 0.3.0. I will continue trying to suss it out, but it seems to be a problem here where you are setting it to the literal string #{battery_percentage}. Forgive my newness with tmux variables, but is that why you have E: before some vars, in the hopes that they are resolved and then resolved again?

@kjnsn
Copy link
Collaborator

kjnsn commented Oct 6, 2024

Rhetorical question: how does the battery plugin add the percentage to the status line?

@kjnsn
Copy link
Collaborator

kjnsn commented Oct 6, 2024

I will continue trying to suss it out, but it seems to be a problem

This is working as per what the battery plugin expects.

where you are setting it to the literal string #{battery_percentage}. Forgive my newness with tmux variables, but is that why you have E: before some vars, in the hopes that they are resolved and then resolved again?

It's not hope. And the term is not "resolved", format strings are "expanded". There are unit tests, and I've carefully read the tmux man page. Like I said, you need to source catppuccin, set the status-right and left options, and then load the battery plugin. It will not work any other way.

@davidfmatheson
Copy link
Contributor

Great, so the crux of the solution is to make sure I'm using set -gF and not set -g when setting status-right and status-left, to ensure that the format string is expanded. That gives me back an actual percentage. Is it possible that you need l: by battery_icon as well, or perhaps I'm still doing something else wrong?

image

@xronin01
Copy link
Author

xronin01 commented Oct 7, 2024

I got it to work, but the battery icon doesn't appear.

### Terminal
set -g default-terminal "tmux-256color"
set -ag terminal-features ",${TERM}:RGB"

### Mouse Support
set -g mouse on

### Status Bar Position
set -g status-position top

### Window Indexing
set -g base-index 1
set -g renumber-windows on

### Keymaps
unbind %
unbind '"'
bind v split-window -h
bind h split-window -v
bind r source-file $HOME/.config/tmux/tmux.conf \; display-message "Settings reloaded!"
# bind-key -n C-h if -F "#{@pane-is-vim}" 'send-keys C-h' 'select-pane -L'
# bind-key -n C-j if -F "#{@pane-is-vim}" 'send-keys C-j' 'select-pane -D'
# bind-key -n C-k if -F "#{@pane-is-vim}" 'send-keys C-k' 'select-pane -U'
# bind-key -n C-l if -F "#{@pane-is-vim}" 'send-keys C-l' 'select-pane -R'
bind-key -n C-Left if -F "#{@pane-is-vim}" 'send-keys C-Left' 'select-pane -L'
bind-key -n C-Down if -F "#{@pane-is-vim}" 'send-keys C-Down' 'select-pane -D'
bind-key -n C-Up if -F "#{@pane-is-vim}" 'send-keys C-Up' 'select-pane -U'
bind-key -n C-Right if -F "#{@pane-is-vim}" 'send-keys C-Right' 'select-pane -R'
# bind-key -n M-h if -F "#{@pane-is-vim}" 'send-keys M-h' 'resize-pane -L 3'
# bind-key -n M-j if -F "#{@pane-is-vim}" 'send-keys M-j' 'resize-pane -D 3'
# bind-key -n M-k if -F "#{@pane-is-vim}" 'send-keys M-k' 'resize-pane -U 3'
# bind-key -n M-l if -F "#{@pane-is-vim}" 'send-keys M-l' 'resize-pane -R 3'
bind-key -n M-Left if -F "#{@pane-is-vim}" 'send-keys M-Left' 'resize-pane -L 3'
bind-key -n M-Down if -F "#{@pane-is-vim}" 'send-keys M-Down' 'resize-pane -D 3'
bind-key -n M-Up if -F "#{@pane-is-vim}" 'send-keys M-Up' 'resize-pane -U 3'
bind-key -n M-Right if -F "#{@pane-is-vim}" 'send-keys M-Right' 'resize-pane -R 3'
bind-key -n C-\\ if -F "#{@pane-is-vim}" 'send-keys C-\\\\' 'select-pane -l'
# bind-key -T copy-mode-vi 'C-h' select-pane -L
# bind-key -T copy-mode-vi 'C-j' select-pane -D
# bind-key -T copy-mode-vi 'C-k' select-pane -U
# bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-Left' select-pane -L
bind-key -T copy-mode-vi 'C-Down' select-pane -D
bind-key -T copy-mode-vi 'C-Up' select-pane -U
bind-key -T copy-mode-vi 'C-Right' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l

### Sesh
bind-key "T" run-shell "sesh connect \"$(
	sesh list | fzf-tmux -p 55%,60% \
		--no-sort --ansi --border-label ' sesh ' --prompt '' \
		--header '  ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \
		--bind 'tab:down,btab:up' \
		--bind 'ctrl-a:change-prompt(⚡  )+reload(sesh list)' \
		--bind 'ctrl-t:change-prompt(🪟  )+reload(sesh list -t)' \
		--bind 'ctrl-g:change-prompt(⚙️  )+reload(sesh list -c)' \
		--bind 'ctrl-x:change-prompt(📁  )+reload(sesh list -z)' \
		--bind 'ctrl-f:change-prompt(🔎  )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
		--bind 'ctrl-d:execute(tmux kill-session -t {})+change-prompt(⚡  )+reload(sesh list)'
)\""

### Plugins
set -g @plugin "tmux-plugins/tpm"
set -g @plugin "catppuccin/tmux"
set -g @plugin "joshmedeski/tmux-nerd-font-window-name"
set -g @plugin "Freed-Wu/tmux-battery#termux"
set -g @plugin "tmux-plugins/tmux-yank"

### Catppuccin Theme Configuration
set -g @catppuccin_flavor "mocha"
set -g @catppuccin_status_background "#11111b"
set -g @catppuccin_application_color "#11111b"
set -g @catppuccin_application_icon ""
set -g @catppuccin_date_time_text "%d-%m-%y %H:%M"
set -g @catppuccin_status_left_separator ""
set -g @catppuccin_status_right_separator ""

# Load catppuccin
run "$HOME/.config/tmux/plugins/tmux/catppuccin.tmux"

set -g status-left ""
set -g status-right "#{E:@catppuccin_status_application}"
set -ag status-right "#{E:@catppuccin_status_session}"
set -agF status-right "#{E:@catppuccin_status_battery}"
set -ag status-right "#{E:@catppuccin_status_date_time}"

### TPM Installation
if "test ! -d $HOME/.config/tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm $HOME/.config/tmux/plugins/tpm && $HOME/.config/tmux/plugins/tpm/bin/install_plugins'"

run "$HOME/.config/tmux/plugins/tpm/tpm"

@xronin01
Copy link
Author

xronin01 commented Oct 7, 2024

Great, so the crux of the solution is to make sure I'm using set -gF and not set -g when setting status-right and status-left, to ensure that the format string is expanded. That gives me back an actual percentage. Is it possible that you need l: by battery_icon as well, or perhaps I'm still doing something else wrong?
image

Screenshot_20241007-131906_Termux_1

@davidfmatheson
Copy link
Contributor

Yes, I was mistaken, #{l:#{battery_icon}} doesn't help. Not sure how to get it to appear. On your above configuration, @xronin01, does it work after a fresh install? If you run:

tmux kill-server
$HOME/.config/tmux/plugins/tpm/bin/clean_plugins`
tmux new-session -t test-session

Does it still work? Fair warning, kill-server will close all open tmux sessions.

@xronin01
Copy link
Author

xronin01 commented Oct 7, 2024

#{l:#{battery_icon}} works for me

@davidfmatheson
Copy link
Contributor

#{l:#{battery_icon}} works for me

You're right, I just tested it again from a fork I created. I created a PR to fix it. To be clear, I'm just a user like you trying to figure out how to use this plugin since the post-0.3.0 rewrite.

Regarding the other question, does your setup still work after you kill all sessions and run clean_plugins?

@xronin01
Copy link
Author

xronin01 commented Oct 7, 2024

works 👍

@davidfmatheson
Copy link
Contributor

Hmmm... how does it manage to do:

run "$HOME/.config/tmux/plugins/tmux/catppuccin.tmux"

if that file isn't there until you run tpm down on:

run "$HOME/.config/tmux/plugins/tpm/tpm"

That's the problem I'm having with my setup.

@kjnsn
Copy link
Collaborator

kjnsn commented Oct 8, 2024

Hmmm... how does it manage to do:


run "$HOME/.config/tmux/plugins/tmux/catppuccin.tmux"

if that file isn't there until you run tpm down on:


run "$HOME/.config/tmux/plugins/tpm/tpm"

That's the problem I'm having with my setup.

Running TPM doesn't install the plugins. Is the problem that you haven't installed the plugins you need?

@davidfmatheson
Copy link
Contributor

Sorry, meant the line above:

if "test ! -d $HOME/.config/tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm $HOME/.config/tmux/plugins/tpm && $HOME/.config/tmux/plugins/tpm/bin/install_plugins'"

If you start from a clean slate (i.e. after a clean_plugins), isn't that where the plugin files will actually be populated in ~/.config/tmux/plugins? I'm in a pretty good state, though. Even loading from scratch, I just reload tmux config once and the battery icon and percentage show up. This PR was needed to make the icon show up, though. I was following @xronin01's comment here.

kjnsn pushed a commit that referenced this issue Oct 9, 2024
pauldthomson pushed a commit to pauldthomson/tmux that referenced this issue Nov 14, 2024
* fix: do not set the status length

This was added a few years ago, and does not seem to have any appreciable affect.
The setting can be set by users if required.

Fixes catppuccin#356, catppuccin#342 catppuccin#347 catppuccin#345

* fix(status): fix status line modules that need external substitution
pauldthomson pushed a commit to pauldthomson/tmux that referenced this issue Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants