What are the differences between set -g, set -ga and set-option -g in a .tmux.conf file? - configuration-files

I'm new to tmux and trying to understand it's configuration. I've started with looking at some pre-existing .tmux.conf files and whatever documentation I can find but it still leaves me wondering about the flags. I've seen the following so far:
A few examples from the ArchWiki entry on tmux
set -g prefix C-a
set -ga terminal-overrides ",xterm-termite:Tc"
set-option -g xterm-keys on
And one line from a .tmux.conf file
set-window-option -g
What do the flags mean and are there any particular cases when one flag one flag is preferable over another?

set is the alias of set-option.
set -g is used to set global options and -ga appends values to existing settings.
From Tmux's man page:
With -a, and if the option expects a string or a style, value is
appended to the existing setting. For example:
set -g status-left "foo"
set -ag status-left "bar"
Will result in ‘foobar’. And:
set -g status-style "bg=red"
set -ag status-style "fg=blue"
Will result in a red background and blue foreground. Without -a, the
result would be the default background and a blue foreground.
set-window-option (alias setw) is used to configure window options (allow-rename, mode-keys, synchronize-panes, etc.) and the same flag options are available.
See:
https://linux.die.net/man/1/tmux
https://superuser.com/questions/758843/difference-between-global-server-session-and-window-options

Related

How can I enable tab-completion for `#` path options to HTTPie in fish?

HTTPie accepts paths as arguments with options that include the # sign. Unfortunately, they don't seem to work with shell completions in fish. Instead, the option is treated as an opaque string.
To stick with the file upload example from the HTTPie documentation with a file at ~/files/data.xml, I would expect to be able to tab complete the file name when typing:
http -f POST pie.dev/post name='John Smith' cv#~/files/da<TAB>
However, no completion is offered.
I have installed the completions for fish from the HTTPie project and they work for short and long arguments. This file does not specify how to complete the # arguments though.
In addition, I looked into specifying my own completions but I am not able to find a way of getting to work file completions with the arbitrary prefix.
How could I implement a completion for these path arguments for HTTPie?
Currently, the fish completions for HTTPie do not have completion for file path arguments with #. There is a more general GitHub Issue open about this.
If this is something you'd like to work on, either for yourself or for the project, you might be able draw some inspiration for the fish implementation from an HTTPie plugin for zsh+ohmyzsh that achieves your desired behaviour.
I managed to get the tab completion of the path arguments working with some caveats.
This adds the completion:
complete -c http --condition "__is_httpie_path_argument" -a "(__complete_httpie_path_argument (commandline -t))"
With the following functions:
function __is_httpie_path_argument
set -l arg (commandline -t)
__match_httpie_path_argument --quiet -- $arg
end
function __match_httpie_path_argument
string match --entire --regex '^([^#:=]*)(#|=#|:=#)(.*)$' $argv
end
function __complete_httpie_path_argument
__complete_httpie_path_argument_helper (__match_httpie_path_argument -- $argv[1])
end
function __complete_httpie_path_argument_helper
set -l arg $argv[1]
set -l field $argv[2]
set -l operator $argv[3]
set -l path $argv[4]
string collect $field$operator(__fish_complete_path $path)
end
The caveat is that this does not expand any variables nor the tilde ~. It essentially only works for plain paths — relative or absolute.

dynamic background color for custom prompt element in Powerlevel9k

