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

Environment variables in tmux options not honoured #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Hats off to [dark-notify](https://github.com/cormacrelf/dark-notify) which this
```conf
set -g @plugin 'erikw/tmux-dark-notify'
```
* Now you must configure the paths for the light/dark themes you want to use. I personally have [seebi/tmux-colors-solarized](https://github.com/seebi/tmux-colors-solarized) installed as a TPM plugin. NOTE that in the tmux.conf any themes must be set up before tmux-dark-notify, otherwise they might override the theme set by this plugin. . Change the paths below to your themes.
* Now you must configure the paths for the light/dark themes you want to use. I personally have [seebi/tmux-colors-solarized](https://github.com/seebi/tmux-colors-solarized) installed as a TPM plugin. NOTE that in the tmux.conf any themes must be set up before tmux-dark-notify, otherwise they might override the theme set by this plugin. . Change the paths below to your themes. *NOTE: If using environment variables in the `@dark-notify-theme-path-*` TPM options use double quotes for the plugin to deal with the variable expanded, otherwise it won't resolve.*
```conf
set -g @dark-notify-theme-path-light '$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-light.conf'
set -g @dark-notify-theme-path-dark '$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-dark.conf'
set -g @dark-notify-theme-path-light "$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-light.conf"
set -g @dark-notify-theme-path-dark "$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-dark.conf"
```
* To cover some corner cases e.g. if you use the plugin [tmux-reset](https://github.com/hallazzang/tmux-reset) or another TPM plugin sets the theme itself, I recommend adding this explicit source of the theme as well as a fallback in case this plugin is not run in all scenarios. The `if-shell` condition is there because the symlink won't be there the very first time until tmux-dark-notify has run. It should be placed after TPM is initialized, because the ordering of plugin initialization is not guaranteed. **Remove any other** `source-file` for theme you have of course!
```conf
Expand All @@ -49,8 +49,8 @@ Hats off to [dark-notify](https://github.com/cormacrelf/dark-notify) which this
set -g @plugin 'seebi/tmux-colors-solarized'
set -g @plugin 'erikw/tmux-dark-notify'

set -g @dark-notify-theme-path-light '$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-light.conf'
set -g @dark-notify-theme-path-dark '$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-dark.conf'
set -g @dark-notify-theme-path-light "$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-light.conf"
set -g @dark-notify-theme-path-dark "$HOME/.config/tmux/plugins/tmux-colors-solarized/tmuxcolors-dark.conf"

[...]
run-shell '~/.config/tmux/plugins/tpm/tpm' # Or however you source tpm.
Expand Down
7 changes: 7 additions & 0 deletions scripts/tmux-theme-mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ tmux_set_theme_mode() {
else
theme_path=$(tmux_get_option $OPTION_THEME_LIGHT)
fi

# NOTE: If the user specified the path with single quotes as
# `set @dark-notify-theme-path-light '$HOME/a/b/c` it will resolve as `\$HOME/a/b/c`
# here, to avoid that make sure the user uses double quotes in their `.tmux.conf`'s
# `"$HOME/a/b/c"` or else this script needs to sanitize that backslack for the `eval
# echo `"$theme_path"` to properly expand the environment variables.

# Expand e.g. $HOME
theme_path=$(eval echo "$theme_path")
if [ ! -r "$theme_path" ]; then
Expand Down