-
Notifications
You must be signed in to change notification settings - Fork 44
New setting options_scope which allows having per session configuration
#31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ set -e | |
| place_holder="\#{prefix_highlight}" | ||
|
|
||
| # Possible configurations | ||
| option_scope_config='@prefix_highlight_option_scope' | ||
| fg_color_config='@prefix_highlight_fg' | ||
| bg_color_config='@prefix_highlight_bg' | ||
| output_prefix='@prefix_highlight_output_prefix' | ||
|
|
@@ -22,7 +23,7 @@ empty_attr_config='@prefix_highlight_empty_attr' | |
| empty_has_affixes='@prefix_highlight_empty_has_affixes' | ||
|
|
||
| tmux_option() { | ||
| local -r value=$(tmux show-option -gqv "$1") | ||
| local -r value=$(tmux show-option -Aqv "$1") | ||
| local -r default="$2" | ||
|
|
||
| if [ -n "$value" ]; then | ||
|
|
@@ -36,6 +37,14 @@ format_style() { | |
| echo "#[${1}]" | sed -e 's/,/]#[/g' | ||
| } | ||
|
|
||
| interpolate() { | ||
| local -r option=$1 | ||
| local -r replacement=$2 | ||
| local -r option_scope=${3#-} | ||
| local -r option_value=$(tmux_option "$option") | ||
| tmux set-option -"$option_scope"q "$option" "${option_value/$place_holder/$replacement}" | ||
| } | ||
|
|
||
| # Defaults | ||
| default_fg='colour231' | ||
| default_bg='colour04' | ||
|
|
@@ -49,6 +58,7 @@ default_empty_prompt='' | |
|
|
||
| main() { | ||
| local -r \ | ||
| option_scope=$(tmux_option "$option_scope_config" "g") \ | ||
| fg_color=$(tmux_option "$fg_color_config" "$default_fg") \ | ||
| bg_color=$(tmux_option "$bg_color_config" "$default_bg") \ | ||
| show_copy_mode=$(tmux_option "$show_copy_config" "off") \ | ||
|
|
@@ -94,11 +104,9 @@ main() { | |
|
|
||
| local -r highlight="#{?client_prefix,$prefix_mode,$fallback}#[default]" | ||
|
|
||
| local -r status_left_value="$(tmux_option "status-left")" | ||
| tmux set-option -gq "status-left" "${status_left_value/$place_holder/$highlight}" | ||
| interpolate "status-left" "$highlight" "$option_scope" | ||
|
|
||
| local -r status_right_value="$(tmux_option "status-right")" | ||
| tmux set-option -gq "status-right" "${status_right_value/$place_holder/$highlight}" | ||
| interpolate "status-right" "$highlight" "$option_scope" | ||
| } | ||
|
|
||
| main | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @imomaliev if you're stilll interested in knowing why this was problematic, this |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why yet, but this broke my status bar. And it's not just me: #32
Changing the
Aback togin the flags fixed everything (I don't understand why), but I think it also takes away the contribution of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carlocab Hi. Very strange.
-Ashould be inheriting all options. Maybe we should rollback this PR for nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been debugging this a little. Pretty sure #30 is related. I'm no C developer but I've been reading the tmux source code for a while to try and make sense of the issue and I think I might have understood enough.
There's a function in
cmd-show-options.ccalledcmd_show_options_execwhich is what runs when you do something liketmux show-options -gqv status-leftortmux show-options -Aqv status-left. One of the first things this function does is to check the scope of the option like this.The
&oothere is the options data which the function will later search to find thestatus-leftorstatus-rightvalue. Over in the implementation ofoptions_scope_from_nameinoptions.c, this&oostruct is actually overwritten in one of two ways depending on the flags. If thegflag is used, thenglobal_s_optionsis written to&oowhich I think is the full global config from.tmux.conf. Otherwise, in theelsebranch,s->optionsis written to&oo, which I think is only the session options.So if I'm understanding this code correctly, then removing the
gflag from the call toshow-optioncauses it to ignore the global config and use only the session config. It's weird though because I can run either version of the command manually in the terminal and get the right result. But it does look like a revert might be the way to go here!Had a lot of fun digging into this tonight BTW. I hope some of what I came up with is actually correct, or maybe even useful if I'm lucky!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have sent a quick revert PR over at #33. I'm loving how much I'm learning about tmux from all this @imomaliev and you've inspired me to try and learn a bit more about sessions at some point. Might be fun to see if I can figure out a way to make this feature work someday. For all I know though we could have tripped up on a bug in tmux itself here 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the issue is that calling
tmux show-option -Aqv status-leftreturns nothing when run from a shell script usingrun-shellintmux.conf.I did this a few times in my
tmux.conf, and this gave me the following:Could be a tmux bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you report this to tmux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet. I intended to poke at it a bit more to try to pin down the problem more precisely (e.g. is it just
-Avs-g, or is it from the combination with-qv? Is it just status options that are affected?), but I just haven't managed to find the time yet.