I am using the awesome Powerlevel9k theme for my Zsh.
I defined a custom kubecontext element to show my kubernetes cluster (context) and namespace (see code below).
While I conditionally set the foreground color through the color variable I would like to set the background color instead to be able to better see when I work on the production cluster.
Is that somehow possible with Powerlevel9k? All I could find is that I can set the background color of the prompt element statically with POWERLEVEL9K_CUSTOM_KUBECONTEXT_BACKGROUND='075'
# Kubernetes Current Context/Namespace
custom_prompt_kubecontext() {
local kubectl_version="$(kubectl version --client 2>/dev/null)"
if [[ -n "$kubectl_version" ]]; then
# Get the current Kuberenetes context
local cur_ctx=$(kubectl config view -o=jsonpath='{.current-context}')
cur_namespace="$(kubectl config view -o=jsonpath="{.contexts[?(#.name==\"${cur_ctx}\")].context.namespace}")"
# If the namespace comes back empty set it default.
if [[ -z "${cur_namespace}" ]]; then
cur_namespace="default"
fi
local k8s_final_text="$cur_ctx/$cur_namespace"
local color='%F{black}'
[[ $cur_ctx == "prod" ]] && color='%F{196}'
echo -n "%{$color%}\U2388 $k8s_final_text%{%f%}" # \U2388 is Kubernetes Icon
#"$1_prompt_segment" "$0" "$2" "magenta" "black" "$k8s_final_text" "KUBERNETES_ICON"
fi
}
POWERLEVEL9K_CUSTOM_KUBECONTEXT="custom_prompt_kubecontext"
# Powerlevel9k configuration
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs custom_kubecontext)
Here is a screenshot of the current setup in action:
Disclaimer: I'm the author of powerlevel10k.
No, this is not possible in powerlevel9k. It is, however, possible in powerlevel10k. Powerlevel10k is backward compatible with powerlevel9k configuration, meaning that you won't have to change any POWERLEVEL9K parameters if you decide to switch.
Powerlevel10k has several advantages over its predecessor:
It's over 10 times faster.
It has a builtin configuration wizard. Type p10k configure to access it.
It has many new features. One of them is relevant to you. The builtin kubecontext supports context classes that allow you to style this prompt segment differently depending on which kubernetes context is currently active. Here's the excerpt from the configuration that p10k configure generates:
# Kubernetes context classes for the purpose of using different colors, icons and expansions with
# different contexts.
#
# POWERLEVEL9K_KUBECONTEXT_CLASSES is an array with even number of elements. The first element
# in each pair defines a pattern against which the current kubernetes context gets matched.
# More specifically, it's P9K_CONTENT prior to the application of context expansion (see below)
# that gets matched. If you unset all POWERLEVEL9K_KUBECONTEXT_*CONTENT_EXPANSION parameters,
# you'll see this value in your prompt. The second element of each pair in
# POWERLEVEL9K_KUBECONTEXT_CLASSES defines the context class. Patterns are tried in order. The
# first match wins.
#
# For example, given these settings:
#
# typeset -g POWERLEVEL9K_KUBECONTEXT_CLASSES=(
# '*prod*' PROD
# '*test*' TEST
# '*' DEFAULT)
#
# If your current kubernetes context is "deathray-testing/default", its class is TEST
# because "deathray-testing/default" doesn't match the pattern '*prod*' but does match '*test*'.
#
# You can define different colors, icons and content expansions for different classes:
#
# typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_FOREGROUND=0
# typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_BACKGROUND=2
# typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_VISUAL_IDENTIFIER_EXPANSION='⭐'
# typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_CONTENT_EXPANSION='> ${P9K_CONTENT} <'
typeset -g POWERLEVEL9K_KUBECONTEXT_CLASSES=(
# '*prod*' PROD # These values are examples that are unlikely
# '*test*' TEST # to match your needs. Customize them as needed.
'*' DEFAULT)
typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_FOREGROUND=7
typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_BACKGROUND=5
typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⎈'
You can also customize the text content of kubecontext. You'll find more info in ~/.p10k.zsh once you run p10k configure. Oh, and kubecontext is about 1000 times faster in powerlevel10k.

scons: how to define command/target that only takes place during 'scons -c'?

Before building the targets I wish to create some directory structures, I know I can use:
env = Environment()
env.Execute('mkdir -p xxx')
But this will cause "mkdir -p' to be executed even when I do clean up:
scons -c
And the "env.Execute" will gets called.
I wish there's some command or target that's only taking place when I execute 'scons -c'
How to achieve that?
Thanks.
The -c option is a built in scons option and you can check if it was set with GetOption('clean').
You could then call the commands conditionally based off the value of the 'clean' option. Here is an example:
env = Environment()
if not GetOption('clean'):
env.Execute('mkdir -p xxx')
else:
env.Execute('echo "Cleaning up..."')
More info on the other built in options can be found here:
https://scons.org/doc/production/HTML/scons-user.html#sect-command-line-option-strings
https://scons.org/doc/production/HTML/scons-man.html#options

Byobu - CentOS - Turning off window auto-renaming

Window name shows the current directory path. If we rename the window name, then whenever we change a path in that window, the name always reverts back to the current directory path.
I tried updating set-window-option -g automatic-rename on to set-window-option -g automatic-rename off in /usr/share/byobu/profile/tmux with no effect.
It looks like the config set-window-option -g automatic-rename off
doesn't work. When I added the following configuration:
set-option -g allow-rename off
in /usr/share/byobu/profiles/tmux, automatic renaming was turned off.

Oh-my-zsh aliases do not autocomplete

I am a bit out of my wits researching this... and I just have to ask.
I have oh-my-zsh on my Mavericks machine and have everything updated. I also have Xcode and Brew. All updated. According to this page: https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet am I not supposed to just type, say: "g" [tab] and get "git"? or type "md" [tab] and get "mkdir -p"? Right now I just get a list of options I can tab through (or arrow through)... I thought it would autocomplete. What am I missing?
I have a feeling it might be related to my $PATH but that is where I also get confused... where should it point to?
I greatly appreciate and enlightenment.
# Path to your oh-my-zsh configuration.
#ZSH=$HOME/.oh-my-zsh
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#ZSH_THEME="af-magic"
ZSH_THEME="agnoster"
# Set to this to use case-sensitive completion
# CASE_SENSITIVE="true"
# Comment this out to disable weekly auto-update checks
# DISABLE_AUTO_UPDATE="true"
# Uncomment following line if you want to disable colors in ls
# DISABLE_LS_COLORS="true"
# Uncomment following line if you want to disable autosetting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment following line if you want red dots to be displayed while waiting for completion
COMPLETION_WAITING_DOTS="true"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git textmate sublime zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
#export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/$
#export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/local/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
zstyle ':completion:*' list-prompt ''
zstyle ':completion:*' select-prompt ''
autoload -Uz compinit
compinit
Aliases are essentially just short names for commands. Before executing a command zsh internally replaces aliases by their values. But by default aliases are not expanded when using completion (Tab), they are handled just like any other command.
For example:
alias ll='ls -l'
alias la='ls -al'
If you now type lTab, zsh will present you every command starting with an l, including the aliases ll and la. If you type llTab it will probably just add an space after ll (assuming there are no other commands starting with ll).
When you run ll somedir it does the exact same thing as ls -l somedir. You can even add other options of ls: ll -t somedir runs ls -l -t somedir.
That being said, if you want to expand aliases when typing Tab, zsh can do so.
There are two ways:
You can call the _expand_alias widget. In emacs mode (bindkey -e) this is bound to ^Xa (press Control+X then A).
You can add _expand_alias to the completer style. It seems that oh-my-zsh does not change this style from its default value, so adding
zstyle ':completion:*' completer _expand_alias _complete _ignored
to your ~/.zshrc should work.
(To be save you can print the current setting with zstyle -L ':completion:*' completer, _expand_alias has to come before _complete)
If you now type llTab, zsh will replace it with ls -l immediatelly.
Note: in both cases the cursor has to be in or just after the alias for the replacement to happen. This also means you have to type the whole alias or backspace if automatically completed (_completer adds a space after successful completion)