import of old configs

This commit is contained in:
andrzej 2024-04-26 19:38:35 +02:00
parent b7be648881
commit 35072b2bca
77 changed files with 5720 additions and 0 deletions

4
bash/.bash_aliases Normal file
View File

@ -0,0 +1,4 @@
alias cuqui="wakeonlan B8:AE:ED:74:C8:B7 && sleep 5 && ssh cuqui@192.168.0.57"
alias cheese="~/scripts/cheesecake.sh"
alias work="~/scripts/sfw.sh"
alias update="apt update && apt upgrade -y"

129
bash/.bashrc Normal file
View File

@ -0,0 +1,129 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
eval "$(zoxide init bash)"
set -o vi
export DENO_INSTALL="/home/andrzej/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
. "$HOME/.cargo/env"

22
git/.gitconfig Normal file
View File

@ -0,0 +1,22 @@
[user]
email = andrzejjamesstepien@gmail.com
name = andrzej
[core]
pager = diff-so-fancy | less --tabs=4 -RF
[interactive]
diffFilter = diff-so-fancy --patch
[color]
ui = true
[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
newHighlight = green bold 22
[color "diff"]
meta = 11
frag = magenta bold
func = 146 bold
commit = yellow bold
old = red bold
new = green bold
whitespace = red reverse

View File

@ -0,0 +1,7 @@
VteTerminal,
vte-terminal,
TerminalScreen {
padding: 0px;
margin: 0px;
-VteTerminal-inner-border: 0px;
}

7
scripts/dbus-monitor_test.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
while true; do
echo "start of loop"
dbus-monitor --session "interface='org.cinnamon.ScreenSaver', member='ActiveChanged'"
# echo "$OUTPUT"
sleep 1
done

View File

@ -0,0 +1,109 @@
#!/bin/bash
# Script to set a custom background or slideshow for Cinnamon's default lockscreen & screensaver
# Built and tested with Cinnamon 4.0.9 on Mint 19.1, but will probably work with older versions of Cinnamon
# Save the script as ~/bin/lock_screen_slideshow.sh or ~/.local/bin/lock_screen_slideshow.sh and make executable
# Add a entry to Startup Applications to launch the script after user login with a delay of 30 seconds
# These variables are intended to be set by the end user.
# Set STATIC_BACKGROUND to the path to your image of choice for static image mode
STATIC_BACKGROUND="/usr/share/backgrounds/linuxmint/default_background.jpg"
# Set SLIDESHOW to true if you want a lock-screen / screensaver slideshow, false if you want a static image
SLIDESHOW=true
# Set SLIDESHOW_DIR to a directory of your choice
# This directory and it's sub-directorys will be searched for images
# for display in a random order in slideshow mode
SLIDESHOW_DIR="/usr/share/backgrounds"
# Set SLIDESHOW_RANDOM to true if you want the display of images in slideshow mode to be randomised, false if not
SLIDESHOW_RANDOM=true
# Set to PERSISTENT_INDEX=true if you want to remember the position of a non-random slideshow between sessions, false if not
PERSISTENT_INDEX=true
# INTERVAL is the time time in seconds between background transitions in slideshow mode
INTERVAL=10
# Main script starts here
# Check for existing instances and kill them leaving current instance running
for PID in $(pidof -o %PPID -x "${0##*/}"); do
if [ "$PID" != $$ ]; then
kill -9 "$PID"
fi
done
# set initial status
ACTIVE=false
# Populate IMAGES array in non random slideshow mode
if ( $SLIDESHOW && ! $SLIDESHOW_RANDOM ); then
if ( $PERSISTENT_INDEX ) && [ -f ~/.config/smurphos_lock_screen_index ]; then
INDEX=$(cat ~/.config/smurphos_lock_screen_index)
else
INDEX=0
fi
IMAGES=()
while IFS= read -r -d $'\n'; do
IMAGES+=("$REPLY")
done < <(find "$SLIDESHOW_DIR" -iname '*.*p*g' | sort -n)
fi
# Start the main loop to monitor screensaver status changes
dbus-monitor --session "interface='org.cinnamon.ScreenSaver', member='ActiveChanged'" | while read -r STATE
do
if echo "$STATE" | grep -q "boolean true"; then
# If screensaver just activated check status of native background slide-show, get user background and either set static
# lock screen background or start slideshow
if ( ! $ACTIVE ) ; then
NATIVE_SLIDESHOW_STATE=$(gsettings get org.cinnamon.desktop.background.slideshow slideshow-enabled)
DESK_BACKGROUND=$(gsettings get org.cinnamon.desktop.background picture-uri)
DESK_MODE=$(gsettings get org.cinnamon.desktop.background picture-options)
gsettings set org.cinnamon.desktop.background picture-options "zoom"
ACTIVE=true
if ( ! $SLIDESHOW ) ; then
gsettings set org.cinnamon.desktop.background picture-uri "file://$STATIC_BACKGROUND"
else
((TIMER=SECONDS))
fi
fi
# Update background if in slideshow mode
if ( $SLIDESHOW ); then
# Start loop to update background whilst screensaver remains active
while dbus-send --print-reply --dest=org.cinnamon.ScreenSaver /org/cinnamon/ScreenSaver org.cinnamon.ScreenSaver.GetActive | grep -q "boolean true"
do
if (( TIMER <= SECONDS )) ; then
if ( $SLIDESHOW_RANDOM ); then
LOCK_BACKGROUND="$(find "$SLIDESHOW_DIR" -iname '*.*p*g' | shuf -n1)"
else
LOCK_BACKGROUND="${IMAGES[$INDEX]}"
((INDEX++))
if [ $INDEX -ge "${#IMAGES[@]}" ]; then
INDEX=0
fi
if ( $PERSISTENT_INDEX ); then
echo "$INDEX" > ~/.config/smurphos_lock_screen_index
fi
fi
gsettings set org.cinnamon.desktop.background picture-uri "file://$LOCK_BACKGROUND"
((TIMER=SECONDS+INTERVAL))
fi
# Sleep adds a slight delay to background reverting after the slideshow ends, but avoids excessive CPU by limiting the looped check of screensaver status to once per second.
sleep 1
done
fi
else
# Set background back to the user background and unpause native slideshow on screensaver de-activation
if ( $ACTIVE ) ; then
gsettings set org.cinnamon.desktop.background picture-options "$DESK_MODE"
if ( $NATIVE_SLIDESHOW_STATE ) ; then
gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled "$NATIVE_SLIDESHOW_STATE"
else
gsettings set org.cinnamon.desktop.background picture-uri "$DESK_BACKGROUND"
fi
ACTIVE=false
fi
fi
done

18
scripts/make_bg_default.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
setDefaultBg() {
sudo -H -u andrzej gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled false && gsettings set org.cinnamon.desktop.background picture-uri "file:///${HOME}/bgs/default.jpg"
}
case "$1" in
pre)
;;
post)
setDefaultBg
;;
esac
exit 0

