add tmux plugin: prefix_highlight
This commit is contained in:
14
.tmux.conf
14
.tmux.conf
@@ -33,7 +33,6 @@ set -g mouse-select-pane on
|
||||
set -g mouse-resize-pane
|
||||
set -g mouse-select-window on
|
||||
|
||||
|
||||
##########################################
|
||||
### Styling
|
||||
##########################################
|
||||
@@ -54,7 +53,7 @@ set -g status-fg colour137
|
||||
set -g status-attr dim
|
||||
set -g status-left ''
|
||||
set -g status-left-length 20
|
||||
set -g status-right "#[fg=colour233,bg=colour245,bold] #(tmux-mem-cpu-load -g 5 --interval 1) %H:%M:%S "
|
||||
set -g status-right "#{prefix_highlight} #[fg=colour233,bg=colour245,bold] #(tmux-mem-cpu-load -g 5 --interval 1) %H:%M:%S "
|
||||
set -g status-right-length 60
|
||||
|
||||
# messaging
|
||||
@@ -138,3 +137,14 @@ bind-key C-b last-window
|
||||
|
||||
# special settings for MacOS
|
||||
if-shell 'test "$(uname)" = "Darwin"' 'source ~/.tmux-osx.conf'
|
||||
|
||||
##########################################
|
||||
### Plugins
|
||||
##########################################
|
||||
|
||||
# prefix_highlight (https://github.com/tmux-plugins/tmux-prefix-highlight)
|
||||
run-shell ~/.tmux/prefix_highlight.tmux
|
||||
set -g @prefix_highlight_fg 'white' # default is 'colour231'
|
||||
set -g @prefix_highlight_bg 'blue' # default is 'colour04'
|
||||
set -g @prefix_highlight_show_copy_mode 'on'
|
||||
set -g @prefix_highlight_copy_mode_attr 'fg=black,bg=yellow,bold' # default is 'fg=default,bg=yellow'
|
||||
70
.tmux/prefix_highlight.tmux
Executable file
70
.tmux/prefix_highlight.tmux
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# Place holder for status left/right
|
||||
place_holder="\#{prefix_highlight}"
|
||||
|
||||
# Possible configurations
|
||||
fg_color_config='@prefix_highlight_fg'
|
||||
bg_color_config='@prefix_highlight_bg'
|
||||
show_copy_config='@prefix_highlight_show_copy_mode'
|
||||
copy_attr_config='@prefix_highlight_copy_mode_attr'
|
||||
|
||||
# Defaults
|
||||
default_fg='colour231'
|
||||
default_bg='colour04'
|
||||
default_copy_attr='fg=default,bg=yellow'
|
||||
|
||||
tmux_option() {
|
||||
local -r value=$(tmux show-option -gqv "$1")
|
||||
local -r default="$2"
|
||||
|
||||
if [ ! -z "$value" ]; then
|
||||
echo "$value"
|
||||
else
|
||||
echo "$default"
|
||||
fi
|
||||
}
|
||||
|
||||
highlight() {
|
||||
local -r \
|
||||
status="$1" \
|
||||
prefix="$2" \
|
||||
prefix_highlight="$3" \
|
||||
show_copy_mode="$4" \
|
||||
copy_highlight="$5"
|
||||
|
||||
local -r status_value="$(tmux_option "$status")"
|
||||
|
||||
if [[ "on" = "$show_copy_mode" ]]; then
|
||||
local -r fallback="${copy_highlight}#{?pane_in_mode,Copy,}"
|
||||
else
|
||||
local -r fallback=""
|
||||
fi
|
||||
|
||||
local -r highlight_on_prefix="${prefix_highlight}#{?client_prefix, $prefix ,$fallback}#[default]"
|
||||
tmux set-option -gq "$status" "${status_value/$place_holder/$highlight_on_prefix}"
|
||||
}
|
||||
|
||||
main() {
|
||||
local -r \
|
||||
prefix=$(tmux_option prefix) \
|
||||
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") \
|
||||
copy_attr=$(tmux_option "$copy_attr_config" "$default_copy_attr")
|
||||
|
||||
local -r short_prefix=$(
|
||||
echo "$prefix" | tr "[:lower:]" "[:upper:]" | sed 's/C-/\^/'
|
||||
)
|
||||
|
||||
local -r \
|
||||
prefix_highlight="#[fg=$fg_color,bg=$bg_color]" \
|
||||
copy_highlight="${copy_attr:+#[default,$copy_attr]}"
|
||||
|
||||
highlight "status-right" "$short_prefix" "$prefix_highlight" "$show_copy_mode" "$copy_highlight"
|
||||
highlight "status-left" "$short_prefix" "$prefix_highlight" "$show_copy_mode" "$copy_highlight"
|
||||
}
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user