tmux-plugins / tmux-battery

Plug and play battery percentage and icon indicator for Tmux.
MIT License
503 stars 98 forks source link

Can't get it working #48

Closed nerdpad closed 7 years ago

nerdpad commented 7 years ago

I am sure something is wrong with my config. I am very new to shell scripting, and not sure if I am constructing the battery template right.

Can you please take a look at this change set. https://github.com/NerdPad/dotfiles/commit/4b430caca65ff9ed581cbf3b58ba0232b53e8632#diff-e4a99bf3a7fbdabd6456dad3160011e3

I added the following lines to my theme.sh, which is sourced in tmux.config after tmp is loaded.

I am running OSX Sierra

Theme.sh

tm_battery="$battery_icon $battery_percentage $battery_remain"
set -g status-right $tm_tunes' '$tm_battery' '$tm_date' '$tm_host

Tmux Plugin

###########################
### Tmux Plugin Manager ###
###########################

# List of plugins
set -g @tpm_plugins '           \
  tmux-plugins/tpm              \
  tmux-plugins/tmux-sensible    \
  tmux-plugins/tmux-resurrect   \
  tmux-plugins/tmux-battery     \
'

# Initialize TMUX plugin manager
run '~/.tmux/plugins/tpm/tpm'

Tmux.conf

# load tmux plugin manager
source ~/.dotfiles/tmux/tmux.plugins.sh

#######################
### Color & Style Settings ###
#######################

source ~/.dotfiles/tmux/theme.sh

All the plugins are installed.

martinbeentjes commented 7 years ago

tm_battery="$battery_icon $battery_percentage $battery_remain"

This should be changed to

tm_battery="#{battery_icon} #{battery_percentage} #{battery_remain}"

nerdpad commented 7 years ago

I have tried that but I still don't see any indicator, it's completely empty.

in my tmux.conf I source the plugin.sh before the theme.sh, so the variables should be available, right?

when I echo the variables I see the following.

~/.dotfiles
⇨ echo $tm_icon     # This works
🙊

~/.dotfiles
⇨ echo $battery_percent # this doesn't. all variables related to the plugin return empty
martinbeentjes commented 7 years ago

How did you install the plugin? I recommend using tpm. Follow their README to install tpm. After installing tpm, add set -g @plugin 'tmux-plugins/tmux-battery to your tmux configuration file. Source your configuration file, and check if it works now.

I do not understand what you are doing exactly. Try by doing exactly what the README of tpm and tmux-battery say.

nerdpad commented 7 years ago

@martinbeentjes I do have tmp installed, and installed the plugin via tpm (Prefix+I), and I am following the instructions properly, the plugin is also installed.

Instead of adding the plugins in my tmux config, I created another file for them, and I am sourcing that file in my tmux.conf before I source another file (theme.sh) that actually sets the tmux status line.

tmux.plugin.sh (https://github.com/NerdPad/dotfiles/blob/master/tmux/tmux.plugins.sh)

###########################
### Tmux Plugin Manager ###
###########################

# List of plugins
set -g @tpm_plugins '           \
  tmux-plugins/tpm              \
  tmux-plugins/tmux-sensible    \
  tmux-plugins/tmux-resurrect   \
  tmux-plugins/tmux-battery     \
'

# Initialize TMUX plugin manager
run '~/.tmux/plugins/tpm/tpm'

This file is sourced in my tmux.conf

tmux.conf (https://github.com/NerdPad/dotfiles/blob/master/tmux/tmux.conf.symlink)

...
...
# load tmux plugin manager
source ~/.dotfiles/tmux/tmux.plugins.sh

#######################
### Color & Style Settings ###
#######################

source ~/.dotfiles/tmux/theme.sh # this is the last line in my tmux.conf

Theme.sh that customizes tmux look. https://github.com/NerdPad/dotfiles/blob/master/tmux/theme.sh

martinbeentjes commented 7 years ago

First of all, @tpm_plugins is deprecated. Please change this to:

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-battery'

Second, run '~/.tmux/plugins/tpm/tpm' should be ran at last. (So just at the end of the tmux configuration file.

Third, maybe it is me but the followings looks like it is missing some quotes:

set -g status-left $tm_session_name' '
set -g status-right $tm_tunes' '$battery_icon' '$tm_date' '$tm_host

I personally did the following:

set -g status-right "#{battery_status_bg} #{battery_percentage} #[bg=default,fg=default] #H %d/%m %H:%M"

What is the reason that you split the configuration into several different files? I personally can't find anything now in your config even with this small amount of files. I really recommend just sticking to one .tmux.conf which lives in your $HOME folder (~).

martinbeentjes commented 7 years ago

Hey @nerdpad, can you tell if the above has worked? Do you still have problems?

nerdpad commented 7 years ago

@martinbeentjes I have currently stopped using tmux-plugins. Will close the issue for now, will open it later when I test it.