1145
scripts/scripts/bin/diff-so-fancy Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,291 @@
package DiffHighlight;
use 5.008;
use warnings FATAL => 'all';
use strict;
# Use the correct value for both UNIX and Windows (/dev/null vs nul)
use File::Spec;
my $NULL = File::Spec->devnull();
# Highlight by reversing foreground and background. You could do
# other things like bold or underline if you prefer.
our @OLD_HIGHLIGHT = (
undef,
"\e[7m",
"\e[27m",
);
our @NEW_HIGHLIGHT = (
$OLD_HIGHLIGHT[0],
$OLD_HIGHLIGHT[1],
$OLD_HIGHLIGHT[2],
);
my $RESET = "\x1b[m";
my $COLOR = qr/\x1b\[[0-9;]*m/;
my $BORING = qr/$COLOR|\s/;
my @removed;
my @added;
my $in_hunk;
my $graph_indent = 0;
our $line_cb = sub { print @_ };
our $flush_cb = sub { local $| = 1 };
# Count the visible width of a string, excluding any terminal color sequences.
sub visible_width {
local $_ = shift;
my $ret = 0;
while (length) {
if (s/^$COLOR//) {
# skip colors
} elsif (s/^.//) {
$ret++;
}
}
return $ret;
}
# Return a substring of $str, omitting $len visible characters from the
# beginning, where terminal color sequences do not count as visible.
sub visible_substr {
my ($str, $len) = @_;
while ($len > 0) {
if ($str =~ s/^$COLOR//) {
next
}
$str =~ s/^.//;
$len--;
}
return $str;
}
sub handle_line {
my $orig = shift;
local $_ = $orig;
# match a graph line that begins a commit
if (/^(?:$COLOR?\|$COLOR?[ ])* # zero or more leading "|" with space
$COLOR?\*$COLOR?[ ] # a "*" with its trailing space
(?:$COLOR?\|$COLOR?[ ])* # zero or more trailing "|"
[ ]* # trailing whitespace for merges
/x) {
my $graph_prefix = $&;
# We must flush before setting graph indent, since the
# new commit may be indented differently from what we
# queued.
flush();
$graph_indent = visible_width($graph_prefix);
} elsif ($graph_indent) {
if (length($_) < $graph_indent) {
$graph_indent = 0;
} else {
$_ = visible_substr($_, $graph_indent);
}
}
if (!$in_hunk) {
$line_cb->($orig);
$in_hunk = /^$COLOR*\@\@ /;
}
elsif (/^$COLOR*-/) {
push @removed, $orig;
}
elsif (/^$COLOR*\+/) {
push @added, $orig;
}
else {
flush();
$line_cb->($orig);
$in_hunk = /^$COLOR*[\@ ]/;
}
# Most of the time there is enough output to keep things streaming,
# but for something like "git log -Sfoo", you can get one early
# commit and then many seconds of nothing. We want to show
# that one commit as soon as possible.
#
# Since we can receive arbitrary input, there's no optimal
# place to flush. Flushing on a blank line is a heuristic that
# happens to match git-log output.
if (!length) {
$flush_cb->();
}
}
sub flush {
# Flush any queued hunk (this can happen when there is no trailing
# context in the final diff of the input).
show_hunk(\@removed, \@added);
@removed = ();
@added = ();
}
sub highlight_stdin {
while (<STDIN>) {
handle_line($_);
}
flush();
}
# Ideally we would feed the default as a human-readable color to
# git-config as the fallback value. But diff-highlight does
# not otherwise depend on git at all, and there are reports
# of it being used in other settings. Let's handle our own
# fallback, which means we will work even if git can't be run.
sub color_config {
my ($key, $default) = @_;
# Removing the redirect speeds up execution by about 12ms
#my $s = `git config --get-color $key 2>$NULL`;
my $s = `git config --get-color $key`;
return length($s) ? $s : $default;
}
sub show_hunk {
my ($a, $b) = @_;
# If one side is empty, then there is nothing to compare or highlight.
if (!@$a || !@$b) {
$line_cb->(@$a, @$b);
return;
}
# If we have mismatched numbers of lines on each side, we could try to
# be clever and match up similar lines. But for now we are simple and
# stupid, and only handle multi-line hunks that remove and add the same
# number of lines.
if (@$a != @$b) {
$line_cb->(@$a, @$b);
return;
}
my @queue;
for (my $i = 0; $i < @$a; $i++) {
my ($rm, $add) = highlight_pair($a->[$i], $b->[$i]);
$line_cb->($rm);
push @queue, $add;
}
$line_cb->(@queue);
}
sub highlight_pair {
my @a = split_line(shift);
my @b = split_line(shift);
# Find common prefix, taking care to skip any ansi
# color codes.
my $seen_plusminus;
my ($pa, $pb) = (0, 0);
while ($pa < @a && $pb < @b) {
if ($a[$pa] =~ /$COLOR/) {
$pa++;
}
elsif ($b[$pb] =~ /$COLOR/) {
$pb++;
}
elsif ($a[$pa] eq $b[$pb]) {
$pa++;
$pb++;
}
elsif (!$seen_plusminus && $a[$pa] eq '-' && $b[$pb] eq '+') {
$seen_plusminus = 1;
$pa++;
$pb++;
}
else {
last;
}
}
# Find common suffix, ignoring colors.
my ($sa, $sb) = ($#a, $#b);
while ($sa >= $pa && $sb >= $pb) {
if ($a[$sa] =~ /$COLOR/) {
$sa--;
}
elsif ($b[$sb] =~ /$COLOR/) {
$sb--;
}
elsif ($a[$sa] eq $b[$sb]) {
$sa--;
$sb--;
}
else {
last;
}
}
if (is_pair_interesting(\@a, $pa, $sa, \@b, $pb, $sb)) {
return highlight_line(\@a, $pa, $sa, \@OLD_HIGHLIGHT),
highlight_line(\@b, $pb, $sb, \@NEW_HIGHLIGHT);
}
else {
return join('', @a),
join('', @b);
}
}
# we split either by $COLOR or by character. This has the side effect of
# leaving in graph cruft. It works because the graph cruft does not contain "-"
# or "+"
sub split_line {
local $_ = shift;
return utf8::decode($_) ?
map { utf8::encode($_); $_ }
map { /$COLOR/ ? $_ : (split //) }
split /($COLOR+)/ :
map { /$COLOR/ ? $_ : (split //) }
split /($COLOR+)/;
}
sub highlight_line {
my ($line, $prefix, $suffix, $theme) = @_;
my $start = join('', @{$line}[0..($prefix-1)]);
my $mid = join('', @{$line}[$prefix..$suffix]);
my $end = join('', @{$line}[($suffix+1)..$#$line]);
# If we have a "normal" color specified, then take over the whole line.
# Otherwise, we try to just manipulate the highlighted bits.
if (defined $theme->[0]) {
s/$COLOR//g for ($start, $mid, $end);
chomp $end;
return join('',
$theme->[0], $start, $RESET,
$theme->[1], $mid, $RESET,
$theme->[0], $end, $RESET,
"\n"
);
} else {
return join('',
$start,
$theme->[1], $mid, $theme->[2],
$end
);
}
}
# Pairs are interesting to highlight only if we are going to end up
# highlighting a subset (i.e., not the whole line). Otherwise, the highlighting
# is just useless noise. We can detect this by finding either a matching prefix
# or suffix (disregarding boring bits like whitespace and colorization).
sub is_pair_interesting {
my ($a, $pa, $sa, $b, $pb, $sb) = @_;
my $prefix_a = join('', @$a[0..($pa-1)]);
my $prefix_b = join('', @$b[0..($pb-1)]);
my $suffix_a = join('', @$a[($sa+1)..$#$a]);
my $suffix_b = join('', @$b[($sb+1)..$#$b]);
return visible_substr($prefix_a, $graph_indent) !~ /^$COLOR*-$BORING*$/ ||
visible_substr($prefix_b, $graph_indent) !~ /^$COLOR*\+$BORING*$/ ||
$suffix_a !~ /^$BORING*$/ ||
$suffix_b !~ /^$BORING*$/;
}

3
scripts/scripts/cheesecake.sh Executable file
View File

@ -0,0 +1,3 @@
#! /usr/bin/bash
gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled true
gsettings set org.cinnamon.desktop.background.slideshow image-source "directory:///home/andrzej/bgs/chsck/"

4
scripts/scripts/sfw.sh Executable file
View File

@ -0,0 +1,4 @@
#! /usr/bin/bash
gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled true
gsettings set org.cinnamon.desktop.background.slideshow image-source "directory:///home/andrzej/bgs/leics/"

13
scripts/scripts/startup.sh Executable file
View File

@ -0,0 +1,13 @@
#! /usr/bin/bash
# arrange windows
wmctrl -r firefox -t 1
wmctrl -r "Volume Control" -t 3
wmctrl -r tidal -t 3
wmctrl -r tidal -b add,hidden
# /arrange windows
#
git -C ~/writing pull
git -C ~/.dotfiles pull
$HOME/scripts/watch_xscreensaver.pl &

56
scripts/scripts/switch-bg.sh Executable file
View File

@ -0,0 +1,56 @@
#! /bin/bash
bgsDirectory="${HOME}/bgs/"
slideshow() {
gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled ${1}
}
setDirectory() {
gsettings set org.cinnamon.desktop.background.slideshow image-source "directory:///${bgsDirectory}${1}"
}
setImage() {
gsettings set org.cinnamon.desktop.background picture-uri "file:///${1}"
}
toggle(){
slideshowEnabled=$(gsettings get org.cinnamon.desktop.background.slideshow slideshow-enabled)
if $slideshowEnabled; then
slideshow false
setImage "${bgsDirectory}/default.jpg"
else
slideshow true
gsettings set org.cinnamon.desktop.background.slideshow image-source "directory:///${bgsDirectory}chsck/"
fi
}
chooseRandom(){
shopt -s nullglob
files=(${1}*)
length=$((${#files[@]}))
echo "length: ${length}"
randomIndex=$(($RANDOM % $length))
echo "random index: ${randomIndex}"
setImage "${files[$randomIndex]}"
}
slideshowOrRandom(){
if [ "$#" -gt 1 -a "$2" = r ]; then
slideshow false
chooseRandom "${bgsDirectory}${1}"
else
slideshow true
setDirectory ${1}
fi
}
case $1 in
c)
slideshowOrRandom "chsck/" $2
;;
l)
slideshowOrRandom "leics/" $2
;;
a)
slideshowOrRandom "art/" $2
;;
t) toggle
;;
*) slideshow false
setImage "${bgsDirectory}/default.jpg"
;;
esac

View File

@ -0,0 +1 @@
../watch_xscreensaver.pl

38
scripts/watch_screensaver.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
pictureURI="file://${HOME}/bgs/default.jpg"
# Check for existing instances and kill them leaving current instance running
for PID in $(pidof -o %PPID -x "${0##*/}"); do
if [ "$PID" != $$ ]; then
kill -9 "$PID"
fi
done
# set initial status
ACTIVE=false
setDefaultBg() {
gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled false && gsettings set org.cinnamon.desktop.background picture-uri $pictureURI
}
# Start the main loop to monitor screensaver status changes
dbus-monitor --session "interface='org.cinnamon.ScreenSaver', member='ActiveChanged'" | while read -r STATE
do
if ( ! $ACTIVE ); then
echo "$STATE"
if echo "$STATE" | grep -q "boolean true"; then
echo "setting bg"
setDefaultBg
ACTIVE=true
fi
elif echo "$STATE" | grep -q "boolean false"; then
echo "$STATE"
echo "screen unlocked"
ACTIVE=false
fi
sleep 1
done

18
scripts/watch_xscreensaver.pl Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/perl
my $blanked = 0;
open (my $in, "xscreensaver-command -watch |") || die;
while (<$in>) {
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
system ("/home/andrzej/scripts/switch-bg.sh");
$blanked = 1;
}
} elsif (m/^UNBLANK/) {
# system ("sound-on");
$blanked = 0;
}
sleep 3;
}

View File

@ -0,0 +1,13 @@
#!/bin/bash
ACTIVE=false
xscreensaver-command --watch | while read -r STATE
do
if condition; then
command ...
else
command ...
fi
done

18
tmux/.tmux.conf Normal file
View File

@ -0,0 +1,18 @@
set -as terminal-features ",xterm-256color:RGB"
set -g @plugin 'rose-pine/tmux'
set -g @rose_pine_variant 'moon' # Options are 'main', 'moon' or 'dawn'
set -g @rose_pine_directory 'on'
set -g @rose_pine_bar_bg_disable 'on'
set -g @rose_pine_date_time '%a %e %B | %R'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'christoomey/vim-tmux-navigator'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

View File

@ -0,0 +1,2 @@
# Force text files to have unix eols, so Windows/Cygwin does not break them
*.* eol=lf

View File

@ -0,0 +1,43 @@
# Changelog
### master
- remove `detach-on-destroy`
- do not set `aggressive-resize` on iTerm terminal
- disable `detach-on-destroy`
### v3.0.0, 2015-06-24
- remove 'almost sensible' feature
### v2.3.0, 2015-06-24
- update to support \*THE\* latest tmux version
- bugfix for `prefix + R` key binding
- fix for tmux 2.0 `default-terminal` option (thanks @kwbr)
### v2.2.0, 2015-02-10
- bugfix in `key_binding_not_set`: the regex is now properly detecting key
bindings with `-r` flag.
- enable `aggressive-resize`
### v2.1.0, 2014-12-12
- check before binding `prefix + prefix` (@m1foley)
- enable `focus-events`
- deprecate 'almost sensible' feature. The reason for this is to focus the
plugin on doing just one thing.
### v2.0.0, 2014-10-03
- bugfix: prevent exiting tmux if 'reattach-to-user-namespace' is not installed
- remove all mouse-related options
- introduce 'almost sensible' setting and options
### v1.1.0, 2014-08-30
- bugfix: determine the default shell from the $SHELL env var on OS X
- set `mode-mouse on` by default
- do not make any decision about the prefix, just enhance it
- update `README.md`. List options set in the plugin.
- do *not* set `mode-mouse on` by default because some users don't like it
- if a user changes default prefix but binds `C-b` to something else, do not
unbind `C-b`
### v1.0.0, 2014-07-30
- initial work on the plugin
- add readme

View File

@ -0,0 +1,19 @@
Copyright (C) 2014 Bruno Sutic
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,122 @@
# Tmux sensible
A set of tmux options that should be acceptable to everyone.
Inspired by [vim-sensible](https://github.com/tpope/vim-sensible).
Tested and working on Linux, OSX and Cygwin.
### Principles
- `tmux-sensible` options should be acceptable to **every** tmux user!<br/>
If any of the options bothers you, please open an issue and it will probably
be updated (or removed).
- if you think a new option should be added, feel free to open a pull request.
- **no overriding** of user defined settings.<br/>
Your existing `.tmux.conf` settings are respected and they won't be changed.
That way you can use `tmux-sensible` if you have a few specific options.
### Goals
- group standard tmux community options in one place
- remove clutter from your `.tmux.conf`
- educate new tmux users about basic options
### Options
```tmux
# Address vim mode switching delay (http://superuser.com/a/252717/65504)
set -s escape-time 0
# Increase scrollback buffer size from 2000 to 50000 lines
set -g history-limit 50000
# Increase tmux messages display duration from 750ms to 4s
set -g display-time 4000
# Refresh 'status-left' and 'status-right' more often, from every 15s to 5s
set -g status-interval 5
# (OS X) Fix pbcopy/pbpaste for old tmux versions (pre 2.6)
set -g default-command "reattach-to-user-namespace -l $SHELL"
# Upgrade $TERM
set -g default-terminal "screen-256color"
# Emacs key bindings in tmux command prompt (prefix + :) are better than
# vi keys, even for vim users
set -g status-keys emacs
# Focus events enabled for terminals that support them
set -g focus-events on
# Super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on
```
### Key bindings
```tmux
# Easier and faster switching between next/prev window
bind C-p previous-window
bind C-n next-window
```
Above bindings enhance the default `prefix + p` and `prefix + n` bindings by
allowing you to hold `Ctrl` and repeat `a + p`/`a + n` (if your prefix is
`C-a`), which is a lot quicker.
```tmux
# Source .tmux.conf as suggested in `man tmux`
bind R source-file '~/.tmux.conf'
```
"Adaptable" key bindings that build upon your `prefix` value:
```tmux
# If prefix is 'C-a'
bind C-a send-prefix
bind a last-window
```
If prefix is `C-b`, above keys will be `C-b` and `b`.<br/>
If prefix is `C-z`, above keys will be `C-z` and `z`... you get the idea.
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Add plugin to the list of TPM plugins in `.tmux.conf`:
```tmux
set -g @plugin 'tmux-plugins/tmux-sensible'
```
Hit `prefix + I` to fetch the plugin and source it. That's it!
### Manual Installation
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-sensible ~/clone/path
Add this line to the bottom of `.tmux.conf`:
```tmux
run-shell ~/clone/path/sensible.tmux
```
Reload TMUX environment with `$ tmux source-file ~/.tmux.conf`, and that's it.
### Other goodies
You might also find these useful:
- [copycat](https://github.com/tmux-plugins/tmux-copycat)
improve tmux search and reduce mouse usage
- [pain control](https://github.com/tmux-plugins/tmux-pain-control)
useful standard bindings for controlling panes
- [resurrect](https://github.com/tmux-plugins/tmux-resurrect)
persists tmux environment across system restarts
### License
[MIT](LICENSE.md)

View File

@ -0,0 +1,168 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# used to match output from `tmux list-keys`
KEY_BINDING_REGEX="bind-key[[:space:]]\+\(-r[[:space:]]\+\)\?\(-T prefix[[:space:]]\+\)\?"
is_osx() {
local platform=$(uname)
[ "$platform" == "Darwin" ]
}
iterm_terminal() {
[[ "${TERM_PROGRAM}" =~ ^iTerm || "${LC_TERMINAL}" =~ ^iTerm ]]
}
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1
}
# returns prefix key, e.g. 'C-a'
prefix() {
tmux show-option -gv prefix
}
# if prefix is 'C-a', this function returns 'a'
prefix_without_ctrl() {
local prefix="$(prefix)"
echo "$prefix" | cut -d '-' -f2
}
option_value_not_changed() {
local option="$1"
local default_value="$2"
local option_value=$(tmux show-option -gv "$option")
[ "$option_value" == "$default_value" ]
}
server_option_value_not_changed() {
local option="$1"
local default_value="$2"
local option_value=$(tmux show-option -sv "$option")
[ "$option_value" == "$default_value" ]
}
key_binding_not_set() {
local key="${1//\\/\\\\}"
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then
return 1
else
return 0
fi
}
key_binding_not_changed() {
local key="$1"
local default_value="$2"
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
# key still has the default binding
return 0
else
return 1
fi
}
get_tmux_config() {
local tmux_config_xdg="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
local tmux_config="$HOME/.tmux.conf"
if [ -f "${tmux_config_xdg}" ]; then
echo "${tmux_config_xdg}"
else
echo ${tmux_config}
fi
}
main() {
# OPTIONS
# address vim mode switching delay (http://superuser.com/a/252717/65504)
if server_option_value_not_changed "escape-time" "500"; then
tmux set-option -s escape-time 0
fi
# increase scrollback buffer size
if option_value_not_changed "history-limit" "2000"; then
tmux set-option -g history-limit 50000
fi
# tmux messages are displayed for 4 seconds
if option_value_not_changed "display-time" "750"; then
tmux set-option -g display-time 4000
fi
# refresh 'status-left' and 'status-right' more often
if option_value_not_changed "status-interval" "15"; then
tmux set-option -g status-interval 5
fi
# required (only) on OS X
if is_osx && command_exists "reattach-to-user-namespace" && option_value_not_changed "default-command" ""; then
tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL"
fi
# upgrade $TERM, tmux 1.9
if option_value_not_changed "default-terminal" "screen"; then
tmux set-option -g default-terminal "screen-256color"
fi
# upgrade $TERM, tmux 2.0+
if server_option_value_not_changed "default-terminal" "screen"; then
tmux set-option -s default-terminal "screen-256color"
fi
# emacs key bindings in tmux command prompt (prefix + :) are better than
# vi keys, even for vim users
tmux set-option -g status-keys emacs
# focus events enabled for terminals that support them
tmux set-option -g focus-events on
# super useful when using "grouped sessions" and multi-monitor setup
if ! iterm_terminal; then
tmux set-window-option -g aggressive-resize on
fi
# DEFAULT KEY BINDINGS
local prefix="$(prefix)"
local prefix_without_ctrl="$(prefix_without_ctrl)"
# if C-b is not prefix
if [ $prefix != "C-b" ]; then
# unbind obsolete default binding
if key_binding_not_changed "C-b" "send-prefix"; then
tmux unbind-key C-b
fi
# pressing `prefix + prefix` sends <prefix> to the shell
if key_binding_not_set "$prefix"; then
tmux bind-key "$prefix" send-prefix
fi
fi
# If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows.
# Works for any prefix character.
if key_binding_not_set "$prefix_without_ctrl"; then
tmux bind-key "$prefix_without_ctrl" last-window
fi
# easier switching between next/prev window
if key_binding_not_set "C-p"; then
tmux bind-key C-p previous-window
fi
if key_binding_not_set "C-n"; then
tmux bind-key C-n next-window
fi
# source `.tmux.conf` file - as suggested in `man tmux`
if key_binding_not_set "R"; then
local tmux_config=$(get_tmux_config)
tmux bind-key R run-shell " \
tmux source-file ${tmux_config} > /dev/null; \
tmux display-message 'Sourced ${tmux_config}!'"
fi
}
main

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Rosé Pine
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,124 @@
<p align="center">
<img src="https://github.com/rose-pine/rose-pine-theme/raw/main/assets/icon.png" width="80" />
<h2 align="center">Rosé Pine for tmux</h2>
</p>
<p align="center">All natural pine, faux fur and a bit of soho vibes for the classy minimalist</p>
<p align="center">
<a href="https://github.com/rose-pine/rose-pine-theme">
<img src="https://img.shields.io/badge/community-rosé%20pine-26233a?labelColor=191724&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjUwIiBoZWlnaHQ9IjIzNyIgdmlld0JveD0iMCAwIDI1MCAyMzciIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xNjEuMjI3IDE2MS4yNTFDMTMyLjE1NCAxNjkuMDQxIDExNC45MDEgMTk4LjkyNCAxMjIuNjkxIDIyNy45OTdDMTIzLjkyNSAyMzIuNjAzIDEyOC42NTkgMjM1LjMzNiAxMzMuMjY0IDIzNC4xMDJMMTg1LjkwNyAyMTkuOTk2QzIxOS41ODUgMjEwLjk3MiAyMzkuNTcgMTc2LjM1NCAyMzAuNTQ2IDE0Mi42NzdMMTYxLjIyNyAxNjEuMjUxWiIgZmlsbD0iIzI0NjI3QiIvPgo8cGF0aCBkPSJNODguMTgzNiAxNTkuOTg4QzExNy4yNTcgMTY3Ljc3OCAxMzQuNTEgMTk3LjY2MiAxMjYuNzIgMjI2LjczNUMxMjUuNDg2IDIzMS4zNCAxMjAuNzUyIDIzNC4wNzMgMTE2LjE0NyAyMzIuODM5TDYzLjUwNDEgMjE4LjczM0MyOS44MjY0IDIwOS43MSA5Ljg0MDk0IDE3NS4wOTIgMTguODY0OSAxNDEuNDE0TDg4LjE4MzYgMTU5Ljk4OFoiIGZpbGw9IiMyNDYyN0IiLz4KPHBhdGggZD0iTTE4Ni44NjcgMTcyLjk4QzE1Mi4wMDIgMTcyLjk4IDEyMy43MzcgMjAxLjI0NSAxMjMuNzM3IDIzNi4xMTFIMTg2Ljg3QzIyMS43MzYgMjM2LjExMSAyNTAgMjA3Ljg0NiAyNTAgMTcyLjk4TDE4Ni44NjcgMTcyLjk4WiIgZmlsbD0iIzMxNzQ4RiIvPgo8cGF0aCBkPSJNNjMuMTMyNyAxNzIuOThDOTcuOTk4NCAxNzIuOTggMTI2LjI2MyAyMDEuMjQ1IDEyNi4yNjMgMjM2LjExMUg2My4xM0MyOC4yNjQyIDIzNi4xMTEgLTEuNTI0MDNlLTA2IDIwNy44NDYgMCAxNzIuOThMNjMuMTMyNyAxNzIuOThaIiBmaWxsPSIjMzE3NDhGIi8+CjxwYXRoIGQ9Ik0xNzEuNzE3IDc1LjEyNjNDMTcxLjcxNyAxMDEuMjc2IDE1MC41MTggMTIyLjQ3NSAxMjQuMzY5IDEyMi40NzVDOTguMjE4OCAxMjIuNDc1IDc3LjAyMDIgMTAxLjI3NiA3Ny4wMjAyIDc1LjEyNjNDNzcuMDIwMiA0OC45NzY0IDk4LjIxODggMjcuNzc3OCAxMjQuMzY5IDI3Ljc3NzhDMTUwLjUxOCAyNy43Nzc4IDE3MS43MTcgNDguOTc2NCAxNzEuNzE3IDc1LjEyNjNaIiBmaWxsPSIjRUJCQ0JBIi8+CjxwYXRoIGQ9Ik0xNDQuMjE3IDg2LjIzNzlDMTYxLjY0OSA1Ni4wNDMyIDE1MS4zMDMgMTcuNDMyOSAxMjEuMTA4IDBMMTA2LjA2IDI2LjA2NDRDODguNjI3IDU2LjI1OSA5OC45NzM2IDk0Ljg2OTQgMTI5LjE2OCAxMTIuMzAyTDE0NC4yMTcgODYuMjM3OVoiIGZpbGw9IiNFQkJDQkEiLz4KPHBhdGggZD0iTTEyNS4yOTkgNjAuOTc4OUMxMTYuMjc1IDI3LjMwMTIgODEuNjU3NSA3LjMxNTY3IDQ3Ljk3OTcgMTYuMzM5Nkw2NC4zMTk3IDc3LjMyMTFDNzMuMzQzNiAxMTAuOTk5IDEwNy45NjEgMTMwLjk4NCAxNDEuNjM5IDEyMS45NkwxMjUuMjk5IDYwLjk3ODlaIiBmaWxsPSIjRUJCQ0JBIi8+CjxwYXRoIGQ9Ik0xMjQuOTI2IDYwLjk3ODlDMTMzLjk1IDI3LjMwMTIgMTY4LjU2NyA3LjMxNTY3IDIwMi4yNDUgMTYuMzM5NkwxODUuOTA1IDc3LjMyMTFDMTc2Ljg4MSAxMTAuOTk5IDE0Mi4yNjMgMTMwLjk4NCAxMDguNTg2IDEyMS45NkwxMjQuOTI2IDYwLjk3ODlaIiBmaWxsPSIjRUJCQ0JBIi8+Cjwvc3ZnPgo=&style=for-the-badge" />
</a>
</p>
## Usage
> NOTE: It uses a [Nerdfont](https://www.nerdfonts.com/font-downloads) by default for the icons, so it is recommended to have a Nerdfont set as your terminal font
1. Install [TPM](https://github.com/tmux-plugins/tpm)
<br>
2. Add the Rosé Pine plugin with the following lines:
```bash
set -g @plugin 'rose-pine/tmux'
# ... alongside
set -g @plugin 'tmux-plugins/tpm'
# To update plugin for future revisions or bug fixes, do the "Prefix + U" keycombo
```
<br>
3. Set your preferred variant:
```bash
set -g @rose_pine_variant 'main' # Options are 'main', 'moon' or 'dawn'
```
<br>
4. After adding TPM and the Rosé Pine theme to `.tmux.conf`, restart tmux and use the <kbd>Prefix + I</kbd> (capital I) combo to source your configuration.
For updating the plugin, the key combination is <kbd>Prefix + U</kbd> (which TPM sets by default).
<br>
5. Optional but recommended: Activate the extra modules, they are enabled by writing 'on' after the option name
```bash
set -g @rose_pine_host 'on' # Enables hostname in the status bar
set -g @rose_pine_date_time '' # It accepts the date UNIX command format (man date for info)
set -g @rose_pine_user 'on' # Turn on the username component in the statusbar
set -g @rose_pine_directory 'on' # Turn on the current folder component in the status bar
set -g @rose_pine_bar_bg_disable 'on' # Disables background color, for transparent terminal emulators
# If @rose_pine_bar_bg_disable is set to 'on', uses the provided value to set the background color
# It can be any of the on tmux (named colors, 256-color set, `default` or hex colors)
# See more on http://man.openbsd.org/OpenBSD-current/man1/tmux.1#STYLES
set -g @rose_pine_bar_bg_disabled_color_option 'default'
set -g @rose_pine_only_windows 'on' # Leaves only the window module, for max focus and space
set -g @rose_pine_disable_active_window_menu 'on' # Disables the menu that shows the active window on the left
set -g @rose_pine_default_window_behavior 'on' # Forces tmux default window list behaviour
set -g @rose_pine_show_current_program 'on' # Forces tmux to show the current running program as window name
set -g @rose_pine_show_pane_directory 'on' # Forces tmux to show the current directory as window name
# Previously set -g @rose_pine_window_tabs_enabled
# Example values for these can be:
set -g @rose_pine_left_separator ' > ' # The strings to use as separators are 1-space padded
set -g @rose_pine_right_separator ' < ' # Accepts both normal chars & nerdfont icons
set -g @rose_pine_field_separator ' | ' # Again, 1-space padding, it updates with prefix + I
set -g @rose_pine_window_separator ' - ' # Replaces the default `:` between the window number and name
# These are not padded
set -g @rose_pine_session_icon '' # Changes the default icon to the left of the session name
set -g @rose_pine_current_window_icon '' # Changes the default icon to the left of the active window name
set -g @rose_pine_folder_icon '' # Changes the default icon to the left of the current directory folder
set -g @rose_pine_username_icon '' # Changes the default icon to the right of the hostname
set -g @rose_pine_hostname_icon '󰒋' # Changes the default icon to the right of the hostname
set -g @rose_pine_date_time_icon '󰃰' # Changes the default icon to the right of the date module
set -g @rose_pine_window_status_separator "  " # Changes the default icon that appears between window names
# Very beta and specific opt-in settings, tested on v3.2a, look at issue #10
set -g @rose_pine_prioritize_windows 'on' # Disables the right side functionality in a certain window count / terminal width
set -g @rose_pine_width_to_hide '80' # Specify a terminal width to toggle off most of the right side functionality
set -g @rose_pine_window_count '5' # Specify a number of windows, if there are more than the number, do the same as width_to_hide
```
- The separator options should go back to the defaults ( →, ← and | NerdFont characters) if the options are unset and you close all tmux sessions (a full restart)
- The `@rose_pine_width_to_hide` and `rose_pine_window_count` settings do not refresh automatically. They need to be refreshed manually, their current state is discussed [here](https://github.com/rose-pine/tmux/issues/10).
- For `@rose_pine_window_tabs_enabled` and any further naming changes / notices, see issue #14.
<br>
6. Integration with other status-bar plugins
- You can add, for example, the [tmux-mode-indicator](https://github.com/MunifTanjim/tmux-mode-indicator) plugin:
```bash
# Add to the beginning / end of the left and right sections your own.
set -g @rose_pine_status_left_prepend_section '#{tmux_mode_indicator}'
set -g @rose_pine_status_left_append_section 'It works'
set -g @rose_pine_status_right_prepend_section 'with normal text'
set -g @rose_pine_status_right_append_section 'too'
```
> This plugin is being developed and tested on tmux v3.2a on Pop_OS! (Ubuntu). If there are problems with other versions, do let me know.
## Gallery
- Main
![image](https://github.com/rose-pine/tmux/assets/121260905/184514d9-08fe-453b-a664-3cd6ccab0d4a)
- Moon
![image](https://github.com/rose-pine/tmux/assets/121260905/e2665eb6-280b-48a2-ab45-163d2eb21050)
- Dawn
![image](https://github.com/rose-pine/tmux/assets/121260905/b194e552-cb15-4296-b459-e1da521aad8c)
## Thanks to
- [MrSandman](https://github.com/mrs4ndman)
- [Catppuccin for tmux](https://github.com/catppuccin/tmux) ([license](https://github.com/catppuccin/tmux/blob/4e48b09a76829edc7b55fbb15467cf0411f07931/LICENSE))
- [mcanueste](https://github.com/mcanueste/rose-pine-tmux) ([license](https://github.com/mcanueste/rose-pine-tmux/blob/715de6925992ab9f7162fcfefc1d3ba1510d187a/LICENSE))

View File

@ -0,0 +1,469 @@
#!/usr/bin/env bash
#
# Rosé Pine - tmux theme
#
# Almost done, any bug found file a PR to rose-pine/tmux
#
# Inspired by dracula/tmux, catppucin/tmux & challenger-deep-theme/tmux
#
#
export TMUX_ROSEPINE_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
get_tmux_option() {
local option value default
option="$1"
default="$2"
value="$(tmux show-option -gqv "$option")"
if [ -n "$value" ]; then
echo "$value"
else
echo "$default"
fi
}
set() {
local option=$1
local value=$2
tmux_commands+=(set-option -gq "$option" "$value" ";")
}
setw() {
local option=$1
local value=$2
tmux_commands+=(set-window-option -gq "$option" "$value" ";")
}
unset_option() {
local option=$1
local value=$2
tmux_commands+=(set-option -gu "$option" ";")
}
main() {
local theme
theme="$(get_tmux_option "@rose_pine_variant" "")"
# INFO: Not removing the thm_hl_low and thm_hl_med colors for posible features
# INFO: If some variables appear unused, they are being used either externally
# or in the plugin's features
if [[ $theme == main ]]; then
thm_base="#191724";
thm_surface="#1f1d2e";
thm_overlay="#26233a";
thm_muted="#6e6a86";
thm_subtle="#908caa";
thm_text="#e0def4";
thm_love="#eb6f92";
thm_gold="#f6c177";
thm_rose="#ebbcba";
thm_pine="#31748f";
thm_foam="#9ccfd8";
thm_iris="#c4a7e7";
thm_hl_low="#21202e";
thm_hl_med="#403d52";
thm_hl_high="#524f67";
elif [[ $theme == dawn ]]; then
thm_base="#faf4ed";
thm_surface="#fffaf3";
thm_overlay="#f2e9e1";
thm_muted="#9893a5";
thm_subtle="#797593";
thm_text="#575279";
thm_love="#b4367a";
thm_gold="#ea9d34";
thm_rose="#d7827e";
thm_pine="#286983";
thm_foam="#56949f";
thm_iris="#907aa9";
thm_hl_low="#f4ede8";
thm_hl_med="#dfdad9";
thm_hl_high="#cecacd";
elif [[ $theme == moon ]]; then
thm_base="#232136";
thm_surface="#2a273f";
thm_overlay="#393552";
thm_muted="#6e6a86";
thm_subtle="#908caa";
thm_text="#e0def4";
thm_love="#eb6f92";
thm_gold="#f6c177";
thm_rose="#ea9a97";
thm_pine="#3e8fb0";
thm_foam="#9ccfd8";
thm_iris="#c4a7e7";
thm_hl_low="#2a283e";
thm_hl_med="#44415a";
thm_hl_high="#56526e";
fi
# Aggregating all commands into a single array
local tmux_commands=()
# Status bar
set "status" "on"
set status-style "fg=$thm_pine,bg=$thm_base"
# set monitor-activity "on"
# Leave justify option to user
# set status-justify "left"
set status-left-length "200"
set status-right-length "200"
# Theoretically messages (need to figure out color placement)
set message-style "fg=$thm_muted,bg=$thm_base"
set message-command-style "fg=$thm_base,bg=$thm_gold"
# Pane styling
set pane-border-style "fg=$thm_hl_high"
set pane-active-border-style "fg=$thm_gold"
set display-panes-active-colour "${thm_text}"
set display-panes-colour "${thm_gold}"
# Windows
setw window-status-style "fg=${thm_iris},bg=${thm_base}"
setw window-status-activity-style "fg=${thm_base},bg=${thm_rose}"
setw window-status-current-style "fg=${thm_gold},bg=${thm_base}"
# Statusline base command configuration: No need to touch anything here
# Placement is handled below
# Shows username of the user the tmux session is run by
local user
user="$(get_tmux_option "@rose_pine_user" "")"
readonly user
# Shows hostname of the computer the tmux session is run on
local host
host="$(get_tmux_option "@rose_pine_host" "")"
readonly host
# Date and time command: follows the date UNIX command structure
local date_time
date_time="$(get_tmux_option "@rose_pine_date_time" "")"
readonly date_time
# Shows truncated current working directory
local directory
directory="$(get_tmux_option "@rose_pine_directory" "")"
local disable_active_window_menu
disable_active_window_menu="$(get_tmux_option "@rose_pine_disable_active_window_menu" "")"
local show_current_program
show_current_program="$(get_tmux_option "@rose_pine_show_current_program" "")"
readonly show_current_program
local window_directory
window_directory="$(get_tmux_option "@rose_pine_show_pane_directory" "")"
readonly window_directory
local window_separator
window_separator="$(get_tmux_option "@rose_pine_window_separator" "")"
readonly window_separator
local default_window_behavior
default_window_behavior="$(get_tmux_option "@rose_pine_default_window_behavior" "")"
readonly default_window_behavior
# Changes the background color for the current active window
# TODO: Together with line 251-269, end development for this feature
# local active_window_color
# active_window_color="$(get_tmux_option "@rose_pine_active_window_color" "")"
# readonly active_window_color
# Transparency enabling for status bar
local bar_bg_disable
bar_bg_disable="$(get_tmux_option "@rose_pine_bar_bg_disable" "")"
readonly bar_bg_disable
# Transparent option for status bar
local bar_bg_disabled_color_option
bar_bg_disabled_color_option="$(get_tmux_option "@rose_pine_bar_bg_disabled_color_option" "0")"
readonly bar_bg_disabled_color_option
# Shows hostname of the computer the tmux session is run on
local only_windows
only_windows="$(get_tmux_option "@rose_pine_only_windows" "")"
readonly only_windows
# Allows user to set a few custom sections (for integration with other plugins)
# Before the plugin's left section
local status_left_prepend_section
status_left_prepend_section="$(get_tmux_option "@rose_pine_status_left_prepend_section" "")"
readonly status_left_prepend_section
#
# after the plugin's left section
local status_left_append_section
status_left_append_section="$(get_tmux_option "@rose_pine_status_left_append_section" "")"
readonly status_left_append_section
# Before the plugin's right section
local status_right_prepend_section
status_right_prepend_section="$(get_tmux_option "@rose_pine_status_right_prepend_section" "")"
readonly status_right_prepend_section
#
# after the plugin's right section
local status_right_append_section
status_right_append_section="$(get_tmux_option "@rose_pine_status_right_append_section" "")"
readonly status_right_append_section
# Settings that allow user to choose their own icons and status bar behaviour
# START
local current_window_icon
current_window_icon="$(get_tmux_option "@rose_pine_current_window_icon" "")"
readonly current_window_icon
local current_session_icon
current_session_icon="$(get_tmux_option "@rose_pine_session_icon" "")"
readonly current_session_icon
local username_icon
username_icon="$(get_tmux_option "@rose_pine_username_icon" "")"
readonly username_icon
local hostname_icon
hostname_icon="$(get_tmux_option "@rose_pine_hostname_icon" "󰒋")"
readonly hostname_icon
local date_time_icon
date_time_icon="$(get_tmux_option "@rose_pine_date_time_icon" "󰃰")"
readonly date_time_icon
local current_folder_icon
current_folder_icon="$(get_tmux_option "@rose_pine_folder_icon" "")"
readonly current_folder_icon
# Changes the icon / character that goes between each window's name in the bar
local window_status_separator
window_status_separator="$(get_tmux_option "@rose_pine_window_status_separator" "  ")"
# This setting does nothing by itself, it enables the 2 below it to toggle the simplified bar
local prioritize_windows
prioritize_windows="$(get_tmux_option "@rose_pine_prioritize_windows" "")"
# Allows the user to set a min width at which most of the bar elements hide, or
local user_window_width
user_window_width="$(get_tmux_option "@rose_pine_width_to_hide" "")"
# A number of windows, when over it, the bar gets simplified
local user_window_count
user_window_count="$(get_tmux_option "@rose_pine_window_count" "")"
# Custom window status that goes between the number and the window name
local custom_window_sep="#[fg=$thm_iris]#I#[fg=$thm_iris,]$window_separator#[fg=$thm_iris]#W"
local custom_window_sep_current="#I#[fg=$thm_gold,bg=""]$window_separator#[fg=$thm_gold,bg=""]#W"
local right_separator
right_separator="$(get_tmux_option "@rose_pine_right_separator" "  ")"
local left_separator
left_separator="$(get_tmux_option "@rose_pine_left_separator" "  ")"
local field_separator
# NOTE: Don't remove
field_separator="$(get_tmux_option "@rose_pine_field_separator" " | " )"
# END
local spacer
spacer=" "
# I know, stupid, right? For some reason, spaces aren't consistent
# These variables are the defaults so that the setw and set calls are easier to parse
local show_window
readonly show_window=" #[fg=$thm_subtle]$current_window_icon #[fg=$thm_rose]#W$spacer"
local show_window_in_window_status
show_window_in_window_status="#[fg=$thm_iris]#I#[fg=$thm_iris,]$left_separator#[fg=$thm_iris]#W"
local show_window_in_window_status_current
show_window_in_window_status_current="#I#[fg=$thm_gold,bg=""]$left_separator#[fg=$thm_gold,bg=""]#W"
local show_session
readonly show_session=" #[fg=$thm_text]$current_session_icon #[fg=$thm_text]#S "
local show_user
readonly show_user="#[fg=$thm_iris]#(whoami)#[fg=$thm_subtle]$right_separator#[fg=$thm_subtle]$username_icon"
local show_host
readonly show_host="$spacer#[fg=$thm_text]#H#[fg=$thm_subtle]$right_separator#[fg=$thm_subtle]$hostname_icon"
local show_date_time
readonly show_date_time=" #[fg=$thm_foam]$date_time#[fg=$thm_subtle]$right_separator#[fg=$thm_subtle]$date_time_icon "
local show_directory
readonly show_directory="$spacer#[fg=$thm_subtle]$current_folder_icon #[fg=$thm_rose]#{b:pane_current_path} "
local show_directory_in_window_status
# BUG: It doesn't let the user pass through a custom window name
show_directory_in_window_status="#I$left_separator#[fg=$thm_gold,bg=""]#{b:pane_current_path}"
local show_directory_in_window_status_current
show_directory_in_window_status_current="#I$left_separator#[fg=$thm_gold,bg=""]#{b:pane_current_path}"
# TODO: This needs some work and testing, rn I can't figure it out
# if [[ "$active_window_color" == "love" ]]; then
# show_window_in_window_status_current="#[bg=$thm_love,bg=$thm_base]#I$left_separator#W"
# fi
# if [[ "$active_window_color" == "gold" ]]; then
# show_window_in_window_status_current="#[bg=$thm_gold,bg=$thm_base]#I$left_separator#W"
# fi
# if [[ "$active_window_color" == "rose" ]]; then
# show_window_in_window_status_current="#bg=$thm_rose,bg=$thm_base#I$left_separator#W"
# fi
# if [[ "$active_window_color" == "pine" ]]; then
# show_window_in_window_status_current="#[bg=$thm_pine,bg=$thm_base]#I$left_separator#W"
# fi
# if [[ "$active_window_color" == "foam" ]]; then
# show_window_in_window_status_current="#[bg=$thm_foam,bg=$thm_base]#I$left_separator#W"
# fi
# if [[ "$active_window_color" == "iris" ]]; then
# show_window_in_window_status_current="#[bg=$thm_iris,bg=$thm_base]#I$left_separator#W"
# fi
# Left status: Now moved to a variable called left_column
# (we can append / prepend things to it)
local left_column
# Right status and organization:
# Right status shows nothing by default
local right_column
# This if statement allows the bg colors to be null if the user decides so
# It sets the base colors for active / inactive, no matter the window appearence switcher choice
# TEST: This needs to be tested further
if [[ "$bar_bg_disable" == "on" ]]; then
set status-style "fg=$thm_pine,bg=$bar_bg_disabled_color_option"
show_window_in_window_status="#[fg=$thm_iris,bg=$bar_bg_disabled_color_option]#I#[fg=$thm_iris,bg=$bar_bg_disabled_color_option]$left_separator#[fg=$thm_iris,bg=$bar_bg_disabled_color_option]#W"
show_window_in_window_status_current="#[fg=$thm_gold,bg=$bar_bg_disabled_color_option]#I#[fg=$thm_gold,bg=$bar_bg_disabled_color_option]$left_separator#[fg=$thm_gold,bg=$bar_bg_disabled_color_option]#W"
show_directory_in_window_status="#[fg=$thm_iris,bg=$bar_bg_disabled_color_option]#I#[fg=$thm_iris,bg=$bar_bg_disabled_color_option]$left_separator#[fg=$thm_iris,bg=$bar_bg_disabled_color_option]#{b:pane_current_path}"
show_directory_in_window_status_current="#[fg=$thm_gold,bg=$bar_bg_disabled_color_option]#I#[fg=$thm_gold,bg=$bar_bg_disabled_color_option]$left_separator#[fg=$thm_gold,bg=$bar_bg_disabled_color_option]#{b:pane_current_path}"
set window-status-style "fg=$thm_iris,bg=$bar_bg_disabled_color_option"
set window-status-current-style "fg=$thm_gold,bg=$bar_bg_disabled_color_option"
set window-status-activity-style "fg=$thm_rose,bg=$bar_bg_disabled_color_option"
set message-style "fg=$thm_muted,bg=$bar_bg_disabled_color_option"
fi
# Window appearence switcher: 3 options for the user
if [[ "$window_separator" != "" ]] ; then
window_status_format=$custom_window_sep
window_status_current_format=$custom_window_sep_current
setw window-status-format "$window_status_format"
setw window-status-current-format "$window_status_current_format"
elif [[ "$show_current_program" == "on" ]]; then
window_status_format=$show_window_in_window_status
window_status_current_format=$show_window_in_window_status_current
setw window-status-format "$window_status_format"
setw window-status-current-format "$window_status_current_format"
# See line 268
elif [[ "$window_directory" ]]; then
local window_status_format=$show_directory_in_window_status
local window_status_current_format=$show_directory_in_window_status_current
setw window-status-format "$window_status_format"
setw window-status-current-format "$window_status_current_format"
#
# Base behaviour, but whit cool colors
elif [[ "$default_window_behavior" == "on" || "$default_window_behavior" == "" ]]; then
unset_option window-status-format
unset_option window-status-current-format
fi
if [[ "$user" == "on" ]]; then
right_column=$right_column$show_user
fi
if [[ "$host" == "on" ]]; then
right_column=$right_column$show_host
fi
if [[ "$date_time" != "" ]]; then
right_column=$right_column$show_date_time
fi
if [[ "$directory" == "on" ]]; then
right_column=$right_column$show_directory
fi
# The append and prepend sections are for inter-plugin compatibility
# and extension
if [[ "$disable_active_window_menu" == "on" ]]; then
left_column=$show_session
else
left_column=$show_session$show_window
fi
#
# Appending / Prepending custom user sections to
if [[ "$status_left_prepend_section" != "" ]]; then
left_column=$status_left_prepend_section$left_column
fi
if [[ "$status_left_append_section" != "" ]]; then
left_column=$left_column$status_left_append_section$spacer
fi
if [[ "$status_right_prepend_section" != "" ]]; then
right_column=$status_right_prepend_section$right_column
fi
if [[ "$status_right_append_section" != "" ]]; then
right_column=$right_column$status_right_append_section
fi
# We set the sections
set status-left "$left_column"
set status-right "$right_column"
# Variable logic for the window prioritization
local current_window_count
local current_window_width
current_window_count=$(tmux list-windows | wc -l)
current_window_width=$(tmux display -p "#{window_width}")
# NOTE: Can possibly integrate the $only_windows mode into this
if [[ "$prioritize_windows" == "on" ]]; then
if [[ "$current_window_count" -gt "$user_window_count" || "$current_window_width" -lt "$user_window_width" ]]; then
set status-left "$left_column$show_directory"
# set status-right "$show_directory"
set status-right ""
fi
else
set status-right "$right_column"
fi
# Defaults to a NerdFont icon, user can change through an option
if [[ "$window_status_separator" != "  " ]]; then
setw window-status-separator "$window_status_separator"
else
setw window-status-separator "  "
fi
# Leaves only the window list on the left side
if [[ "$only_windows" == "on" ]]; then
set status-left ""
set status-right ""
fi
# NOTE: Dont remove this, it can be useful for references
# setw window-status-format "$window_status_format"
# setw window-status-current-format "$window_status_current_format"
# tmux integrated modes
setw clock-mode-colour "${thm_love}"
setw mode-style "fg=${thm_gold}"
# Call everything to action
tmux "${tmux_commands[@]}"
}
main "$@"

9
tmux/.tmux/plugins/tpm/.gitattributes vendored Normal file
View File

@ -0,0 +1,9 @@
# Force text files to have unix eols, so Windows/Cygwin does not break them
*.* eol=lf
# These files are unfortunately not recognized as text files so
# explicitly listing them here
tpm eol=lf
bin/* eol=lf
bindings/* eol=lf
tests/* eol=lf

4
tmux/.tmux/plugins/tpm/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
**/.vagrant/
run_tests
tests/run_tests_in_isolation
tests/helpers/helpers.sh

3
tmux/.tmux/plugins/tpm/.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/tmux-test"]
path = lib/tmux-test
url = https://github.com/tmux-plugins/tmux-test.git

View File

@ -0,0 +1,19 @@
# generic packages and tmux
before_install:
- sudo apt-get update
- sudo apt-get install -y git-core expect
- sudo apt-get install -y python-software-properties software-properties-common
- sudo apt-get install -y libevent-dev libncurses-dev
- git clone https://github.com/tmux/tmux.git
- cd tmux
- git checkout 2.0
- sh autogen.sh
- ./configure && make && sudo make install
install:
- git fetch --unshallow --recurse-submodules || git fetch --recurse-submodules
# manual `git clone` required for testing `tmux-test` plugin itself
- git clone https://github.com/tmux-plugins/tmux-test lib/tmux-test; true
- lib/tmux-test/setup
script: ./tests/run_tests_in_isolation

View File

@ -0,0 +1,86 @@
# Changelog
### master
### v3.1.0, 2023-01-03
- upgrade to new version of `tmux-test`
- bug: when using `emacs` copy mode, Enter does not quit screen after tpm
installation/update. Fix by making `Escape` the key for emacs mode.
- add a doc with troubleshooting instructions
- add `.gitattributes` file that forces linefeed characters (classic `\n`) as
line endings - helps with misconfigured git on windows/cygwin
- readme update: announce Cygwin support
- un-deprecate old plugin definition syntax: `set -g @tpm_plugins`
- More stuff, check `git log`.
### v3.0.0, 2015-08-03
- refactor `shared_set_tpm_path_constant` function
- move all instructions to `docs/` dir
- add `bin/install_plugins` cli executable script
- improved test runner function
- switch to using [tmux-test](https://github.com/tmux-plugins/tmux-test)
framework
- add `bin/update_plugins` cli executable script
- refactor test `expect` scripts, make them simpler and ensure they properly
assert expectations
- refactor code that sets 'TMUX_PLUGIN_MANAGER_PATH' global env var
- stop using global variable for 'tpm path'
- support defining plugins via `set -g @plugin` in sourced files as well
### v2.0.0, 2015-07-07
- enable overriding default key bindings
- start using `C-c` to clear screen
- add uninstall/clean procedure and keybinding (prefix+alt+u) (@chilicuil)
- add new `set @plugin 'repo'` plugin definition syntax (@chilicuil)
- revert back to using `-g` flag in new plugin definition syntax
- permit leading whitespace with new plugin definition syntax (thanks @chilicuil)
- make sure `TMUX_PLUGIN_MANAGER_PATH` always has trailng slash
- ensure old/deprecated plugin syntax `set -g @tpm_plugins` works alongside new
`set -g @plugin` syntax
### v1.2.2, 2015-02-08
- set GIT_TERMINAL_PROMPT=0 when doing `git clone`, `pull` or `submodule update`
to ensure git does not prompt for username/password in any case
### v1.2.1, 2014-11-21
- change the way plugin name is expanded. It now uses the http username
and password by default, like this: `https://git::@github.com/`. This prevents
username and password prompt (and subsequently tmux install hanging) with old
git versions. Fixes #7.
### v1.2.0, 2014-11-20
- refactor tests so they can be used on travis
- add travis.yml, add travis badge to the readme
### v1.1.0, 2014-11-19
- if the plugin is not downloaded do not source it
- remove `PLUGINS.md`, an obsolete list of plugins
- update readme with instructions about uninstalling plugins
- tilde char and `$HOME` in `TMUX_SHARED_MANAGER_PATH` couldn't be used because
they are just plain strings. Fixing the problem by manually expanding them.
- bugfix: fragile `*.tmux` file globbing (@majutsushi)
### v1.0.0, 2014-08-05
- update readme because of github organization change to
[tmux-plugins](https://github.com/tmux-plugins)
- update tests to pass
- update README to suggest different first plugin
- update list of plugins in the README
- remove README 'about' section
- move key binding to the main file. Delete `key_binding.sh`.
- rename `display_message` -> `echo_message`
- installing plugins installs just new plugins. Already installed plugins aren't
updated.
- add 'update plugin' binding and functionality
- add test for updating a plugin
### v0.0.2, 2014-07-17
- run all *.tmux plugin files as executables
- fix all redirects to /dev/null
- fix bug: TPM shared path is created before sync (cloning plugins from github
is done)
- add test suite running in Vagrant
- add Tmux version check. `TPM` won't run if Tmux version is less than 1.9.
### v0.0.1, 2014-05-21
- get TPM up and running

View File

@ -0,0 +1,2 @@
Instructions moved to
[docs/how_to_create_plugin.md](docs/how_to_create_plugin.md).

View File

@ -0,0 +1,20 @@
MIT license
Copyright (C) 2014 Bruno Sutic
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,101 @@
# Tmux Plugin Manager
[![Build Status](https://travis-ci.org/tmux-plugins/tpm.svg?branch=master)](https://travis-ci.org/tmux-plugins/tpm)
Installs and loads `tmux` plugins.
Tested and working on Linux, OSX, and Cygwin.
See list of plugins [here](https://github.com/tmux-plugins/list).
### Installation
Requirements: `tmux` version 1.9 (or higher), `git`, `bash`.
Clone TPM:
```bash
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
```
Put this at the bottom of `~/.tmux.conf` (`$XDG_CONFIG_HOME/tmux/tmux.conf`
works too):
```bash
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
```
Reload TMUX environment so TPM is sourced:
```bash
# type this in terminal if tmux is already running
tmux source ~/.tmux.conf
```
That's it!
### Installing plugins
1. Add new plugin to `~/.tmux.conf` with `set -g @plugin '...'`
2. Press `prefix` + <kbd>I</kbd> (capital i, as in **I**nstall) to fetch the plugin.
You're good to go! The plugin was cloned to `~/.tmux/plugins/` dir and sourced.
### Uninstalling plugins
1. Remove (or comment out) plugin from the list.
2. Press `prefix` + <kbd>alt</kbd> + <kbd>u</kbd> (lowercase u as in **u**ninstall) to remove the plugin.
All the plugins are installed to `~/.tmux/plugins/` so alternatively you can
find plugin directory there and remove it.
### Key bindings
`prefix` + <kbd>I</kbd>
- Installs new plugins from GitHub or any other git repository
- Refreshes TMUX environment
`prefix` + <kbd>U</kbd>
- updates plugin(s)
`prefix` + <kbd>alt</kbd> + <kbd>u</kbd>
- remove/uninstall plugins not on the plugin list
### Docs
- [Help, tpm not working](docs/tpm_not_working.md) - problem solutions
More advanced features and instructions, regular users probably do not need
this:
- [How to create a plugin](docs/how_to_create_plugin.md). It's easy.
- [Managing plugins via the command line](docs/managing_plugins_via_cmd_line.md)
- [Changing plugins install dir](docs/changing_plugins_install_dir.md)
- [Automatic TPM installation on a new machine](docs/automatic_tpm_installation.md)
### Tests
Tests for this project run on [Travis CI](https://travis-ci.org/tmux-plugins/tpm).
When run locally, [vagrant](https://www.vagrantup.com/) is required.
Run tests with:
```bash
# within project directory
./run_tests
```
### License
[MIT](LICENSE.md)

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Script intended for use via the command line.
#
# `.tmux.conf` needs to be set for TPM. Tmux has to be installed on the system,
# but does not need to be started in order to run this script.
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
main() {
"$SCRIPTS_DIR/clean_plugins.sh" # has correct exit code
}
main

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Script intended for use via the command line.
#
# `.tmux.conf` needs to be set for TPM. Tmux has to be installed on the system,
# but does not need to be started in order to run this script.
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
main() {
"$SCRIPTS_DIR/install_plugins.sh" # has correct exit code
}
main

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Script intended for use via the command line.
#
# `.tmux.conf` needs to be set for TPM. Tmux has to be installed on the system,
# but does not need to be started in order to run this script.
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
PROGRAM_NAME="$0"
if [ $# -eq 0 ]; then
echo "usage:"
echo " $PROGRAM_NAME all update all plugins"
echo " $PROGRAM_NAME tmux-foo update plugin 'tmux-foo'"
echo " $PROGRAM_NAME tmux-bar tmux-baz update multiple plugins"
exit 1
fi
main() {
"$SCRIPTS_DIR/update_plugin.sh" --shell-echo "$*" # has correct exit code
}
main "$*"

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Tmux key-binding script.
# Scripts intended to be used via the command line are in `bin/` directory.
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
HELPERS_DIR="$SCRIPTS_DIR/helpers"
source "$HELPERS_DIR/tmux_echo_functions.sh"
source "$HELPERS_DIR/tmux_utils.sh"
main() {
reload_tmux_environment
"$SCRIPTS_DIR/clean_plugins.sh" --tmux-echo >/dev/null 2>&1
reload_tmux_environment
end_message
}
main

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Tmux key-binding script.
# Scripts intended to be used via the command line are in `bin/` directory.
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
HELPERS_DIR="$SCRIPTS_DIR/helpers"
source "$HELPERS_DIR/tmux_echo_functions.sh"
source "$HELPERS_DIR/tmux_utils.sh"
main() {
reload_tmux_environment
"$SCRIPTS_DIR/install_plugins.sh" --tmux-echo >/dev/null 2>&1
reload_tmux_environment
end_message
}
main

View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
# Tmux key-binding script.
# Scripts intended to be used via the command line are in `bin/` directory.
# This script:
# - shows a list of installed plugins
# - starts a prompt to enter the name of the plugin that will be updated
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
HELPERS_DIR="$SCRIPTS_DIR/helpers"
source "$HELPERS_DIR/plugin_functions.sh"
source "$HELPERS_DIR/tmux_echo_functions.sh"
source "$HELPERS_DIR/tmux_utils.sh"
display_plugin_update_list() {
local plugins="$(tpm_plugins_list_helper)"
tmux_echo "Installed plugins:"
tmux_echo ""
for plugin in $plugins; do
# displaying only installed plugins
if plugin_already_installed "$plugin"; then
local plugin_name="$(plugin_name_helper "$plugin")"
tmux_echo " $plugin_name"
fi
done
tmux_echo ""
tmux_echo "Type plugin name to update it."
tmux_echo ""
tmux_echo "- \"all\" - updates all plugins"
tmux_echo "- ENTER - cancels"
}
update_plugin_prompt() {
tmux command-prompt -p 'plugin update:' " \
send-keys C-c; \
run-shell '$SCRIPTS_DIR/update_plugin_prompt_handler.sh %1'"
}
main() {
reload_tmux_environment
display_plugin_update_list
update_plugin_prompt
}
main

View File

@ -0,0 +1,12 @@
# Automatic tpm installation
One of the first things we do on a new machine is cloning our dotfiles. Not everything comes with them though, so for example `tpm` most likely won't be installed.
If you want to install `tpm` and plugins automatically when tmux is started, put the following snippet in `.tmux.conf` before the final `run '~/.tmux/plugins/tpm/tpm'`:
```
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"
```
This useful tip was submitted by @acr4 and narfman0.

View File

@ -0,0 +1,16 @@
# Changing plugins install dir
By default, TPM installs plugins in a subfolder named `plugins/` inside
`$XDG_CONFIG_HOME/tmux/` if a `tmux.conf` file was found at that location, or
inside `~/.tmux/` otherwise.
You can change the install path by putting this in `.tmux.conf`:
set-environment -g TMUX_PLUGIN_MANAGER_PATH '/some/other/path/'
Tmux plugin manager initialization in `.tmux.conf` should also be updated:
# initializes TMUX plugin manager in a new path
run /some/other/path/tpm/tpm
Please make sure that the `run` line is at the very bottom of `.tmux.conf`.

View File

@ -0,0 +1,108 @@
# How to create Tmux plugins
Creating a new plugin is easy.
For demonstration purposes we'll create a simple plugin that lists all
installed TPM plugins. Yes, a plugin that lists plugins :) We'll bind that to
`prefix + T`.
The source code for this example plugin can be found
[here](https://github.com/tmux-plugins/tmux-example-plugin).
### 1. create a new git project
TPM depends on git for downloading and updating plugins.
To create a new git project:
$ mkdir tmux_my_plugin
$ cd tmux_my_plugin
$ git init
### 2. create a `*.tmux` plugin run file
When it sources a plugin, TPM executes all `*.tmux` files in your plugins'
directory. That's how plugins are run.
Create a plugin run file in plugin directory:
$ touch my_plugin.tmux
$ chmod u+x my_plugin.tmux
You can have more than one `*.tmux` file, and all will get executed. However, usually
you'll need just one.
### 3. create a plugin key binding
We want the behavior of the plugin to trigger when a user hits `prefix + T`.
Key `T` is chosen because:
- it's "kind of" a mnemonic for `TPM`
- the key is not used by Tmux natively. Tmux man page, KEY BINDINGS section
contains a list of all the bindings Tmux uses. There's plenty of unused keys
and we don't want to override any of Tmux default key bindings.
Open the plugin run file in your favorite text editor:
$ vim my_plugin.tmux
# or
$ subl my_plugin.tmux
Put the following content in the file:
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
tmux bind-key T run-shell "$CURRENT_DIR/scripts/tmux_list_plugins.sh"
As you can see, plugin run file is a simple bash script that sets up the binding.
When pressed, `prefix + T` will execute another shell script:
`tmux_list_plugins.sh`. That script should be in `scripts/` directory -
relative to the plugin run file.
### 4. listing plugins
Now that we have the binding, let's create a script that's invoked with
`prefix + T`.
$ mkdir scripts
$ touch scripts/tmux_list_plugins.sh
$ chmod u+x scripts/tmux_list_plugins.sh
And here's the script content:
#!/usr/bin/env bash
# fetching the directory where plugins are installed
plugin_path="$(tmux show-env -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)"
# listing installed plugins
ls -1 "$plugin_path"
### 5. try it out
To see if this works, execute the plugin run file:
$ ./my_plugin.tmux
That should set up the key binding. Now hit `prefix + T` and see if it works.
### 6. publish the plugin
When everything is ready, push the plugin to an online git repository,
preferably GitHub.
Other users can install your plugin by just adding plugin git URL to the
`@plugin` list in their `.tmux.conf`.
If the plugin is on GitHub, your users will be able to use the shorthand of
`github_username/repository`.
### Conclusion
Hopefully, that was easy. As you can see, it's mostly shell scripting.
You can use other scripting languages (ruby, python etc) but plain old shell
is preferred because of portability.

View File

@ -0,0 +1,36 @@
# Managing plugins via the command line
Aside from tmux key bindings, TPM provides shell interface for managing plugins
via scripts located in [bin/](../bin/) directory.
Tmux does not need to be started in order to run scripts (but it's okay if it
is). If you [changed tpm install dir](../docs/changing_plugins_install_dir.md)
in `.tmux.conf` that should work fine too.
Prerequisites:
- tmux installed on the system (doh)
- `.tmux.conf` set up for TPM
### Installing plugins
As usual, plugins need to be specified in `.tmux.conf`. Run the following
command to install plugins:
~/.tmux/plugins/tpm/bin/install_plugins
### Updating plugins
To update all installed plugins:
~/.tmux/plugins/tpm/bin/update_plugins all
or update a single plugin:
~/.tmux/plugins/tpm/bin/update_plugins tmux-sensible
### Removing plugins
To remove plugins not on the plugin list:
~/.tmux/plugins/tpm/bin/clean_plugins

View File

@ -0,0 +1,102 @@
# Help, tpm not working!
Here's the list of issues users had with `tpm`:
<hr />
> Nothing works. `tpm` key bindings `prefix + I`, `prefix + U` not even
defined.
Related [issue #22](https://github.com/tmux-plugins/tpm/issues/22)
- Do you have required `tmux` version to run `tpm`?<br/>
Check `tmux` version with `$ tmux -V` command and make sure it's higher or
equal to the required version for `tpm` as stated in the readme.
- ZSH tmux plugin might be causing issues.<br/>
If you have it installed, try disabling it and see if `tpm` works then.
<hr />
> Help, I'm using custom config file with `tmux -f /path/to/my_tmux.conf`
to start Tmux and for some reason plugins aren't loaded!?
Related [issue #57](https://github.com/tmux-plugins/tpm/issues/57)
`tpm` has a known issue when using custom config file with `-f` option.
The solution is to use alternative plugin definition syntax. Here are the steps
to make it work:
1. remove all `set -g @plugin` lines from tmux config file
2. in the config file define the plugins in the following way:
# List of plugins
set -g @tpm_plugins ' \
tmux-plugins/tpm \
tmux-plugins/tmux-sensible \
tmux-plugins/tmux-resurrect \
'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
3. Reload TMUX environment so TPM is sourced: `$ tmux source /path/to/my_tmux.conf`
The plugins should now be working.
<hr />
> Weird sequence of characters show up when installing or updating plugins
Related: [issue #25](https://github.com/tmux-plugins/tpm/issues/25)
- This could be caused by [tmuxline.vim](https://github.com/edkolev/tmuxline.vim)
plugin. Uninstall it and see if things work.
<hr />
> "failed to connect to server" error when sourcing .tmux.conf
Related: [issue #48](https://github.com/tmux-plugins/tpm/issues/48)
- Make sure `tmux source ~/.tmux.conf` command is ran from inside `tmux`.
<hr />
> tpm not working: '~/.tmux/plugins/tpm/tpm' returned 2 (Windows / Cygwin)
Related: [issue #81](https://github.com/tmux-plugins/tpm/issues/81)
This issue is most likely caused by Windows line endings. For example, if you
have git's `core.autocrlf` option set to `true`, git will automatically convert
all the files to Windows line endings which might cause a problem.
The solution is to convert all line ending to Unix newline characters. This
command handles that for all files under `.tmux/` dir (skips `.git`
subdirectories):
```bash
find ~/.tmux -type d -name '.git*' -prune -o -type f -print0 | xargs -0 dos2unix
```
<hr />
> '~/.tmux/plugins/tpm/tpm' returned 127 (on macOS, w/ tmux installed using brew)
Related: [issue #67](https://github.com/tmux-plugins/tpm/issues/67)
This problem is because tmux's `run-shell` command runs a shell which doesn't read from user configs, thus tmux installed in a brew prefix (e.g. `/usr/local/bin`) will not be found.
The solution is to find your brew prefix
```sh
> echo "$(brew --prefix)/bin"
/opt/homebrew/bin
```
And prepend it to the `PATH` environment variable
```
set-environment -g PATH "/opt/homebrew/bin:/bin:/usr/bin"
```
before any `run-shell`/`run` commands in `~/.tmux.conf`.

View File

@ -0,0 +1,78 @@
#!/usr/bin/env bash
VERSION="$1"
UNSUPPORTED_MSG="$2"
get_tmux_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
# Ensures a message is displayed for 5 seconds in tmux prompt.
# Does not override the 'display-time' tmux option.
display_message() {
local message="$1"
# display_duration defaults to 5 seconds, if not passed as an argument
if [ "$#" -eq 2 ]; then
local display_duration="$2"
else
local display_duration="5000"
fi
# saves user-set 'display-time' option
local saved_display_time=$(get_tmux_option "display-time" "750")
# sets message display time to 5 seconds
tmux set-option -gq display-time "$display_duration"
# displays message
tmux display-message "$message"
# restores original 'display-time' value
tmux set-option -gq display-time "$saved_display_time"
}
# this is used to get "clean" integer version number. Examples:
# `tmux 1.9` => `19`
# `1.9a` => `19`
get_digits_from_string() {
local string="$1"
local only_digits="$(echo "$string" | tr -dC '[:digit:]')"
echo "$only_digits"
}
tmux_version_int() {
local tmux_version_string=$(tmux -V)
echo "$(get_digits_from_string "$tmux_version_string")"
}
unsupported_version_message() {
if [ -n "$UNSUPPORTED_MSG" ]; then
echo "$UNSUPPORTED_MSG"
else
echo "Error, Tmux version unsupported! Please install Tmux version $VERSION or greater!"
fi
}
exit_if_unsupported_version() {
local current_version="$1"
local supported_version="$2"
if [ "$current_version" -lt "$supported_version" ]; then
display_message "$(unsupported_version_message)"
exit 1
fi
}
main() {
local supported_version_int="$(get_digits_from_string "$VERSION")"
local current_version_int="$(tmux_version_int)"
exit_if_unsupported_version "$current_version_int" "$supported_version_int"
}
main

View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR/helpers"
source "$HELPERS_DIR/plugin_functions.sh"
source "$HELPERS_DIR/utility.sh"
if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions
source "$HELPERS_DIR/tmux_echo_functions.sh"
else # shell output functions
source "$HELPERS_DIR/shell_echo_functions.sh"
fi
clean_plugins() {
local plugins plugin plugin_directory
plugins="$(tpm_plugins_list_helper)"
for plugin_directory in "$(tpm_path)"/*; do
[ -d "${plugin_directory}" ] || continue
plugin="$(plugin_name_helper "${plugin_directory}")"
case "${plugins}" in
*"${plugin}"*) : ;;
*)
[ "${plugin}" = "tpm" ] && continue
echo_ok "Removing \"$plugin\""
rm -rf "${plugin_directory}" >/dev/null 2>&1
[ -d "${plugin_directory}" ] &&
echo_err " \"$plugin\" clean fail" ||
echo_ok " \"$plugin\" clean success"
;;
esac
done
}
main() {
ensure_tpm_path_exists
clean_plugins
exit_value_helper
}
main

View File

@ -0,0 +1,104 @@
# using @tpm_plugins is now deprecated in favor of using @plugin syntax
tpm_plugins_variable_name="@tpm_plugins"
# manually expanding tilde char or `$HOME` variable.
_manual_expansion() {
local path="$1"
local expanded_tilde="${path/#\~/$HOME}"
echo "${expanded_tilde/#\$HOME/$HOME}"
}
_tpm_path() {
local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
_manual_expansion "$string_path"
}
_CACHED_TPM_PATH="$(_tpm_path)"
# Get the absolute path to the users configuration file of TMux.
# This includes a prioritized search on different locations.
#
_get_user_tmux_conf() {
# Define the different possible locations.
xdg_location="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
default_location="$HOME/.tmux.conf"
# Search for the correct configuration file by priority.
if [ -f "$xdg_location" ]; then
echo "$xdg_location"
else
echo "$default_location"
fi
}
_tmux_conf_contents() {
user_config=$(_get_user_tmux_conf)
cat /etc/tmux.conf "$user_config" 2>/dev/null
if [ "$1" == "full" ]; then # also output content from sourced files
local file
for file in $(_sourced_files); do
cat $(_manual_expansion "$file") 2>/dev/null
done
fi
}
# return files sourced from tmux config files
_sourced_files() {
_tmux_conf_contents |
sed -E -n -e "s/^[[:space:]]*source(-file)?[[:space:]]+(-q+[[:space:]]+)?['\"]?([^'\"]+)['\"]?/\3/p"
}
# Want to be able to abort in certain cases
trap "exit 1" TERM
export TOP_PID=$$
_fatal_error_abort() {
echo >&2 "Aborting."
kill -s TERM $TOP_PID
}
# PUBLIC FUNCTIONS BELOW
tpm_path() {
if [ "$_CACHED_TPM_PATH" == "/" ]; then
echo >&2 "FATAL: Tmux Plugin Manager not configured in tmux.conf"
_fatal_error_abort
fi
echo "$_CACHED_TPM_PATH"
}
tpm_plugins_list_helper() {
# lists plugins from @tpm_plugins option
echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")"
# read set -g @plugin "tmux-plugins/tmux-example-plugin" entries
_tmux_conf_contents "full" |
awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }'
}
# Allowed plugin name formats:
# 1. "git://github.com/user/plugin_name.git"
# 2. "user/plugin_name"
plugin_name_helper() {
local plugin="$1"
# get only the part after the last slash, e.g. "plugin_name.git"
local plugin_basename="$(basename "$plugin")"
# remove ".git" extension (if it exists) to get only "plugin_name"
local plugin_name="${plugin_basename%.git}"
echo "$plugin_name"
}
plugin_path_helper() {
local plugin="$1"
local plugin_name="$(plugin_name_helper "$plugin")"
echo "$(tpm_path)${plugin_name}/"
}
plugin_already_installed() {
local plugin="$1"
local plugin_path="$(plugin_path_helper "$plugin")"
[ -d "$plugin_path" ] &&
cd "$plugin_path" &&
git remote >/dev/null 2>&1
}

View File

@ -0,0 +1,7 @@
echo_ok() {
echo "$*"
}
echo_err() {
fail_helper "$*"
}

View File

@ -0,0 +1,28 @@
_has_emacs_mode_keys() {
$(tmux show -gw mode-keys | grep -q emacs)
}
tmux_echo() {
local message="$1"
tmux run-shell "echo '$message'"
}
echo_ok() {
tmux_echo "$*"
}
echo_err() {
tmux_echo "$*"
}
end_message() {
if _has_emacs_mode_keys; then
local continue_key="ESCAPE"
else
local continue_key="ENTER"
fi
tmux_echo ""
tmux_echo "TMUX environment reloaded."
tmux_echo ""
tmux_echo "Done, press $continue_key to continue."
}

View File

@ -0,0 +1,6 @@
HELPERS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$HELPERS_DIR/plugin_functions.sh"
reload_tmux_environment() {
tmux source-file $(_get_user_tmux_conf) >/dev/null 2>&1
}

View File

@ -0,0 +1,17 @@
ensure_tpm_path_exists() {
mkdir -p "$(tpm_path)"
}
fail_helper() {
local message="$1"
echo "$message" >&2
FAIL="true"
}
exit_value_helper() {
if [ "$FAIL" == "true" ]; then
exit 1
else
exit 0
fi
}

View File

@ -0,0 +1,75 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR/helpers"
source "$HELPERS_DIR/plugin_functions.sh"
source "$HELPERS_DIR/utility.sh"
if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions
source "$HELPERS_DIR/tmux_echo_functions.sh"
else # shell output functions
source "$HELPERS_DIR/shell_echo_functions.sh"
fi
clone() {
local plugin="$1"
local branch="$2"
if [ -n "$branch" ]; then
cd "$(tpm_path)" &&
GIT_TERMINAL_PROMPT=0 git clone -b "$branch" --single-branch --recursive "$plugin" >/dev/null 2>&1
else
cd "$(tpm_path)" &&
GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" >/dev/null 2>&1
fi
}
# tries cloning:
# 1. plugin name directly - works if it's a valid git url
# 2. expands the plugin name to point to a GitHub repo and tries cloning again
clone_plugin() {
local plugin="$1"
local branch="$2"
clone "$plugin" "$branch" ||
clone "https://git::@github.com/$plugin" "$branch"
}
# clone plugin and produce output
install_plugin() {
local plugin="$1"
local branch="$2"
local plugin_name="$(plugin_name_helper "$plugin")"
if plugin_already_installed "$plugin"; then
echo_ok "Already installed \"$plugin_name\""
else
echo_ok "Installing \"$plugin_name\""
clone_plugin "$plugin" "$branch" &&
echo_ok " \"$plugin_name\" download success" ||
echo_err " \"$plugin_name\" download fail"
fi
}
install_plugins() {
local plugins="$(tpm_plugins_list_helper)"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
install_plugin "${plugin[0]}" "${plugin[1]}"
done
}
verify_tpm_path_permissions() {
local path="$(tpm_path)"
# check the write permission flag for all users to ensure
# that we have proper access
[ -w "$path" ] ||
echo_err "$path is not writable!"
}
main() {
ensure_tpm_path_exists
verify_tpm_path_permissions
install_plugins
exit_value_helper
}
main

View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR/helpers"
source "$HELPERS_DIR/plugin_functions.sh"
plugin_dir_exists() {
[ -d "$1" ]
}
# Runs all *.tmux files from the plugin directory.
# Files are ran as executables.
# No errors if the plugin dir does not exist.
silently_source_all_tmux_files() {
local plugin_path="$1"
local plugin_tmux_files="$plugin_path*.tmux"
if plugin_dir_exists "$plugin_path"; then
for tmux_file in $plugin_tmux_files; do
# if the glob didn't find any files this will be the
# unexpanded glob which obviously doesn't exist
[ -f "$tmux_file" ] || continue
# runs *.tmux file as an executable
$tmux_file >/dev/null 2>&1
done
fi
}
source_plugins() {
local plugin plugin_path
local plugins="$(tpm_plugins_list_helper)"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
plugin_path="$(plugin_path_helper "${plugin[0]}")"
silently_source_all_tmux_files "$plugin_path"
done
}
main() {
source_plugins
}
main

View File

@ -0,0 +1,78 @@
#!/usr/bin/env bash
# this script handles core logic of updating plugins
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR/helpers"
source "$HELPERS_DIR/plugin_functions.sh"
source "$HELPERS_DIR/utility.sh"
if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions
source "$HELPERS_DIR/tmux_echo_functions.sh"
else # shell output functions
source "$HELPERS_DIR/shell_echo_functions.sh"
fi
# from now on ignore first script argument
shift
pull_changes() {
local plugin="$1"
local plugin_path="$(plugin_path_helper "$plugin")"
cd "$plugin_path" &&
GIT_TERMINAL_PROMPT=0 git pull &&
GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive
}
update() {
local plugin="$1" output
output=$(pull_changes "$plugin" 2>&1)
if (( $? == 0 )); then
echo_ok " \"$plugin\" update success"
echo_ok "$(echo "$output" | sed -e 's/^/ | /')"
else
echo_err " \"$plugin\" update fail"
echo_err "$(echo "$output" | sed -e 's/^/ | /')"
fi
}
update_all() {
echo_ok "Updating all plugins!"
echo_ok ""
local plugins="$(tpm_plugins_list_helper)"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
# updating only installed plugins
if plugin_already_installed "$plugin_name"; then
update "$plugin_name" &
fi
done
wait
}
update_plugins() {
local plugins="$*"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
if plugin_already_installed "$plugin_name"; then
update "$plugin_name" &
else
echo_err "$plugin_name not installed!" &
fi
done
wait
}
main() {
ensure_tpm_path_exists
if [ "$1" == "all" ]; then
update_all
else
update_plugins "$*"
fi
exit_value_helper
}
main "$*"

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR/helpers"
if [ $# -eq 0 ]; then
exit 0
fi
source "$HELPERS_DIR/tmux_echo_functions.sh"
source "$HELPERS_DIR/tmux_utils.sh"
main() {
"$CURRENT_DIR/update_plugin.sh" --tmux-echo "$*"
reload_tmux_environment
end_message
}
main "$*"

View File

@ -0,0 +1,13 @@
install_key_option="@tpm-install"
default_install_key="I"
update_key_option="@tpm-update"
default_update_key="U"
clean_key_option="@tpm-clean"
default_clean_key="M-u"
SUPPORTED_TMUX_VERSION="1.9"
DEFAULT_TPM_ENV_VAR_NAME="TMUX_PLUGIN_MANAGER_PATH"
DEFAULT_TPM_PATH="$HOME/.tmux/plugins/"

View File

@ -0,0 +1,36 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + I
send "I"
# cloning might take a while
set timeout 20
expect_after {
timeout { exit 1 }
}
expect {
"Installing \"non-existing-plugin\""
}
expect {
"\"non-existing-plugin\" download fail"
}
expect {
"Done, press ENTER to continue" {
exit 0
}
}
exit 1

View File

@ -0,0 +1,35 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + alt + u
send "u"
set timeout 5
expect_after {
timeout { exit 1 }
}
expect {
"Removing \"tmux-example-plugin\""
}
expect {
"\"tmux-example-plugin\" clean success"
}
expect {
"Done, press ENTER to continue." {
exit 0
}
}
exit 1

View File

@ -0,0 +1,44 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + I
send "I"
# cloning might take a while
set timeout 15
expect_after {
timeout { exit 1 }
}
expect {
"Installing \"tmux-example-plugin\""
}
expect {
"\"tmux-example-plugin\" download success"
}
expect {
"Installing \"tmux-copycat\""
}
expect {
"\"tmux-copycat\" download success"
}
expect {
"Done, press ENTER to continue." {
exit 0
}
}
exit 1

View File

@ -0,0 +1,50 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + I
send "I"
# cloning might take a while
set timeout 15
expect_after {
timeout { exit 1 }
}
expect {
"Installing \"tmux-example-plugin\""
}
expect {
"\"tmux-example-plugin\" download success"
}
expect {
"Done, press ENTER to continue" {
send " "
}
}
sleep 1
# this is tmux prefix + I
send "I"
expect {
"Already installed \"tmux-example-plugin\""
}
expect {
"Done, press ENTER to continue" {
exit 0
}
}
exit 1

View File

@ -0,0 +1,55 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + U
send "U"
set timeout 15
expect_after {
timeout { exit 1 }
}
expect {
"Installed plugins"
}
expect {
"tmux-example-plugin"
}
expect {
"\"all\" - updates all plugins"
}
expect {
"ENTER - cancels"
}
# wait for tmux to display prompt before sending characters
sleep 1
send "tmux-example-plugin\r"
expect {
"Updating \"tmux-example-plugin\""
}
expect {
"\"tmux-example-plugin\" update success"
}
expect {
"Done, press ENTER to continue." {
exit 0
}
}
exit 1

View File

@ -0,0 +1,59 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + U
send "U"
set timeout 5
expect_after {
timeout { exit 1 }
}
expect {
"Installed plugins"
}
expect {
"tmux-example-plugin"
}
expect {
"\"all\" - updates all plugins"
}
expect {
"ENTER - cancels"
}
# wait for tmux to display prompt before sending characters
sleep 1
send "all\r"
expect {
"Updating all plugins!"
}
expect {
"Updating \"tmux-example-plugin\""
}
expect {
"\"tmux-example-plugin\" update success"
}
expect {
"Done, press ENTER to continue." {
exit 0
}
}
exit 1

View File

@ -0,0 +1,13 @@
check_dir_exists_helper() {
[ -d "$1" ]
}
# runs the scripts and asserts it has the correct output and exit code
script_run_helper() {
local script="$1"
local expected_output="$2"
local expected_exit_code="${3:-0}"
$script 2>&1 |
grep "$expected_output" >/dev/null 2>&1 && # grep -q flag quits the script early
[ "${PIPESTATUS[0]}" -eq "$expected_exit_code" ]
}

View File

@ -0,0 +1,67 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TPM_DIR="$PWD"
PLUGINS_DIR="$HOME/.tmux/plugins"
source "$CURRENT_DIR/helpers/helpers.sh"
source "$CURRENT_DIR/helpers/tpm.sh"
manually_install_the_plugin() {
rm -rf "$PLUGINS_DIR"
mkdir -p "$PLUGINS_DIR"
cd "$PLUGINS_DIR"
git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin
}
# TMUX KEY-BINDING TESTS
test_plugin_uninstallation_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
run-shell "$TPM_DIR/tpm"
HERE
manually_install_the_plugin
"$CURRENT_DIR/expect_successful_clean_plugins" ||
fail_helper "[key-binding] clean fails"
teardown_helper
}
# SCRIPT TESTS
test_plugin_uninstallation_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
run-shell "$TPM_DIR/tpm"
HERE
manually_install_the_plugin
script_run_helper "$TPM_DIR/bin/clean_plugins" '"tmux-example-plugin" clean success' ||
fail_helper "[script] plugin cleaning fails"
teardown_helper
}
test_unsuccessful_plugin_uninstallation_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
run-shell "$TPM_DIR/tpm"
HERE
manually_install_the_plugin
chmod 000 "$PLUGINS_DIR/tmux-example-plugin" # disable directory deletion
local expected_exit_code=1
script_run_helper "$TPM_DIR/bin/clean_plugins" '"tmux-example-plugin" clean fail' "$expected_exit_code" ||
fail_helper "[script] unsuccessful plugin cleaning doesn't fail"
chmod 755 "$PLUGINS_DIR/tmux-example-plugin" # enable directory deletion
teardown_helper
}
run_tests

View File

@ -0,0 +1,284 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PLUGINS_DIR="$HOME/.tmux/plugins"
TPM_DIR="$PWD"
CUSTOM_PLUGINS_DIR="$HOME/foo/plugins"
ADDITIONAL_CONFIG_FILE_1="$HOME/.tmux/additional_config_file_1"
ADDITIONAL_CONFIG_FILE_2="$HOME/.tmux/additional_config_file_2"
source "$CURRENT_DIR/helpers/helpers.sh"
source "$CURRENT_DIR/helpers/tpm.sh"
# TMUX KEY-BINDING TESTS
test_plugin_installation_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
"$CURRENT_DIR/expect_successful_plugin_download" ||
fail_helper "[key-binding] plugin installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding] plugin download fails"
teardown_helper
}
test_plugin_installation_via_tmux_key_binding_set_option() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set-option -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
"$CURRENT_DIR/expect_successful_plugin_download" ||
fail_helper "[key-binding][set-option] plugin installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding][set-option] plugin download fails"
teardown_helper
}
test_plugin_installation_custom_dir_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set-environment -g TMUX_PLUGIN_MANAGER_PATH '$CUSTOM_PLUGINS_DIR'
set -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
"$CURRENT_DIR/expect_successful_plugin_download" ||
fail_helper "[key-binding][custom dir] plugin installation fails"
check_dir_exists_helper "$CUSTOM_PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding][custom dir] plugin download fails"
teardown_helper
rm -rf "$CUSTOM_PLUGINS_DIR"
}
test_non_existing_plugin_installation_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/non-existing-plugin"
run-shell "$TPM_DIR/tpm"
HERE
"$CURRENT_DIR/expect_failed_plugin_download" ||
fail_helper "[key-binding] non existing plugin installation doesn't fail"
teardown_helper
}
test_multiple_plugins_installation_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/tmux-example-plugin"
\ \ set -g @plugin 'tmux-plugins/tmux-copycat'
run-shell "$TPM_DIR/tpm"
HERE
"$CURRENT_DIR/expect_successful_multiple_plugins_download" ||
fail_helper "[key-binding] multiple plugins installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[key-binding] plugin download fails (tmux-copycat)"
teardown_helper
}
test_plugins_installation_from_sourced_file_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
source '$ADDITIONAL_CONFIG_FILE_1'
set -g @plugin 'tmux-plugins/tmux-example-plugin'
run-shell "$TPM_DIR/tpm"
HERE
mkdir ~/.tmux
echo "set -g @plugin 'tmux-plugins/tmux-copycat'" > "$ADDITIONAL_CONFIG_FILE_1"
"$CURRENT_DIR/expect_successful_multiple_plugins_download" ||
fail_helper "[key-binding][sourced file] plugins installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding][sourced file] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[key-binding][sourced file] plugin download fails (tmux-copycat)"
teardown_helper
}
test_plugins_installation_from_multiple_sourced_files_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
\ \ source '$ADDITIONAL_CONFIG_FILE_1'
source-file '$ADDITIONAL_CONFIG_FILE_2'
run-shell "$TPM_DIR/tpm"
HERE
mkdir ~/.tmux
echo "set -g @plugin 'tmux-plugins/tmux-example-plugin'" > "$ADDITIONAL_CONFIG_FILE_1"
echo " set -g @plugin 'tmux-plugins/tmux-copycat'" > "$ADDITIONAL_CONFIG_FILE_2"
"$CURRENT_DIR/expect_successful_multiple_plugins_download" ||
fail_helper "[key-binding][multiple sourced files] plugins installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding][multiple sourced files] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[key-binding][multiple sourced files] plugin download fails (tmux-copycat)"
teardown_helper
}
# SCRIPT TESTS
test_plugin_installation_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-example-plugin" download success' ||
fail_helper "[script] plugin installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script] plugin download fails"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-example-plugin"' ||
fail_helper "[script] plugin already installed message fail"
teardown_helper
}
test_plugin_installation_custom_dir_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set-environment -g TMUX_PLUGIN_MANAGER_PATH '$CUSTOM_PLUGINS_DIR'
set -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-example-plugin" download success' ||
fail_helper "[script][custom dir] plugin installation fails"
check_dir_exists_helper "$CUSTOM_PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script][custom dir] plugin download fails"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-example-plugin"' ||
fail_helper "[script][custom dir] plugin already installed message fail"
teardown_helper
rm -rf "$CUSTOM_PLUGINS_DIR"
}
test_non_existing_plugin_installation_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/non-existing-plugin"
run-shell "$TPM_DIR/tpm"
HERE
local expected_exit_code=1
script_run_helper "$TPM_DIR/bin/install_plugins" '"non-existing-plugin" download fail' "$expected_exit_code" ||
fail_helper "[script] non existing plugin installation doesn't fail"
teardown_helper
}
test_multiple_plugins_installation_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/tmux-example-plugin"
\ \ set -g @plugin 'tmux-plugins/tmux-copycat'
run-shell "$TPM_DIR/tpm"
HERE
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-example-plugin" download success' ||
fail_helper "[script] multiple plugins installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[script] plugin download fails (tmux-copycat)"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-copycat"' ||
fail_helper "[script] multiple plugins already installed message fail"
teardown_helper
}
test_plugins_installation_from_sourced_file_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
source '$ADDITIONAL_CONFIG_FILE_1'
set -g @plugin 'tmux-plugins/tmux-example-plugin'
run-shell "$TPM_DIR/tpm"
HERE
mkdir ~/.tmux
echo "set -g @plugin 'tmux-plugins/tmux-copycat'" > "$ADDITIONAL_CONFIG_FILE_1"
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-copycat" download success' ||
fail_helper "[script][sourced file] plugins installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script][sourced file] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[script][sourced file] plugin download fails (tmux-copycat)"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-copycat"' ||
fail_helper "[script][sourced file] plugins already installed message fail"
teardown_helper
}
test_plugins_installation_from_multiple_sourced_files_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
\ \ source '$ADDITIONAL_CONFIG_FILE_1'
source-file '$ADDITIONAL_CONFIG_FILE_2'
set -g @plugin 'tmux-plugins/tmux-example-plugin'
run-shell "$TPM_DIR/tpm"
HERE
mkdir ~/.tmux
echo " set -g @plugin 'tmux-plugins/tmux-copycat'" > "$ADDITIONAL_CONFIG_FILE_1"
echo "set -g @plugin 'tmux-plugins/tmux-sensible'" > "$ADDITIONAL_CONFIG_FILE_2"
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-sensible" download success' ||
fail_helper "[script][multiple sourced files] plugins installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script][multiple sourced files] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[script][multiple sourced files] plugin download fails (tmux-copycat)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-sensible/" ||
fail_helper "[script][multiple sourced files] plugin download fails (tmux-sensible)"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-sensible"' ||
fail_helper "[script][multiple sourced files] plugins already installed message fail"
teardown_helper
}
run_tests

View File

@ -0,0 +1,100 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PLUGINS_DIR="$HOME/.tmux/plugins"
TPM_DIR="$PWD"
source "$CURRENT_DIR/helpers/helpers.sh"
source "$CURRENT_DIR/helpers/tpm.sh"
# TMUX KEY-BINDING TESTS
test_plugin_installation_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @tpm_plugins "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
# opens tmux and test it with `expect`
$CURRENT_DIR/expect_successful_plugin_download ||
fail_helper "[key-binding] plugin installation fails"
# check plugin dir exists after download
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding] plugin download fails"
teardown_helper
}
test_legacy_and_new_syntax_for_plugin_installation_work_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @tpm_plugins " \
tmux-plugins/tmux-example-plugin \
"
set -g @plugin 'tmux-plugins/tmux-copycat'
run-shell "$TPM_DIR/tpm"
HERE
# opens tmux and test it with `expect`
"$CURRENT_DIR"/expect_successful_multiple_plugins_download ||
fail_helper "[key-binding] multiple plugins installation fails"
# check plugin dir exists after download
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[key-binding] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[key-binding] plugin download fails (tmux-copycat)"
teardown_helper
}
# SCRIPT TESTS
test_plugin_installation_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @tpm_plugins "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-example-plugin" download success' ||
fail_helper "[script] plugin installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script] plugin download fails"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-example-plugin"' ||
fail_helper "[script] plugin already installed message fail"
teardown_helper
}
test_legacy_and_new_syntax_for_plugin_installation_work_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @tpm_plugins " \
tmux-plugins/tmux-example-plugin \
"
set -g @plugin 'tmux-plugins/tmux-copycat'
run-shell "$TPM_DIR/tpm"
HERE
script_run_helper "$TPM_DIR/bin/install_plugins" '"tmux-example-plugin" download success' ||
fail_helper "[script] multiple plugin installation fails"
check_dir_exists_helper "$PLUGINS_DIR/tmux-example-plugin/" ||
fail_helper "[script] plugin download fails (tmux-example-plugin)"
check_dir_exists_helper "$PLUGINS_DIR/tmux-copycat/" ||
fail_helper "[script] plugin download fails (tmux-copycat)"
script_run_helper "$TPM_DIR/bin/install_plugins" 'Already installed "tmux-copycat"' ||
fail_helper "[script] multiple plugins already installed message fail"
teardown_helper
}
run_tests

View File

@ -0,0 +1,78 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TPM_DIR="$PWD"
PLUGINS_DIR="$HOME/.tmux/plugins"
CUSTOM_PLUGINS_DIR="$HOME/foo/plugins"
source "$CURRENT_DIR/helpers/helpers.sh"
source "$CURRENT_DIR/helpers/tpm.sh"
check_binding_defined() {
local binding="$1"
tmux list-keys | grep -q "$binding"
}
create_test_plugin_helper() {
local plugin_path="$PLUGINS_DIR/tmux_test_plugin/"
rm -rf "$plugin_path"
mkdir -p "$plugin_path"
while read line; do
echo "$line" >> "$plugin_path/test_plugin.tmux"
done
chmod +x "$plugin_path/test_plugin.tmux"
}
check_tpm_path() {
local correct_tpm_path="$1"
local tpm_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)"
[ "$correct_tpm_path" == "$tpm_path" ]
}
test_plugin_sourcing() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "doesnt_matter/tmux_test_plugin"
run-shell "$TPM_DIR/tpm"
HERE
# manually creates a local tmux plugin
create_test_plugin_helper <<- HERE
tmux bind-key R run-shell foo_command
HERE
tmux new-session -d # tmux starts detached
check_binding_defined "R run-shell foo_command" ||
fail_helper "Plugin sourcing fails"
teardown_helper
}
test_default_tpm_path() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
run-shell "$TPM_DIR/tpm"
HERE
check_tpm_path "${PLUGINS_DIR}/" ||
fail_helper "Default TPM path not correct"
teardown_helper
}
test_custom_tpm_path() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set-environment -g TMUX_PLUGIN_MANAGER_PATH '$CUSTOM_PLUGINS_DIR'
run-shell "$TPM_DIR/tpm"
HERE
check_tpm_path "$CUSTOM_PLUGINS_DIR" ||
fail_helper "Custom TPM path not correct"
teardown_helper
}
run_tests

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TPM_DIR="$PWD"
PLUGINS_DIR="$HOME/.tmux/plugins"
source "$CURRENT_DIR/helpers/helpers.sh"
source "$CURRENT_DIR/helpers/tpm.sh"
manually_install_the_plugin() {
mkdir -p "$PLUGINS_DIR"
cd "$PLUGINS_DIR"
git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin
}
# TMUX KEY-BINDING TESTS
test_plugin_update_via_tmux_key_binding() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
manually_install_the_plugin
"$CURRENT_DIR/expect_successful_update_of_all_plugins" ||
fail_helper "[key-binding] 'update all plugins' fails"
"$CURRENT_DIR/expect_successful_update_of_a_single_plugin" ||
fail_helper "[key-binding] 'update single plugin' fails"
teardown_helper
}
# SCRIPT TESTS
test_plugin_update_via_script() {
set_tmux_conf_helper <<- HERE
set -g mode-keys vi
set -g @plugin "tmux-plugins/tmux-example-plugin"
run-shell "$TPM_DIR/tpm"
HERE
manually_install_the_plugin
local expected_exit_code=1
script_run_helper "$TPM_DIR/bin/update_plugins" 'usage' "$expected_exit_code" ||
fail_helper "[script] running update plugins without args should fail"
script_run_helper "$TPM_DIR/bin/update_plugins tmux-example-plugin" '"tmux-example-plugin" update success' ||
fail_helper "[script] plugin update fails"
script_run_helper "$TPM_DIR/bin/update_plugins all" '"tmux-example-plugin" update success' ||
fail_helper "[script] update all plugins fails"
teardown_helper
}
run_tests

81
tmux/.tmux/plugins/tpm/tpm Executable file
View File

@ -0,0 +1,81 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BINDINGS_DIR="$CURRENT_DIR/bindings"
SCRIPTS_DIR="$CURRENT_DIR/scripts"
source "$SCRIPTS_DIR/variables.sh"
get_tmux_option() {
local option="$1"
local default_value="$2"
local option_value="$(tmux show-option -gqv "$option")"
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
tpm_path_set() {
tmux show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1
}
# Check if configuration file exists at an XDG-compatible location, if so use
# that directory for TMUX_PLUGIN_MANAGER_PATH. Otherwise use $DEFAULT_TPM_PATH.
set_default_tpm_path() {
local xdg_tmux_path="${XDG_CONFIG_HOME:-$HOME/.config}/tmux"
local tpm_path="$DEFAULT_TPM_PATH"
if [ -f "$xdg_tmux_path/tmux.conf" ]; then
tpm_path="$xdg_tmux_path/plugins/"
fi
tmux set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$tpm_path"
}
# Ensures TMUX_PLUGIN_MANAGER_PATH global env variable is set.
#
# Put this in `.tmux.conf` to override the default:
# `set-environment -g TMUX_PLUGIN_MANAGER_PATH "/some/other/path/"`
set_tpm_path() {
if ! tpm_path_set; then
set_default_tpm_path
fi
}
# 1. Fetches plugin names from `@plugin` variables
# 2. Creates full plugin path
# 3. Sources all *.tmux files from each of the plugin directories
# - no errors raised if directory does not exist
# Files are sourced as tmux config files, not as shell scripts!
source_plugins() {
"$SCRIPTS_DIR/source_plugins.sh" >/dev/null 2>&1
}
# prefix + I - downloads TPM plugins and reloads TMUX environment
# prefix + U - updates a plugin (or all of them) and reloads TMUX environment
# prefix + alt + u - remove unused TPM plugins and reloads TMUX environment
set_tpm_key_bindings() {
local install_key="$(get_tmux_option "$install_key_option" "$default_install_key")"
tmux bind-key "$install_key" run-shell "$BINDINGS_DIR/install_plugins"
local update_key="$(get_tmux_option "$update_key_option" "$default_update_key")"
tmux bind-key "$update_key" run-shell "$BINDINGS_DIR/update_plugins"
local clean_key="$(get_tmux_option "$clean_key_option" "$default_clean_key")"
tmux bind-key "$clean_key" run-shell "$BINDINGS_DIR/clean_plugins"
}
supported_tmux_version_ok() {
"$SCRIPTS_DIR/check_tmux_version.sh" "$SUPPORTED_TMUX_VERSION"
}
main() {
if supported_tmux_version_ok; then
set_tpm_path
set_tpm_key_bindings
source_plugins
fi
}
main

View File

@ -0,0 +1 @@
doc/tags

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Chris Toomey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,462 @@
Vim Tmux Navigator
==================
This plugin is a repackaging of [Mislav Marohnić's](https://mislav.net/) tmux-navigator
configuration described in [this gist][]. When combined with a set of tmux
key bindings, the plugin will allow you to navigate seamlessly between
vim and tmux splits using a consistent set of hotkeys.
**NOTE**: This requires tmux v1.8 or higher.
Usage
-----
This plugin provides the following mappings which allow you to move between
Vim panes and tmux splits seamlessly.
- `<ctrl-h>` => Left
- `<ctrl-j>` => Down
- `<ctrl-k>` => Up
- `<ctrl-l>` => Right
- `<ctrl-\>` => Previous split
**Note** - you don't need to use your tmux `prefix` key sequence before using
the mappings.
If you want to use alternate key mappings, see the [configuration section
below][].
Installation
------------
### Vim
If you don't have a preferred installation method, I recommend using [Vundle][].
Assuming you have Vundle installed and configured, the following steps will
install the plugin:
Add the following line to your `~/.vimrc` file
``` vim
Plugin 'christoomey/vim-tmux-navigator'
```
Then run
```
:PluginInstall
```
If you are using Vim 8+, you don't need any plugin manager. Simply clone this repository inside `~/.vim/pack/plugin/start/` directory and restart Vim.
```
git clone git@github.com:christoomey/vim-tmux-navigator.git ~/.vim/pack/plugins/start/vim-tmux-navigator
```
### lazy.nvim
If you are using [lazy.nvim](https://github.com/folke/lazy.nvim). Add the following plugin to your configuration.
```lua
{
"christoomey/vim-tmux-navigator",
cmd = {
"TmuxNavigateLeft",
"TmuxNavigateDown",
"TmuxNavigateUp",
"TmuxNavigateRight",
"TmuxNavigatePrevious",
},
keys = {
{ "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
{ "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
{ "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
{ "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
{ "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
},
}
```
Then, restart Neovim and lazy.nvim will automatically install the plugin and configure the keybindings.
### tmux
To configure the tmux side of this customization there are two options:
#### Add a snippet
Add the following to your `~/.tmux.conf` file:
``` tmux
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
```
#### TPM
If you'd prefer, you can use the Tmux Plugin Manager ([TPM][]) instead of
copying the snippet.
When using TPM, add the following lines to your ~/.tmux.conf:
``` tmux
set -g @plugin 'christoomey/vim-tmux-navigator'
run '~/.tmux/plugins/tpm/tpm'
```
Thanks to Christopher Sexton who provided the updated tmux configuration in
[this blog post][].
Configuration
-------------
### Custom Key Bindings
If you don't want the plugin to create any mappings, you can use the five
provided functions to define your own custom maps. You will need to define
custom mappings in your `~/.vimrc` as well as update the bindings in tmux to
match.
#### Vim
Add the following to your `~/.vimrc` to define your custom maps:
``` vim
let g:tmux_navigator_no_mappings = 1
noremap <silent> {Left-Mapping} :<C-U>TmuxNavigateLeft<cr>
noremap <silent> {Down-Mapping} :<C-U>TmuxNavigateDown<cr>
noremap <silent> {Up-Mapping} :<C-U>TmuxNavigateUp<cr>
noremap <silent> {Right-Mapping} :<C-U>TmuxNavigateRight<cr>
noremap <silent> {Previous-Mapping} :<C-U>TmuxNavigatePrevious<cr>
```
*Note* Each instance of `{Left-Mapping}` or `{Down-Mapping}` must be replaced
in the above code with the desired mapping. Ie, the mapping for `<ctrl-h>` =>
Left would be created with `noremap <silent> <c-h> :<C-U>TmuxNavigateLeft<cr>`.
##### Autosave on leave
You can configure the plugin to write the current buffer, or all buffers, when
navigating from Vim to tmux. This functionality is exposed via the
`g:tmux_navigator_save_on_switch` variable, which can have either of the
following values:
Value | Behavior
------ | ------
1 | `:update` (write the current buffer, but only if changed)
2 | `:wall` (write all buffers)
To enable this, add the following (with the desired value) to your ~/.vimrc:
```vim
" Write all buffers before navigating from Vim to tmux pane
let g:tmux_navigator_save_on_switch = 2
```
##### Disable While Zoomed
By default, if you zoom the tmux pane running Vim and then attempt to navigate
"past" the edge of the Vim session, tmux will unzoom the pane. This is the
default tmux behavior, but may be confusing if you've become accustomed to
navigation "wrapping" around the sides due to this plugin.
We provide an option, `g:tmux_navigator_disable_when_zoomed`, which can be used
to disable this unzooming behavior, keeping all navigation within Vim until the
tmux pane is explicitly unzoomed.
To disable navigation when zoomed, add the following to your ~/.vimrc:
```vim
" Disable tmux navigator when zooming the Vim pane
let g:tmux_navigator_disable_when_zoomed = 1
```
##### Preserve Zoom
As noted above, navigating from a Vim pane to another tmux pane normally causes
the window to be unzoomed. Some users may prefer the behavior of tmux's `-Z`
option to `select-pane`, which keeps the window zoomed if it was zoomed. To
enable this behavior, set the `g:tmux_navigator_preserve_zoom` option to `1`:
```vim
" If the tmux window is zoomed, keep it zoomed when moving from Vim to another pane
let g:tmux_navigator_preserve_zoom = 1
```
Naturally, if `g:tmux_navigator_disable_when_zoomed` is enabled, this option
will have no effect.
#### Tmux
Alter each of the five lines of the tmux configuration listed above to use your
custom mappings. **Note** each line contains two references to the desired
mapping.
### Additional Customization
#### Ignoring programs that use Ctrl+hjkl movement
In interactive programs such as FZF, Ctrl+hjkl can be used instead of the arrow keys to move the selection up and down. If vim-tmux-navigator is getting in your way trying to change the active window instead, you can make it be ignored and work as if this plugin were not enabled. Just modify the `is_vim` variable(that you have either on the snipped you pasted on `~/.tmux.conf` or on the `vim-tmux-navigator.tmux` file). For example, to add the program `foobar`:
```diff
- is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
+ is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf|foobar)(diff)?$'"
```
#### Restoring Clear Screen (C-l)
The default key bindings include `<Ctrl-l>` which is the readline key binding
for clearing the screen. The following binding can be added to your `~/.tmux.conf` file to provide an alternate mapping to `clear-screen`.
``` tmux
bind C-l send-keys 'C-l'
```
With this enabled you can use `<prefix> C-l` to clear the screen.
Thanks to [Brian Hogan][] for the tip on how to re-map the clear screen binding.
#### Restoring SIGQUIT (C-\\)
The default key bindings also include `<Ctrl-\>` which is the default method of
sending SIGQUIT to a foreground process. Similar to "Clear Screen" above, a key
binding can be created to replicate SIGQUIT in the prefix table.
``` tmux
bind C-\\ send-keys 'C-\'
```
Alternatively, you can exclude the previous pane key binding from your `~/.tmux.conf`. If using TPM, the following line can be used to unbind the previous pane binding set by the plugin.
``` tmux
unbind -n C-\\
```
#### Disable Wrapping
By default, if you try to move past the edge of the screen, tmux/vim will
"wrap" around to the opposite side. To disable this, you'll need to
configure both tmux and vim:
For vim, you only need to enable this option:
```vim
let g:tmux_navigator_no_wrap = 1
```
Tmux doesn't have an option, so whatever key bindings you have need to be set
to conditionally wrap based on position on screen:
```tmux
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" { send-keys C-h } { if-shell -F '#{pane_at_left}' {} { select-pane -L } }
bind-key -n 'C-j' if-shell "$is_vim" { send-keys C-j } { if-shell -F '#{pane_at_bottom}' {} { select-pane -D } }
bind-key -n 'C-k' if-shell "$is_vim" { send-keys C-k } { if-shell -F '#{pane_at_top}' {} { select-pane -U } }
bind-key -n 'C-l' if-shell "$is_vim" { send-keys C-l } { if-shell -F '#{pane_at_right}' {} { select-pane -R } }
bind-key -T copy-mode-vi 'C-h' if-shell -F '#{pane_at_left}' {} { select-pane -L }
bind-key -T copy-mode-vi 'C-j' if-shell -F '#{pane_at_bottom}' {} { select-pane -D }
bind-key -T copy-mode-vi 'C-k' if-shell -F '#{pane_at_top}' {} { select-pane -U }
bind-key -T copy-mode-vi 'C-l' if-shell -F '#{pane_at_right}' {} { select-pane -R }
```
#### Nesting
If you like to nest your tmux sessions, this plugin is not going to work
properly. It probably never will, as it would require detecting when Tmux would
wrap from one outermost pane to another and propagating that to the outer
session.
By default this plugin works on the outermost tmux session and the vim
sessions it contains, but you can customize the behaviour by adding more
commands to the expression used by the grep command.
When nesting tmux sessions via ssh or mosh, you could extend it to look like
`'(^|\/)g?(view|vim|ssh|mosh?)(diff)?$'`, which makes this plugin work within
the innermost tmux session and the vim sessions within that one. This works
better than the default behaviour if you use the outer Tmux sessions as relays
to different hosts and have all instances of vim on remote hosts.
Similarly, if you like to nest tmux locally, add `|tmux` to the expression.
This behaviour means that you can't leave the innermost session with Ctrl-hjkl
directly. These following fallback mappings can be targeted to the right Tmux
session by escaping the prefix (Tmux' `send-prefix` command).
``` tmux
bind -r C-h run "tmux select-pane -L"
bind -r C-j run "tmux select-pane -D"
bind -r C-k run "tmux select-pane -U"
bind -r C-l run "tmux select-pane -R"
bind -r C-\ run "tmux select-pane -l"
```
Another workaround is to configure tmux on the outer machine to send keys to
the inner tmux session:
```
bind-key -n 'M-h' 'send-keys c-h'
bind-key -n 'M-j' 'send-keys c-j'
bind-key -n 'M-k' 'send-keys c-k'
bind-key -n 'M-l' 'send-keys c-l'
```
Here we bind "meta" key (aka "alt" or "option" key) combinations for each of
the four directions and send those along to the innermost session via
`send-keys`. You use the normal `C-h,j,k,l` while in the outermost session and
the alternative bindings to navigate the innermost session. Note that if you
use the example above on a Mac, you may need to configure your terminal app to
get the option key to work like a normal meta key. Consult your terminal app's
manual for details.
A third possible solution is to manually prevent the outermost tmux session
from intercepting the navigation keystrokes by disabling the prefix table:
```
set -g pane-active-border-style 'fg=#000000,bg=#ffff00'
bind -T root F12 \
set prefix None \;\
set key-table off \;\
if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
set -g pane-active-border-style 'fg=#000000,bg=#00ff00'
refresh-client -S \;\
bind -T off F12 \
set -u prefix \;\
set -u key-table \;\
set -g pane-active-border-style 'fg=#000000,bg=#ffff00'
refresh-client -S
```
This code, added to the machine running the outermost tmux session, toggles the
outermost prefix table on and off with the `F12` key. When off, the active
pane's border changes to green to indicate that the inner session receives
navigation keystrokes. When toggled back on, the border returns to yellow and
normal operation resumes and the outermost responds to the nav keystrokes.
The code example above also toggles the prefix key (ctrl-b by default) for the
outer session so that same prefix can be temporarily used on the inner session
instead of having to use a different prefix (ctrl-a by default) which you may
find convenient. If not, simply remove the lines that set/unset the prefix key
from the code example above.
Troubleshooting
---------------
### Vim -> Tmux doesn't work!
This is likely due to conflicting key mappings in your `~/.vimrc`. You can check
this by running `:verbose nmap <C-h>` (similar for each of the key bindings).
You should see vim-tmux-runner as the source listed for the key binding, but if
you see something else, you've got a conflict and will need to remove the other
key binding or otherwise restructure your vim config.
Another option is that the pattern matching included in the `.tmux.conf` is
not recognizing that Vim is active. To check that tmux is properly recognizing
Vim, use the provided Vim command `:TmuxNavigatorProcessList`. The output of
that command should be a list like:
```
Ss -zsh
S+ vim
S+ tmux
```
If you encounter a different output please [open an issue][] with as much info
about your OS, Vim version, and tmux version as possible.
[open an issue]: https://github.com/christoomey/vim-tmux-navigator/issues/new
### Tmux Can't Tell if Vim Is Active
This functionality requires tmux version 1.8 or higher. You can check your
version to confirm with this shell command:
``` bash
tmux -V # should return 'tmux 1.8'
```
### Switching out of Vim Is Slow
If you find that navigation within Vim (from split to split) is fine, but Vim
to a non-Vim tmux pane is delayed, it might be due to a slow shell startup.
Consider moving code from your shell's non-interactive rc file (e.g.,
`~/.zshenv`) into the interactive startup file (e.g., `~/.zshrc`) as Vim only
sources the non-interactive config.
### It doesn't work in Vim's `terminal` mode
Terminal mode is currently unsupported as adding this plugin's mappings there
causes conflict with movement mappings for FZF (it also uses terminal mode).
There's a conversation about this in https://github.com/christoomey/vim-tmux-navigator/pull/172
### It Doesn't Work in tmate
[tmate][] is a tmux fork that aids in setting up remote pair programming
sessions. It is designed to run alongside tmux without issue, but occasionally
there are hiccups. Specifically, if the versions of tmux and tmate don't match,
you can have issues. See [this
issue](https://github.com/christoomey/vim-tmux-navigator/issues/27) for more
detail.
[tmate]: http://tmate.io/
### Switching between host panes doesn't work when docker is running
Images built from minimalist OSes may not have the `ps` command or have a
simpler version of the command that is not compatible with this plugin.
Try installing the `procps` package using the appropriate package manager
command. For Alpine, you would do `apk add procps`.
If this doesn't solve your problem, you can also try the following:
Replace the `is_vim` variable in your `~/.tmux.conf` file with:
```tmux
if-shell '[ -f /.dockerenv ]' \
"is_vim=\"ps -o state=,comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'\""
# Filter out docker instances of nvim from the host system to prevent
# host from thinking nvim is running in a pseudoterminal when its not.
"is_vim=\"ps -o state=,comm=,cgroup= -t '#{pane_tty}' \
| grep -ivE '^.+ +.+ +.+\\/docker\\/.+$' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)? +'\""
```
Details: The output of the ps command on the host system includes processes
running within containers, but containers have their own instances of
/dev/pts/\*. vim-tmux-navigator relies on /dev/pts/\* to determine if vim is
running, so if vim is running in say /dev/pts/<N> in a container and there is a
tmux pane (not running vim) in /dev/pts/<N> on the host system, then without
the patch above vim-tmux-navigator will think vim is running when its not.
### It Still Doesn't Work!!!
The tmux configuration uses an inlined grep pattern match to help determine if
the current pane is running Vim. If you run into any issues with the navigation
not happening as expected, you can try using [Mislav's original external
script][] which has a more robust check.
[Brian Hogan]: https://twitter.com/bphogan
[Mislav's original external script]: https://github.com/mislav/dotfiles/blob/master/bin/tmux-vim-select-pane
[Vundle]: https://github.com/gmarik/vundle
[TPM]: https://github.com/tmux-plugins/tpm
[configuration section below]: #custom-key-bindings
[this blog post]: http://www.codeography.com/2013/06/19/navigating-vim-and-tmux-splits
[this gist]: https://gist.github.com/mislav/5189704

View File

@ -0,0 +1,39 @@
*tmux-navigator.txt* Plugin to allow seamless navigation between tmux and vim
==============================================================================
CONTENTS *tmux-navigator-contents*
==============================================================================
INTRODUCTION *tmux-navigator*
Vim-tmux-navigator is a little plugin which enables seamless navigation
between tmux panes and vim splits. This plugin is a repackaging of Mislav
Marohinc's tmux=navigator configuration. When combined with a set of tmux key
bindings, the plugin will allow you to navigate seamlessly between vim and
tmux splits using a consistent set of hotkeys.
NOTE: This requires tmux v1.8 or higher.
==============================================================================
CONFIGURATION *tmux-navigator-configuration*
* Activate autoupdate on exit
let g:tmux_navigator_save_on_switch = 1
* Disable vim->tmux navigation when the Vim pane is zoomed in tmux
let g:tmux_navigator_disable_when_zoomed = 1
* If the Vim pane is zoomed, stay zoomed when moving to another tmux pane
let g:tmux_navigator_preserve_zoom = 1
* Custom Key Bindings
let g:tmux_navigator_no_mappings = 1
noremap <silent> {Left-mapping} :<C-U>TmuxNavigateLeft<cr>
noremap <silent> {Down-Mapping} :<C-U>TmuxNavigateDown<cr>
noremap <silent> {Up-Mapping} :<C-U>TmuxNavigateUp<cr>
noremap <silent> {Right-Mapping} :<C-U>TmuxNavigateRight<cr>
noremap <silent> {Previous-Mapping} :<C-U><C-U>TmuxNavigatePrevious<cr>
vim:tw=78:ts=8:ft=help:norl:

View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Collection of various test strings that could be the output of the tmux
# 'pane_current_comamnd' message. Included as regression test for updates to
# the inline grep pattern used in the `.tmux.conf` configuration
set -e
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
NORMAL=$(tput sgr0)
vim_pattern='(^|\/)g?(view|l?n?vim?x?|fzf)(diff)?$'
match_tests=(vim Vim VIM vimdiff lvim /usr/local/bin/vim vi gvim view gview nvim vimx fzf)
no_match_tests=( /Users/christoomey/.vim/thing /usr/local/bin/start-vim )
display_matches() {
for process_name in "$@"; do
printf "%s %s\n" "$(matches_vim_pattern $process_name)" "$process_name"
done
}
matches_vim_pattern() {
if echo "$1" | grep -iqE "$vim_pattern"; then
echo "${GREEN}match${NORMAL}"
else
echo "${RED}fail${NORMAL}"
fi
}
main() {
echo "Testing against pattern: ${YELLOW}$vim_pattern${NORMAL}\n"
echo "These should all ${GREEN}match${NORMAL}\n----------------------"
display_matches "${match_tests[@]}"
echo "\nThese should all ${RED}fail${NORMAL}\n---------------------"
display_matches "${no_match_tests[@]}"
}
main

View File

@ -0,0 +1,140 @@
" Maps <C-h/j/k/l> to switch vim splits in the given direction. If there are
" no more windows in that direction, forwards the operation to tmux.
" Additionally, <C-\> toggles between last active vim splits/tmux panes.
if exists("g:loaded_tmux_navigator") || &cp || v:version < 700
finish
endif
let g:loaded_tmux_navigator = 1
function! s:VimNavigate(direction)
try
execute 'wincmd ' . a:direction
catch
echohl ErrorMsg | echo 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits: wincmd k' | echohl None
endtry
endfunction
if !get(g:, 'tmux_navigator_no_mappings', 0)
noremap <silent> <c-h> :<C-U>TmuxNavigateLeft<cr>
noremap <silent> <c-j> :<C-U>TmuxNavigateDown<cr>
noremap <silent> <c-k> :<C-U>TmuxNavigateUp<cr>
noremap <silent> <c-l> :<C-U>TmuxNavigateRight<cr>
noremap <silent> <c-\> :<C-U>TmuxNavigatePrevious<cr>
endif
if empty($TMUX)
command! TmuxNavigateLeft call s:VimNavigate('h')
command! TmuxNavigateDown call s:VimNavigate('j')
command! TmuxNavigateUp call s:VimNavigate('k')
command! TmuxNavigateRight call s:VimNavigate('l')
command! TmuxNavigatePrevious call s:VimNavigate('p')
finish
endif
command! TmuxNavigateLeft call s:TmuxAwareNavigate('h')
command! TmuxNavigateDown call s:TmuxAwareNavigate('j')
command! TmuxNavigateUp call s:TmuxAwareNavigate('k')
command! TmuxNavigateRight call s:TmuxAwareNavigate('l')
command! TmuxNavigatePrevious call s:TmuxAwareNavigate('p')
if !exists("g:tmux_navigator_save_on_switch")
let g:tmux_navigator_save_on_switch = 0
endif
if !exists("g:tmux_navigator_disable_when_zoomed")
let g:tmux_navigator_disable_when_zoomed = 0
endif
if !exists("g:tmux_navigator_preserve_zoom")
let g:tmux_navigator_preserve_zoom = 0
endif
if !exists("g:tmux_navigator_no_wrap")
let g:tmux_navigator_no_wrap = 0
endif
let s:pane_position_from_direction = {'h': 'left', 'j': 'bottom', 'k': 'top', 'l': 'right'}
function! s:TmuxOrTmateExecutable()
return (match($TMUX, 'tmate') != -1 ? 'tmate' : 'tmux')
endfunction
function! s:TmuxVimPaneIsZoomed()
return s:TmuxCommand("display-message -p '#{window_zoomed_flag}'") == 1
endfunction
function! s:TmuxSocket()
" The socket path is the first value in the comma-separated list of $TMUX.
return split($TMUX, ',')[0]
endfunction
function! s:TmuxCommand(args)
let cmd = s:TmuxOrTmateExecutable() . ' -S ' . s:TmuxSocket() . ' ' . a:args
let l:x=&shellcmdflag
let &shellcmdflag='-c'
let retval=system(cmd)
let &shellcmdflag=l:x
return retval
endfunction
function! s:TmuxNavigatorProcessList()
echo s:TmuxCommand("run-shell 'ps -o state= -o comm= -t ''''#{pane_tty}'''''")
endfunction
command! TmuxNavigatorProcessList call s:TmuxNavigatorProcessList()
let s:tmux_is_last_pane = 0
augroup tmux_navigator
au!
autocmd WinEnter * let s:tmux_is_last_pane = 0
augroup END
function! s:NeedsVitalityRedraw()
return exists('g:loaded_vitality') && v:version < 704 && !has("patch481")
endfunction
function! s:ShouldForwardNavigationBackToTmux(tmux_last_pane, at_tab_page_edge)
if g:tmux_navigator_disable_when_zoomed && s:TmuxVimPaneIsZoomed()
return 0
endif
return a:tmux_last_pane || a:at_tab_page_edge
endfunction
function! s:TmuxAwareNavigate(direction)
let nr = winnr()
let tmux_last_pane = (a:direction == 'p' && s:tmux_is_last_pane)
if !tmux_last_pane
call s:VimNavigate(a:direction)
endif
let at_tab_page_edge = (nr == winnr())
" Forward the switch panes command to tmux if:
" a) we're toggling between the last tmux pane;
" b) we tried switching windows in vim but it didn't have effect.
if s:ShouldForwardNavigationBackToTmux(tmux_last_pane, at_tab_page_edge)
if g:tmux_navigator_save_on_switch == 1
try
update " save the active buffer. See :help update
catch /^Vim\%((\a\+)\)\=:E32/ " catches the no file name error
endtry
elseif g:tmux_navigator_save_on_switch == 2
try
wall " save all the buffers. See :help wall
catch /^Vim\%((\a\+)\)\=:E141/ " catches the no file name error
endtry
endif
let args = 'select-pane -t ' . shellescape($TMUX_PANE) . ' -' . tr(a:direction, 'phjkl', 'lLDUR')
if g:tmux_navigator_preserve_zoom == 1
let l:args .= ' -Z'
endif
if g:tmux_navigator_no_wrap == 1
let args = 'if -F "#{pane_at_' . s:pane_position_from_direction[a:direction] . '}" "" "' . args . '"'
endif
silent call s:TmuxCommand(args)
if s:NeedsVitalityRedraw()
redraw!
endif
let s:tmux_is_last_pane = 1
else
let s:tmux_is_last_pane = 0
endif
endfunction

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
version_pat='s/^tmux[^0-9]*([.0-9]+).*/\1/p'
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
tmux bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
tmux bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
tmux bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
tmux bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
tmux_version="$(tmux -V | sed -En "$version_pat")"
tmux setenv -g tmux_version "$tmux_version"
#echo "{'version' : '${tmux_version}', 'sed_pat' : '${version_pat}' }" > ~/.tmux_version.json
tmux if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
tmux if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
tmux bind-key -T copy-mode-vi C-h select-pane -L
tmux bind-key -T copy-mode-vi C-j select-pane -D
tmux bind-key -T copy-mode-vi C-k select-pane -U
tmux bind-key -T copy-mode-vi C-l select-pane -R
tmux bind-key -T copy-mode-vi C-\\ select-pane -l