Merge pull request #3 from kforney/master

Add autologin and custom tmux config.

Former-commit-id: ed5abccdb9
Former-commit-id: 94b3c0da296c9c9ae68ab97d29c62835a6c08867
This commit is contained in:
Don Bowers 2018-09-28 14:59:53 -06:00 committed by GitHub
commit a1a542d3fb
173 changed files with 7845 additions and 0 deletions

View file

@ -0,0 +1 @@
63afacef10d1b276bb5627477bc6d03ebd15e708

View file

@ -0,0 +1,33 @@
# GDM configuration storage - modified by kali-root-login
#
# See /usr/share/gdm/gdm.schemas for a list of available options.
[daemon]
# Enabling automatic login
AutomaticLoginEnable = true
AutomaticLogin = root
# Enabling timed login
# TimedLoginEnable = true
# TimedLogin = user1
# TimedLoginDelay = 10
# Reserving more VTs for test consoles (default is 7)
# FirstVT = 9
[security]
AllowRoot = true
[xdmcp]
[greeter]
# Only include selected logins in the greeter
# IncludeAll = false
# Include = user1,user2
[chooser]
[debug]
# More verbose logs
# Additionally lets the X server dump core if it crashes
# Enable = true

View file

@ -0,0 +1,79 @@
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @plugin 'tmux-plugins/tmux-net-speed'
#set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
#If you don't want TMUX Resurrect, comment these three out...
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
set -g mouse off
# panes
set -g pane-border-fg black
set -g pane-active-border-fg brightred
## Status bar design
# status line
# set -g status-utf8 on
set -g status-justify left
set -g status-interval 2
# Info on left (I don't have a session display for now)
set -g status-left ''
# loud or quiet?
set-option -g visual-activity off
set-option -g visual-bell off
set-option -g visual-silence off
set-window-option -g monitor-activity off
set-option -g bell-action none
set -g default-terminal "screen-256color"
# The modes {
setw -g clock-mode-colour colour135
setw -g mode-attr bold
# }
# The panes {
# }
# The statusbar {
set -g @net_speed_interfaces "enp3s0f2 wlp2s0"
set -g @download_speed_format "%10s"
set -g @upload_speed_format "%10s"
set -g @net_speed_format "D:%10s U:%10s"
set -g status-position bottom
set -g status-attr dim
set -g status-left '#{prefix_highlight}'
set -g status-right 'CPU: #{cpu_percentage} | #[fg=colour233,bg=colour245,bold] #H | %H:%M:%S '
set -g status-right-length 50
set -g status-left-length 20
setw -g window-status-current-attr bold
setw -g window-status-attr none
setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '
setw -g window-status-bell-attr bold
setw -g window-status-bell-fg colour255
setw -g window-status-bell-bg colour1
# }
# The messages {
set -g message-attr bold
# }
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

View file

@ -0,0 +1,41 @@
# Changelog
### master
- Added `#{battery_status_bg}` feature (@RyanFrantz)
- Added multibattery output support for `upower` (@futuro)
- Added Chromebook support (@forkjoseph)
- Added battery graph, simplify interpolation (@levens)
### v1.2.0, 2016-09-24
- show output for `#{battery_remain}` interpolation only if the battery is
discharging
- prevent displaying "(No" for `#{battery_remain}` interpolation (when battery
status is "No estimate"
- display all batteries that upower knows about (@JanAhrens)
- acpi battery status (@cpb)
- fix issue with status-right and status-left whitespace being cut out
- fix issue with the `pmset -g batt` command output for macOS Sierra and further
### v1.1.0, 2015-03-14
- change the default icon for "attached" battery state from :snail: to :warning:
- add support for OS X "attached" battery state (@m1foley)
- add `#{battery_remain}` feature (@asethwright)
### v1.0.0, 2014-08-31
- update readme to reflect github organization change
- bring in linux support
- small refactoring
- rename plugin to tmux-battery
- add contributors to the readme
### v0.0.2, 2014-06-03
- switch to tab indentation
- do not automatically prepend battery status
- change format interpolation strings to more Tmux-idiomatic
`#{battery_percentage}` and `#{battery_icon}`
- refactoring for simplicity
- support interpolation in `status-left` option too
- README update
### v0.0.1, 2014-06-03
- tag version 0.0.1

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,128 @@
# Tmux battery status
Enables displaying battery percentage and status icon in tmux status-right.
## Installation
### Intallation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Add plugin to the list of TPM plugins in `.tmux.conf`:
set -g @plugin 'tmux-plugins/tmux-battery'
Hit `prefix + I` to fetch the plugin and source it.
If format strings are added to `status-right`, they should now be visible.
### Manual Installation
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-battery ~/clone/path
Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/battery.tmux
Reload TMUX environment:
# type this in terminal
$ tmux source-file ~/.tmux.conf
If format strings are added to `status-right`, they should now be visible.
## Usage
Add `#{battery_icon}`, `#{battery_percentage}` `#{battery_remain}`, or
`#{battery_status_bg}` format strings to existing `status-right` tmux option.
Example:
# in .tmux.conf
set -g status-right '#{battery_status_bg} Batt: #{battery_icon} #{battery_percentage} #{battery_remain} | %a %h-%d %H:%M '
## Examples
Battery full (for OS X):<br/>
![battery full](/screenshots/battery_full.png)
Battery discharging, custom discharge icon:<br/>
![battery discharging, custom icon](/screenshots/battery_discharging.png)
Battery charging:<br/>
![battery charging](/screenshots/battery_charging.png)
Battery remain:<br/>
![battery remain](/screenshots/battery_remain.png)
Battery fully charged:<br/>
![battery_status_bg_green](/screenshots/battery_status_bg_green.png)
Battery between 99% and 51% charged:<br/>
![battery_status_bg_yellow](/screenshots/battery_status_bg_yellow.png)
Battery between 50% and 16% charged:<br/>
![battery_status_bg_orange](/screenshots/battery_status_bg_orange.png)
Battery between 15% and dead:<br/>
![battery_status_bg_red](/screenshots/battery_status_bg_red.png)
This is done by introducing 4 new format strings that can be added to
`status-right` option:
- `#{battery_icon}` - will display a battery status icon
- `#{battery_percentage}` - will show battery percentage
- `#{battery_remain}` - will show remaining time of battery charge
- `#{battery_status_bg}` - will set the background color of the status bar based on the battery percentage
- `#{battery_status_fg}` - will set the foreground color of the status bar based on the battery percentage
- `#{battery_graph}` - will show battery percentage as a bar graph ▁▂▃▅▇
## Changing icons
By default, these icons are displayed:
- charged: ":battery:" ("❇ " when not on OS X)
- charging: ":zap:"
- discharging: (nothing shown)
- attached but not charging: ":warning:"
You can change these defaults by adding the following to `.tmux.conf` (the
following lines are not in the code block so that emojis can be seen):
- set -g @batt_charged_icon ":sunglasses:"
- set -g @batt_charging_icon ":+1:"
- set -g @batt_discharging_icon ":thumbsdown:"
- set -g @batt_attached_icon ":neutral_face:"
Don't forget to reload tmux environment (`$ tmux source-file ~/.tmux.conf`)
after you do this.
*Warning*: The battery icon change most likely will not be instant. When you un-plug the power cord, it will take some time (15 - 60 seconds) for the icon to change. This depends on the `status-interval` tmux option. Setting it to 15 seconds should be good enough.
### Tmux Plugins
This plugin is part of the [tmux-plugins](https://github.com/tmux-plugins) organisation. Checkout plugins as [resurrect](https://github.com/tmux-plugins/tmux-resurrect), [logging](https://github.com/tmux-plugins/tmux-logging), [online status](https://github.com/tmux-plugins/tmux-online-status), and many more over at the [tmux-plugins](https://github.com/tmux-plugins) organisation page.
You might want to follow [@brunosutic](https://twitter.com/brunosutic) on
twitter if you want to hear about new tmux plugins or feature updates.
### Maintainer
- [Martin Beentjes](https://github.com/martinbeentjes)
### Contributors
- Adam Biggs
- Aleksandar Djurdjic
- Bruno Sutic
- Caleb
- Evan N-D
- Jan Ahrens
- Joey Geralnik
- Joseph
- Martin Beentjes
- Mike Foley
- Ryan Frantz
- Seth Wright
- Tom Levens
### License
[MIT](LICENSE.md)

View file

@ -0,0 +1,49 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/helpers.sh"
battery_interpolation=(
"\#{battery_percentage}"
"\#{battery_remain}"
"\#{battery_icon}"
"\#{battery_status_bg}"
"\#{battery_status_fg}"
"\#{battery_graph}"
)
battery_commands=(
"#($CURRENT_DIR/scripts/battery_percentage.sh)"
"#($CURRENT_DIR/scripts/battery_remain.sh)"
"#($CURRENT_DIR/scripts/battery_icon.sh)"
"#($CURRENT_DIR/scripts/battery_status_bg.sh)"
"#($CURRENT_DIR/scripts/battery_status_fg.sh)"
"#($CURRENT_DIR/scripts/battery_graph.sh)"
)
set_tmux_option() {
local option="$1"
local value="$2"
tmux set-option -gq "$option" "$value"
}
do_interpolation() {
local all_interpolated="$1"
for ((i=0; i<${#battery_commands[@]}; i++)); do
all_interpolated=${all_interpolated/${battery_interpolation[$i]}/${battery_commands[$i]}}
done
echo "$all_interpolated"
}
update_tmux_option() {
local option="$1"
local option_value="$(get_tmux_option "$option")"
local new_option_value="$(do_interpolation "$option_value")"
set_tmux_option "$option" "$new_option_value"
}
main() {
update_tmux_option "status-right"
update_tmux_option "status-left"
}
main

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 KiB

View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
print_graph() {
if [ -z "$1" ]; then
echo ""
elif [ "$1" -lt "20" ]; then
echo "▁"
elif [ "$1" -lt "40" ]; then
echo "▂"
elif [ "$1" -lt "60" ]; then
echo "▃"
elif [ "$1" -lt "80" ]; then
echo "▅"
else
echo "▇"
fi
}
main() {
local percentage=$($CURRENT_DIR/battery_percentage.sh)
print_graph ${percentage%?}
}
main

View file

@ -0,0 +1,53 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
charged_icon=""
charging_icon=""
attached_icon=""
discharging_icon=""
charged_default="❇ "
charged_default_osx="🔋 "
charging_default="⚡️ "
attached_default="⚠️ "
discharging_default=""
charged_default() {
if is_osx; then
echo "$charged_default_osx"
else
echo "$charged_default"
fi
}
# icons are set as script global variables
get_icon_settings() {
charged_icon=$(get_tmux_option "@batt_charged_icon" "$(charged_default)")
charging_icon=$(get_tmux_option "@batt_charging_icon" "$charging_default")
attached_icon=$(get_tmux_option "@batt_attached_icon" "$attached_default")
discharging_icon=$(get_tmux_option "@batt_discharging_icon" "$discharging_default")
}
print_icon() {
local status=$1
if [[ $status =~ (charged) ]]; then
printf "$charged_icon"
elif [[ $status =~ (^charging) ]]; then
printf "$charging_icon"
elif [[ $status =~ (^discharging) ]]; then
printf "$discharging_icon"
elif [[ $status =~ (attached) ]]; then
printf "$attached_icon"
fi
}
main() {
get_icon_settings
local status=$(battery_status)
print_icon "$status"
}
main

View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
print_battery_percentage() {
# percentage displayed in the 2nd field of the 2nd row
if command_exists "pmset"; then
pmset -g batt | grep -o "[0-9]\{1,3\}%"
elif command_exists "upower"; then
local batteries=( $(upower -e | grep battery) )
local energy
local energy_full
for battery in ${batteries[@]}; do
energy=$(upower -i $battery | awk -v nrg="$energy" '/energy:/ {print nrg+$2}')
energy_full=$(upower -i $battery | awk -v nrgfull="$energy_full" '/energy-full:/ {print nrgfull+$2}')
done
echo $energy $energy_full | awk '{printf("%d%%", ($1/$2)*100)}'
elif command_exists "acpi"; then
acpi -b | grep -Eo "[0-9]+%"
fi
}
main() {
print_battery_percentage
}
main

View file

@ -0,0 +1,49 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
battery_discharging() {
local status="$(battery_status)"
[[ $status =~ (discharging) ]]
}
pmset_battery_remaining_time() {
pmset -g batt | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}'
}
print_battery_remain() {
if command_exists "pmset"; then
pmset_battery_remaining_time
elif command_exists "upower"; then
battery=$(upower -e | grep battery | head -1)
if is_chrome; then
if battery_discharging; then
upower -i $battery | grep 'time to empty' | awk '{printf "- %s %s left", $4, $5}'
else
upower -i $battery | grep 'time to full' | awk '{printf "- %s %s till full", $4, $5}'
fi
else
upower -i $battery | grep -E '(remain|time to empty)' | awk '{print $(NF-1)}'
fi
elif command_exists "acpi"; then
acpi -b | grep -Eo "[0-9]+:[0-9]+:[0-9]+"
fi
}
print_battery_full() {
if command_exists "upower"; then
battery=$(upower -e | grep battery | head -1)
upower -i $battery | grep 'time to full' | awk '{printf "- %s %s till full", $4, $5}'
fi
}
main() {
if battery_discharging; then
print_battery_remain
else
print_battery_full
fi
}
main

View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
color_full_charge_default="#[bg=green]"
color_high_charge_default="#[bg=yellow]"
color_medium_charge_default="#[bg=colour208]" # orange
color_low_charge_default="#[bg=red]"
color_full_charge=""
color_high_charge=""
color_medium_charge=""
color_low_charge=""
get_charge_color_settings() {
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
}
print_battery_status_bg() {
# Call `battery_percentage.sh`.
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
if [ $percentage -eq 100 ]; then
printf $color_full_charge
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
printf $color_high_charge
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
printf $color_medium_charge
else
printf $color_low_charge
fi
}
main() {
get_charge_color_settings
print_battery_status_bg
}
main

View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
color_full_charge_default="#[fg=green]"
color_high_charge_default="#[fg=yellow]"
color_medium_charge_default="#[fg=colour208]" # orange
color_low_charge_default="#[fg=red]"
color_full_charge=""
color_high_charge=""
color_medium_charge=""
color_low_charge=""
get_charge_color_settings() {
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
}
print_battery_status_fg() {
# Call `battery_percentage.sh`.
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
if [ $percentage -eq 100 ]; then
printf $color_full_charge
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
printf $color_high_charge
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
printf $color_medium_charge
else
printf $color_low_charge
fi
}
main() {
get_charge_color_settings
print_battery_status_fg
}
main

View file

@ -0,0 +1,41 @@
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
}
is_osx() {
[ $(uname) == "Darwin" ]
}
is_chrome() {
chrome="/sys/class/chromeos/cros_ec"
if [ -d "$chrome" ]; then
return 0
else
return 1
fi
}
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1
}
battery_status() {
if command_exists "pmset"; then
pmset -g batt | awk -F '; *' 'NR==2 { print $2 }'
elif command_exists "upower"; then
# sort order: attached, charging, discharging
for battery in $(upower -e | grep battery); do
upower -i $battery | grep state | awk '{print $2}'
done | sort | head -1
elif command_exists "acpi"; then
acpi -b | grep -oi 'discharging' | awk '{print tolower($0)}'
fi
}

View file

@ -0,0 +1,42 @@
# Changelog
### master
### v3.1.0, 2015-03-14
- properly quote scripts
- bugfix: "auto restore" feature does not work on tmux `1.9a`
- bugfix: do not count `tmux source-file .tmux.conf` as a tmux process (when
checking if other tmux server is running). Previously, this caused
interpolation command not to be inserted into `status-right` because `tmux
source-file` was falsely detected as another tmux server.
- add `#{continuum_status}` status line interpolation
### v3.0.0, 2015-02-20
- rename the plugin from `tmux-resurrect-auto` to `tmux-continuum`
### v2.2.0, 2015-02-20
- document tmux multi-server behavior in the readme
- do not auto-restore tmux environment if another tmux server is already running
(we don't want to duplicate stuff)
- bugfixes for 'tmux auto start' OS X Terminal.app and iTerm scripts
- prevent saving for the first 15 minutes only when plugin is sourced the first
time (not on subsequent sources or tmux.conf reloads)
- do not start auto-saving if there's another tmux server running (we don't want
for save files from various tmux environments to override each other)
### v2.1.0, 2015-02-18
- enable "tmux auto start" for OS X
- enable customizing "tmux auto start" for OS X
- fix errors when creating a launchd plist file for auto-start on OS X
### v2.0.0, 2015-02-15
- enable automatic environment restore when tmux is started
### v1.0.0, 2015-02-12
- first working version
- run the save script in the background
- do not start saving right after tmux is started
- add a check for tmux version to the initializer script
- when interval is set to '0' autosave is disabled
- bugfix: helper files not loaded
- update readme with the instructions how to disable auto saving

View file

@ -0,0 +1,15 @@
### Contributing
Code contributions are welcome!
If you wanna contribute a bigger feature, please open a github issue so we can
discuss it together first.
### Reporting a bug
If you find a bug please report it in the issues. When reporting a bug please
attach:
- a file symlinked to `~/.tmux/resurrect/last`.
- your `.tmux.conf`
- if you're getting an error paste it to a [gist](https://gist.github.com/) and
link it in the issue

View file

@ -0,0 +1,19 @@
Copyright (C) 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-continuum
Features:
- continuous saving of tmux environment
- automatic tmux start when computer/server is turned on
- automatic restore when tmux is started
Together these features enable uninterrupted tmux usage. No matter the computer
or server restarts, if the machine is on, tmux will be there how you left it off
the last time it was used.
Tested and working on Linux, OSX and Cygwin.
#### Continuous saving
Tmux environment will be saved at the interval of 15 minutes. All the saving
happens in the background without the impact to your workflow.
This action starts automatically when the plugin is installed.
#### Automatic tmux start
Tmux is automatically started after the computer/server is turned on.
See the [instructions](docs/automatic_start.md) how to enable this for your
system.
#### Automatic restore
Last saved environment is automatically restored when tmux is started.
Put `set -g @continuum-restore 'on'` in `tmux.conf` to enable this.
Note: automatic restore happens **exclusively** on tmux server start. No other
action (e.g. sourcing `tmux.conf`) triggers this.
#### Dependencies
`tmux 1.9` or higher, `bash`,
[tmux-resurrect](https://github.com/tmux-plugins/tmux-resurrect) plugin.
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Please make sure you have
[tmux-resurrect](https://github.com/tmux-plugins/tmux-resurrect) installed.
Add plugin to the list of TPM plugins in `.tmux.conf`:
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
Hit `prefix + I` to fetch the plugin and source it. The plugin will
automatically start "working" in the background, no action required.
### Manual Installation
Please make sure you have
[tmux-resurrect](https://github.com/tmux-plugins/tmux-resurrect) installed.
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-continuum ~/clone/path
Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/continuum.tmux
Reload TMUX environment with: `$ tmux source-file ~/.tmux.conf`
The plugin will automatically start "working" in the background, no action
required.
### Docs
- [frequently asked questions](docs/faq.md)
- [behavior when running multiple tmux servers](docs/multiple_tmux_servers.md) -
this doc is safe to skip, but you might want to read it if you're using tmux
with `-L` or `-S` flags
- [automatically start tmux after the computer is turned on](docs/automatic_start.md)
- [continuum status in tmux status line](docs/continuum_status.md)
### Other goodies
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for
regex searches in tmux and fast match selection
- [tmux-yank](https://github.com/tmux-plugins/tmux-yank) - enables copying
highlighted text to system clipboard
- [tmux-open](https://github.com/tmux-plugins/tmux-open) - a plugin for quickly
opening highlighted file or a url
You might want to follow [@brunosutic](https://twitter.com/brunosutic) on
twitter if you want to hear about new tmux plugins or feature updates.
### Reporting bugs and contributing
Both contributing and bug reports are welcome. Please check out
[contributing guidelines](CONTRIBUTING.md).
### License
[MIT](LICENSE.md)

View file

@ -0,0 +1,92 @@
#!/usr/bin/env bash
set -x
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/helpers.sh"
source "$CURRENT_DIR/scripts/variables.sh"
source "$CURRENT_DIR/scripts/shared.sh"
save_command_interpolation="#($CURRENT_DIR/scripts/continuum_save.sh)"
supported_tmux_version_ok() {
"$CURRENT_DIR/scripts/check_tmux_version.sh" "$SUPPORTED_VERSION"
}
handle_tmux_automatic_start() {
"$CURRENT_DIR/scripts/handle_tmux_automatic_start.sh"
}
another_tmux_server_running() {
if just_started_tmux_server; then
another_tmux_server_running_on_startup
else
# script loaded after tmux server start can have multiple clients attached
[ "$(number_tmux_processes_except_current_server)" -gt "$(number_current_server_client_processes)" ]
fi
}
delay_saving_environment_on_first_plugin_load() {
if [ -z "$(get_tmux_option "$last_auto_save_option" "")" ]; then
# last save option not set, this is first time plugin load
set_last_save_timestamp
fi
}
add_resurrect_save_interpolation() {
local status_right_value="$(get_tmux_option "status-right" "")"
# check interpolation not already added
if ! [[ "$status_right_value" == *"$save_command_interpolation"* ]]; then
local new_value="${save_command_interpolation}${status_right_value}"
set_tmux_option "status-right" "$new_value"
fi
}
number_of_sessions() {
tmux list-sessions |
wc -l |
sed "s/ //g"
}
# when tmux server is first started, number of sessions is 0
just_started_tmux_server() {
[ "$(number_of_sessions)" -eq 0 ]
}
start_auto_restore_in_background() {
"$CURRENT_DIR/scripts/continuum_restore.sh" &
}
update_tmux_option() {
local option="$1"
local option_value="$(get_tmux_option "$option")"
# replace interpolation string with a script to execute
local new_option_value="${option_value/$status_interpolation_string/$status_script}"
set_tmux_option "$option" "$new_option_value"
}
main() {
if supported_tmux_version_ok; then
handle_tmux_automatic_start
# Advanced edge case handling: start auto-saving only if this is the
# only tmux server. We don't want saved files from more environments to
# overwrite each other.
if ! another_tmux_server_running; then
# give user a chance to restore previously saved session
delay_saving_environment_on_first_plugin_load
add_resurrect_save_interpolation
fi
if just_started_tmux_server; then
start_auto_restore_in_background
fi
# Put "#{continuum_status}" interpolation in status-right or
# status-left tmux option to get current tmux continuum status.
update_tmux_option "status-right"
update_tmux_option "status-left"
fi
}
main

View file

@ -0,0 +1,35 @@
# Automatic Tmux start
Tmux is automatically started after the computer/server is turned on.
### OS X
To enable this feature:
- put `set -g @continuum-boot 'on'` in `tmux.conf`
- reload tmux config with this shell command: `$ tmux source-file ~/.tmux.conf`
Next time the computer is started:
- `Terminal.app` window will open and resize to maximum size
- `tmux` command will be executed in the terminal window
- if "auto restore" feature is enabled, tmux will start restoring previous env
Config options:
- `set -g @continuum-boot-options 'fullscreen'` - terminal window
will go fullscreen
- `set -g @continuum-boot-options 'iterm'` - start `iTerm` instead
of `Terminal.app`
- `set -g @continuum-boot-options 'iterm,fullscreen'` - start `iTerm`
in fullscreen
### Linux
Help with this would be greatly appreciated. Please get in touch.
#### Systemd
##### this will only start the tmux server, it will *not* start any terminal emulator
To enable automatic start with systemd:
- Put `set -g @continuum-boot 'on'` in tmux.conf
- reload tmux config with this shell command: `$ tmux source-file ~/.tmux.conf`
- see [systemd](./systemd_details.md) for more details about how this is implemented

View file

@ -0,0 +1,17 @@
## Continuum status in tmux status line
There is an option to display current status of tmux continuum in tmux status
line. This is done via `#{continuum_status}` interpolation and it works with
both `status-right` and `status-left` tmux native options.
Example usage:
set -g status-right 'Continuum status: #{continuum_status}'
When running, `#{continuum_status}` will show continuum save interval:
Continuum status: 15
or if continuous saving is disabled:
Continuum status: off

View file

@ -0,0 +1,57 @@
### FAQ
> Will a previous save be overwritten immediately after I start tmux?
No, first automatic save starts 15 minutes after tmux is started. If automatic
restore is not enabled, that gives you enough time to manually restore from a
previous save.
> I want to make a restore to a previous point in time, but it seems that save
is now overwritten?
None of the previous saves are deleted (unless you explicitly do that). All save
files are kept in `~/.tmux/resurrect/` directory.<br/>
Here are the steps to restore to a previous point in time:
- make sure you start this with a "fresh" tmux instance
- `$ cd ~/.tmux/resurrect/`
- locate the save file you'd like to use for restore (file names have a timestamp)
- symlink the `last` file to the desired save file: `$ ln -sf <file_name> last`
- do a restore with `tmux-resurrect` key: `prefix + Ctrl-r`
You should now be restored to the time when `<file_name>` save happened.
> Will this plugin fill my hard disk?
Most likely no. A regular save file is in the range of 5Kb. That said, it
would be good to clean out old save files from `~/.tmux/resurrect/` dir from
time to time.
> How do I change the save interval to i.e. 1 hour?
The interval is always measured in minutes. So setting the interval to `60`
(minutes) will do the trick. Put this in `.tmux.conf`:
set -g @continuum-save-interval '60'
and then source `tmux.conf` by executing this command in the shell
`$ tmux source-file ~/.tmux.conf`.
> How do I stop automatic saving?
Just set the save interval to `0`. Put this in `.tmux.conf`
set -g @continuum-save-interval '0'
and then source `tmux.conf` by executing this command in the shell
`$ tmux source-file ~/.tmux.conf`.
> I had automatic restore turned on, how do I disable it now?
Just remove `set -g @continuum-restore 'on'` from `tmux.conf`.
To be absolutely sure automatic restore doesn't happen, create a
`tmux_no_auto_restore` file in your home directory (command:
`$ touch ~/tmux_no_auto_restore`). Automatic restore won't happen if this file
exists.

View file

@ -0,0 +1,20 @@
### Behavior when running multiple tmux servers
(This is safe to skip if you're always running a single tmux server.)
If you're an advanced tmux user, you might be running multiple tmux servers at
the same time. Maybe you start the first tmux server with `$ tmux` and then
later another one with e.g. `$ tmux -S/tmp/foo`.
You probably don't want to "auto restore" the same environment in the second
tmux that uses `/tmp/foo` socket. You also probably don't want two tmux
environments both having "auto save" feature on (think about overwrites).
This plugin handles multi-server scenario by giving precedence to the tmux
server that was first started.
In the above example, the server started with `$ tmux` will do "auto
restore" (if enabled) and will start "auto saving".
"Auto restore" or "auto saving" **will not** happen for the second server that
was started later with the `$ tmux -S/tmp/foo` command. The plugin will
detect the presence of another server (`$ tmux`) and give it precedence.

View file

@ -0,0 +1,13 @@
# Systemd automatic start for tmux
The first time tmux starts when `@continuum-boot` is set to 'on' tmux-continuum will generate a user level systemd unit file which it will save to `${HOME}/.config/systemd/user/tmux.service` and enable it. From then on when that user logs in, either through a GUI session or on the console or via ssh, Systemd will start the tmux server.
The command used to start the tmux server is determined via the `@continuum-systemd-start-cmd` option that can be set in .tmux.conf. (Remember to reload your configuration with `tmux source ~/.tmux.conf` afterwards.
The default command to use is `new-session -d`. If you want more control over what sessions get started then you should set up your sessions in tmux.conf and set `@continuum-systemd-start-cmd = 'start-server'`. As this will be executed as part of systemd's ExecStart statement there will be no shell parsing. See [Systemd manual](http://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines) for more details.
To control the tmux service you can use all the standard `systemctl` commands using the `--user` argument. eg to see if the tmux server has started:
systemctl --user status tmux.service

View file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
VERSION="$1"
UNSUPPORTED_MSG="$2"
# 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")"
}
exit_if_unsupported_version() {
local current_version="$1"
local supported_version="$2"
if [ "$current_version" -lt "$supported_version" ]; then
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,29 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/variables.sh"
auto_restore_enabled() {
local auto_restore_value="$(get_tmux_option "$auto_restore_option" "$auto_restore_default")"
[ "$auto_restore_value" == "on" ] && [ ! -f "$auto_restore_halt_file" ]
}
fetch_and_run_tmux_resurrect_restore_script() {
# give tmux some time to start and source all the plugins
sleep 1
local resurrect_restore_script_path="$(get_tmux_option "$resurrect_restore_path_option" "")"
if [ -n "$resurrect_restore_script_path" ]; then
"$resurrect_restore_script_path"
fi
}
main() {
# Advanced edge case handling: auto restore only if this is the only tmux
# server. If another tmux server exists, it is assumed auto-restore is not wanted.
if auto_restore_enabled && ! another_tmux_server_running_on_startup; then
fetch_and_run_tmux_resurrect_restore_script
fi
}
main

View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
supported_tmux_version_ok() {
"$CURRENT_DIR/check_tmux_version.sh" "$SUPPORTED_VERSION"
}
get_interval() {
get_tmux_option "$auto_save_interval_option" "$auto_save_interval_default"
}
auto_save_not_disabled() {
[ "$(get_interval)" -gt 0 ]
}
enough_time_since_last_run_passed() {
local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "0")"
local interval_minutes="$(get_interval)"
local interval_seconds="$((interval_minutes * 60))"
local next_run="$((last_saved_timestamp + $interval_seconds))"
[ "$(current_timestamp)" -ge "$next_run" ]
}
fetch_and_run_tmux_resurrect_save_script() {
local resurrect_save_script_path="$(get_tmux_option "$resurrect_save_path_option" "")"
if [ -n "$resurrect_save_script_path" ]; then
"$resurrect_save_script_path" "quiet" >/dev/null 2>&1 &
set_last_save_timestamp
fi
}
main() {
if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then
fetch_and_run_tmux_resurrect_save_script
fi
}
main

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/variables.sh"
print_status() {
local save_int="$(get_tmux_option "$auto_save_interval_option")"
local status=""
local style_wrap
if [ $save_int -gt 0 ]; then
style_wrap="$(get_tmux_option "$status_on_style_wrap_option" "")"
status="$save_int"
else
style_wrap="$(get_tmux_option "$status_off_style_wrap_option" "")"
status="off"
fi
if [ -n "$style_wrap" ]; then
status="${style_wrap/$status_wrap_string/$status}"
fi
echo "$status"
}
print_status

View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/variables.sh"
is_tmux_automatic_start_enabled() {
local auto_start_value="$(get_tmux_option "$auto_start_option" "$auto_start_default")"
[ "$auto_start_value" == "on" ]
}
is_osx() {
[ $(uname) == "Darwin" ]
}
is_systemd() {
[ $(ps -o comm= -p1) == 'systemd' ]
}
main() {
if is_tmux_automatic_start_enabled; then
if is_osx; then
"$CURRENT_DIR/handle_tmux_automatic_start/osx_enable.sh"
elif is_systemd; then
"$CURRENT_DIR/handle_tmux_automatic_start/systemd_enable.sh"
fi
else
if is_osx; then
"$CURRENT_DIR/handle_tmux_automatic_start/osx_disable.sh"
elif is_systemd; then
"$CURRENT_DIR/handle_tmux_automatic_start/systemd_disable.sh"
fi
fi
}
main

View file

@ -0,0 +1 @@
docs/automatic_start.md

View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/../variables.sh"
main() {
rm "$osx_auto_start_file_path" > /dev/null 2>&1
}
main

View file

@ -0,0 +1,66 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/../helpers.sh"
source "$CURRENT_DIR/../variables.sh"
template() {
local tmux_start_script="$1"
local is_fullscreen="$2"
local fullscreen_tag=""
if [ "$is_fullscreen" == "true" ]; then
# newline and spacing so tag is aligned with other tags in template
fullscreen_tag=$'\n <string>fullscreen</string>'
fi
local content
read -r -d '' content <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${osx_auto_start_file_name}</string>
<key>ProgramArguments</key>
<array>
<string>${tmux_start_script}</string>$fullscreen_tag
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
echo "$content"
}
get_iterm_or_teminal_option_value() {
local options="$1"
if [[ "$options" =~ "iterm" ]]; then
echo "iterm"
else
# Terminal.app is the default console app
echo "terminal"
fi
}
get_fullscreen_option_value() {
local options="$1"
if [[ "$options" =~ "fullscreen" ]]; then
echo "true"
else
echo "false"
fi
}
main() {
local options="$(get_tmux_option "$auto_start_config_option" "$auto_start_config_default")"
local iterm_or_terminal_value="$(get_iterm_or_teminal_option_value "$options")"
local fullscreen_option_value="$(get_fullscreen_option_value "$options")"
local tmux_start_script_path="${CURRENT_DIR}/osx_${iterm_or_terminal_value}_start_tmux.sh"
local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")"
echo "$launchd_plist_file_content" > "$osx_auto_start_file_path"
}
main

View file

@ -0,0 +1,66 @@
#!/usr/bin/env bash
# for "true full screen" call the script with "fullscreen" as the first argument
TRUE_FULL_SCREEN="$1"
start_iterm_and_run_tmux() {
osascript <<-EOF
tell application "iTerm"
activate
# open iterm window
try
set _session to current session of current terminal
on error
set _term to (make new terminal)
tell _term
launch session "Tmux"
set _session to current session
end tell
end try
# start tmux
tell _session
write text "tmux"
end tell
end tell
EOF
}
resize_window_to_full_screen() {
osascript <<-EOF
tell application "iTerm"
set winID to id of window 1
tell i term application "Finder"
set desktopSize to bounds of window of desktop
end tell
set bounds of window id winID to desktopSize
end tell
EOF
}
resize_to_true_full_screen() {
osascript <<-EOF
tell application "iTerm"
# wait for iTerm to start
delay 1
activate
# short wait for iTerm to gain focus
delay 0.1
# Command + Enter for fullscreen
tell i term application "System Events"
key code 36 using {command down}
end tell
end tell
EOF
}
main() {
start_iterm_and_run_tmux
if [ "$TRUE_FULL_SCREEN" == "fullscreen" ]; then
resize_to_true_full_screen
else
resize_window_to_full_screen
fi
}
main

View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
# for "true full screen" call the script with "fullscreen" as the first argument
TRUE_FULL_SCREEN="$1"
start_terminal_and_run_tmux() {
osascript <<-EOF
tell application "Terminal"
if not (exists window 1) then reopen
activate
set winID to id of window 1
do script "tmux" in window id winID
end tell
EOF
}
resize_window_to_full_screen() {
osascript <<-EOF
tell application "Terminal"
set winID to id of window 1
tell application "Finder"
set desktopSize to bounds of window of desktop
end tell
set bounds of window id winID to desktopSize
end tell
EOF
}
resize_to_true_full_screen() {
osascript <<-EOF
tell application "Terminal"
# waiting for Terminal.app to start
delay 1
activate
# short wait for Terminal to gain focus
delay 0.1
tell application "System Events"
keystroke "f" using {control down, command down}
end tell
end tell
EOF
}
main() {
start_terminal_and_run_tmux
if [ "$TRUE_FULL_SCREEN" == "fullscreen" ]; then
resize_to_true_full_screen
else
resize_window_to_full_screen
fi
}
main

View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/../variables.sh"
main() {
systemctl --user disable ${systemd_service_name}
}
main

View file

@ -0,0 +1,55 @@
#!/usr/bin/env bash
CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
source "$CURRENT_DIR/../helpers.sh"
source "$CURRENT_DIR/../variables.sh"
template() {
local tmux_start_script="$1"
shift
local options="$@"
local content=""
read -r -d '' content <<-EOF
[Unit]
Description=tmux default session (detached)
Documentation=man:tmux(1)
[Service]
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/tmux ${systemd_tmux_server_start_cmd}
ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh
ExecStop=/usr/bin/tmux kill-server
KillMode=none
RestartSec=2
[Install]
WantedBy=default.target
EOF
echo "$content"
}
systemd_tmux_is_enabled() {
systemctl --user is_enabled $(basename "${systemd_unit_file_path}") >/dev/null 2>&1
}
enable_tmux_unit_on_boot() {
if ! systemd_tmux_is_enabled; then
systemctl --user enable ${systemd_service_name}
fi
}
main() {
local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")"
local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" )"
local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh"
local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}")
echo "$systemd_unit_file" > "${systemd_unit_file_path}"
enable_tmux_unit_on_boot
}
main

View file

@ -0,0 +1,48 @@
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
}
set_tmux_option() {
local option="$1"
local value="$2"
tmux set-option -gq "$option" "$value"
}
# multiple tmux server detection helpers
current_tmux_server_pid() {
echo "$TMUX" |
cut -f2 -d","
}
all_tmux_processes() {
# ignores `tmux source-file .tmux.conf` command used to reload tmux.conf
ps -Ao "command pid" |
\grep "^tmux" |
\grep -v "^tmux source"
}
number_tmux_processes_except_current_server() {
all_tmux_processes |
\grep -v " $(current_tmux_server_pid)$" |
wc -l |
sed "s/ //g"
}
number_current_server_client_processes() {
tmux list-clients |
wc -l |
sed "s/ //g"
}
another_tmux_server_running_on_startup() {
# there are 2 tmux processes (current tmux server + 1) on tmux startup
[ "$(number_tmux_processes_except_current_server)" -gt 1 ]
}

View file

@ -0,0 +1,7 @@
current_timestamp() {
echo "$(date +%s)"
}
set_last_save_timestamp() {
set_tmux_option "$last_auto_save_option" "$(current_timestamp)"
}

View file

@ -0,0 +1,40 @@
SUPPORTED_VERSION="1.9"
# these tmux options contain paths to tmux resurrect save and restore scripts
resurrect_save_path_option="@resurrect-save-script-path"
resurrect_restore_path_option="@resurrect-restore-script-path"
auto_save_interval_option="@continuum-save-interval"
auto_save_interval_default="15"
# time when the tmux environment was last saved (unix timestamp)
last_auto_save_option="@continuum-save-last-timestamp"
auto_restore_option="@continuum-restore"
auto_restore_default="off"
auto_restore_halt_file="${HOME}/tmux_no_auto_restore"
# tmux auto start options
auto_start_option="@continuum-boot"
auto_start_default="off"
# comma separated list of additional options for tmux auto start
auto_start_config_option="@continuum-boot-options"
auto_start_config_default=""
osx_auto_start_file_name="Tmux.Start.plist"
osx_auto_start_file_path="${HOME}/Library/LaunchAgents/${osx_auto_start_file_name}"
status_interpolation_string="\#{continuum_status}"
status_script="#($CURRENT_DIR/scripts/continuum_status.sh)"
# below options set style/color for #{continuum_status} interpolation
status_on_style_wrap_option="@continuum-status-on-wrap-style" # example value: "#[fg=green]#{value}#[fg=white]"
status_off_style_wrap_option="@continuum-status-off-wrap-style" # example value: "#[fg=yellow,bold]#{value}#[fg=white,nobold]"
status_wrap_string="\#{value}"
systemd_service_name="tmux.service"
systemd_unit_file_path="$HOME/.config/systemd/user/${systemd_service_name}"
systemd_tmux_server_start_cmd_option="@continuum-systemd-start-cmd"
systemd_tmux_server_start_cmd_default="new-session -d"

View file

@ -0,0 +1,22 @@
# Changelog
### master
### v1.0.0, 2014-08-31
- update readme to reflect github organization change
- bring in linux support
- small refactoring
- rename plugin to tmux-battery
- add contributors to the readme
### v0.0.2, 2014-06-03
- switch to tab indentation
- do not automatically prepend battery status
- change format interpolation strings to more Tmux-idiomatic
`#{battery_percentage}` and `#{battery_icon}`
- refactoring for simplicity
- support interpolation in `status-left` option too
- README update
### v0.0.1, 2014-06-03
- tag version 0.0.1

View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 ctjhoa
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,85 @@
# Tmux cpu status
Enables displaying cpu percentage and status icon in Tmux status-right.
CPU:<br/>
`CPU: ❏ 8.7%`
This is done by introducing 2 new format strings that can be added to
`status-right` option:
- `#{cpu_icon}` - will display a cpu status icon
- `#{cpu_percentage}` - will show cpu percentage
### Usage
Add `#{cpu_icon}` or `#{cpu_percentage}` format strings to existing
`status-right` Tmux option. Example:
# in .tmux.conf
set -g status-right "CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M "
### Optional requirement (Linux, BSD, OSX)
`iostat` or `sar` are the best way to get an accurate cpu percentage
A fallback is included using `ps -aux` but could be inaccurate.
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Add plugin to the list of TPM plugins in `.tmux.conf`:
set -g @plugin 'tmux-plugins/tmux-cpu'
Hit `prefix + I` to fetch the plugin and source it.
If format strings are added to `status-right`, they should now be visible.
### Manual Installation
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-cpu ~/clone/path
Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/cpu.tmux
Reload TMUX environment:
# type this in terminal
$ tmux source-file ~/.tmux.conf
If format strings are added to `status-right`, they should now be visible.
### Changing icons
By default, these icons are displayed:
- cpu: "❏"
You can change these defaults by adding the following to `.tmux.conf` (the
following lines are not in the code block so that emojis can be seen):
- set-option -g @cpu_icon ":sunglasses:"
Don't forget to reload TMUX environment (`$ tmux source-file ~/.tmux.conf`)
after you do this.
### Limitations
- CPU change most likely won't be instant.<br/>
It will take some time (15 - 60 seconds) for the value to change.
This depends on the `status-interval` TMUX option.
### Other plugins
You might also find these useful:
- [battery](https://github.com/tmux-plugins/tmux-battery) - Plug and play battery percentage and icon indicator for Tmux.
- [online status](https://github.com/tmux-plugins/tmux-online-status) - online status
indicator in Tmux `status-right`. Useful when on flaky connection to see if
you're online.
### License
[MIT](LICENSE)

View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/helpers.sh"
cpu_percentage="#($CURRENT_DIR/scripts/cpu_percentage.sh)"
cpu_icon="#($CURRENT_DIR/scripts/cpu_icon.sh)"
cpu_percentage_interpolation="\#{cpu_percentage}"
cpu_icon_interpolation="\#{cpu_icon}"
set_tmux_option() {
local option=$1
local value=$2
tmux set-option -gq "$option" "$value"
}
do_interpolation() {
local string=$1
local percentage_interpolated=${string/$cpu_percentage_interpolation/$cpu_percentage}
local all_interpolated=${percentage_interpolated/$cpu_icon_interpolation/$cpu_icon}
echo $all_interpolated
}
update_tmux_option() {
local option=$1
local option_value=$(get_tmux_option "$option")
local new_option_value=$(do_interpolation "$option_value")
set_tmux_option "$option" "$new_option_value"
}
main() {
update_tmux_option "status-right"
update_tmux_option "status-left"
}
main

View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
cpu_icon=""
cpu_default="❏ "
# icons are set as script global variables
get_icon_settings() {
cpu_icon=$(get_tmux_option "@cpu_icon" "$cpu_default")
}
main() {
get_icon_settings
printf "$cpu_icon"
}
main

View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
print_cpu_percentage() {
if command_exists "iostat"; then
if is_linux_iostat; then
iostat -c 1 2 | tail -n 2 | head -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
elif is_osx; then
iostat -c 2 disk0 | tail -n 1 | awk '{usage=100-$6} END {printf("%5.1f%%", usage)}'
elif is_freebsd || is_openbsd; then
iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
else
echo "Unknown iostat version please create an issue"
fi
elif command_exists "sar"; then
sar -u 1 1 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
else
if is_cygwin; then
usage="$(WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
printf "%5.1f%%" $usage
else
load=`ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}'`
cpus=$(cpus_number)
echo "$load $cpus" | awk '{printf "%5.2f%%", $1/$2}'
fi
fi
}
main() {
print_cpu_percentage
}
main

View file

@ -0,0 +1,48 @@
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
}
is_osx() {
[ $(uname) == "Darwin" ]
}
is_freebsd() {
[ $(uname) == "FreeBSD" ]
}
is_openbsd() {
[ $(uname) == "OpenBSD" ]
}
is_linux() {
[ $(uname) == "Linux" ]
}
is_cygwin() {
command -v WMIC &> /dev/null
}
is_linux_iostat() {
# Bug in early versions of linux iostat -V return error code
iostat -c &> /dev/null
}
cpus_number() {
if is_linux; then
nproc
else
sysctl -n hw.ncpu
fi
}
command_exists() {
local command="$1"
command -v "$command" &> /dev/null
}

View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Travis Goldie
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,81 @@
# tmux-net-speed
Tmux plugin to monitor upload and download speed of one or all interfaces.
## Usage
Add one of the following format string to `status-right` tmux option.
## Special Credit
This plugin is roughly based on the various plugins in [https://github.com/tmux-plugins]("tmux-plugins").
## Formats
Shows value in either MB/s, KB/s, or B/s.
- `#{download_speed}` - Shows only download speed,
- `#{upload_speed}` - Shows only upload speed,
- `#{net_speed}` - Shows both the upload and download speeds.
**Example**: "D: 123 MB/s U: 25 MB/s"
## Past Values
Since this is a difference, the old values are stored in files in `/tmp/`. The user must be able to
read and write to this directory.
### Set Options
Set the following options in your `.tmux.conf`.
To change which interfaces to pull from, use a space-separated list. If not set,
grabs all the interfaces listed in "/sys/class/net/"
```
set -g @net_speed_interfaces "eth0 eth1"
```
To change the formatter sting passed to `printf`.
```
set -g @download_speed_format "%10s"
set -g @upload_speed_format "%10s"
set -g @net_speed_format "D:%10s U:%10s"
```
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Add plugin to the list of TPM plugins in `.tmux.conf`:
set -g @plugin 'tmux-plugins/tmux-net-speed'
Hit `prefix + I` to fetch the plugin and source it.
If format strings are added to `status-right`, they should now be visible.
### Manual Installation
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-net-speed ~/clone/path
Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/net_speed.tmux
Reload TMUX environment (type this in terminal)
$ tmux source-file ~/.tmux.conf
If format strings are added to `status-right`, they should now be visible.
### Storage of Past Values
This plugin stores the total output for all the interfaces in a file in `/tmp/`. Therefore, the current user must be able to write and read from that directory.
### TODO
- Add unit tests
- Add error handling
- Configure which interfaces to calculate
- Configure format string for `#{net_speed}`
- Handle other OSs (currently only supports Linux)
### License
[MIT](LICENSE)

View file

@ -0,0 +1,13 @@
#!/bin/bash -
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/helpers.sh"
# Initialize files
main()
{
# TODO Add error checking
echo "0" > $DOWNLOAD_FILE
echo "0" > $UPLOAD_FILE
}
main

View file

@ -0,0 +1,36 @@
#!/bin/bash -
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/helpers.sh"
download_speed="#($CURRENT_DIR/scripts/download_speed.sh)"
net_speed="#($CURRENT_DIR/scripts/net_speed.sh)"
upload_speed="#($CURRENT_DIR/scripts/upload_speed.sh)"
download_interpolation="\#{download_speed}"
net_interpolation="\#{net_speed}"
upload_interpolation="\#{upload_speed}"
do_interpolation() {
local input=$1
local result=""
result=${input/$download_interpolation/$download_speed}
result=${result/$net_interpolation/$net_speed}
result=${result/$upload_interpolation/$upload_speed}
echo $result
}
update_tmux_option() {
local option=$1
local option_value=$(get_tmux_option "$option")
local new_option_value=$(do_interpolation "$option_value")
set_tmux_option "$option" "$new_option_value"
}
main() {
update_tmux_option "status-right"
update_tmux_option "status-left"
}
main

View file

@ -0,0 +1,6 @@
#!/bin/bash -
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
for testSuite in $CURRENT_DIR/tests/suites/* ; do
$testSuite
done

View file

@ -0,0 +1,28 @@
#!/bin/bash -
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
sum_download_speed()
{
# Output uses first column
sum_speed 1
}
main()
{
# TODO make configurable
#local file=$(get_tmux_option $DOWNLOAD_FILE)
local file=$DOWNLOAD_FILE
local old_val=$(read_file $file)
local new_val=$(sum_download_speed)
write_file $file $new_val
local vel=$(get_velocity $new_val $old_val)
## Format output
local format=$(get_tmux_option @download_speed_format "%s")
printf "$format" "$vel"
}
main

View file

@ -0,0 +1,129 @@
#!/bin/bash -
##
# Varialbes
##
DOWNLOAD_FILE="/tmp/tmux_net_speed.download"
UPLOAD_FILE="/tmp/tmux_net_speed.upload"
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
}
set_tmux_option() {
local option=$1
local value=$2
tmux set-option -gq "$option" "$value"
}
get_velocity()
{
local new_value=$1
local old_value=$2
# Consts
local THOUSAND=1024
local MILLION=1048576
local vel=$(( new_value - old_value ))
local vel_kb=$(( vel / THOUSAND ))
local vel_mb=$(( vel / MILLION ))
if [[ $vel_mb != 0 ]] ; then
echo -n "$vel_mb MB/s"
elif [[ $vel_kb != 0 ]] ; then
echo -n "$vel_kb KB/s";
else
echo -n "$vel B/s";
fi
}
# Reads from value from file. If file does not exist,
# is empty, or not readable, starts back at 0
read_file()
{
local path="$1"
local fallback_val=0
# File exists and is readdable?
if [[ ! -f "$path" ]] ; then
echo $fallback_val
return 1
elif [[ ! -r "$path" ]]; then
echo $fallback_val
return 1
fi
# Does the file have content?
tmp=$(< "$path")
if [[ "x${tmp}" == "x" ]] ; then
echo $fallback_val
return 1
fi
# Now return known value
echo $tmp
}
# Update values in file
write_file()
{
local path="$1"
local val="$2"
# TODO Add error checking
echo "$val" > "$path"
}
get_interfaces()
{
local interfaces=$(get_tmux_option @net_speed_interfaces "")
if [[ -z "$interfaces" ]] ; then
for interface in /sys/class/net/*; do
interfaces+=$(echo $(basename $interface) " ");
done
fi
# Do not quote the variable. This way will handle trailing whitespace
echo -n $interfaces
}
sum_speed()
{
local column=$1
declare -a interfaces=$(get_interfaces)
local line=""
local val=0
for intf in ${interfaces[@]} ; do
line=$(cat /proc/net/dev | grep "$intf" | cut -d':' -f 2)
speed="$(echo -n $line | cut -d' ' -f $column)"
let val+=${speed:=0}
done
echo $val
}
is_osx() {
[ $(uname) == "Darwin" ]
}
is_cygwin() {
command -v WMIC > /dev/null
}
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1
}

View file

@ -0,0 +1,15 @@
#!/bin/bash -
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
main()
{
local download=$("$CURRENT_DIR/download_speed.sh")
local upload=$("$CURRENT_DIR/upload_speed.sh")
## Format output
local format=$(get_tmux_option @net_speed_format "D:%10s U:%10s")
printf "$format" "$download" "$upload"
}
main

View file

@ -0,0 +1,28 @@
#!/bin/bash -
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
sum_upload_speed()
{
# Output uses ninth column
sum_speed 9
}
main()
{
# TODO make configurable
#local upload_file=$(get_tmux_option $UPLOAD_FILE)
local file=$UPLOAD_FILE
local old_val=$(read_file $file)
local new_val=$(sum_upload_speed)
write_file $file $new_val
local vel=$(get_velocity $new_val $old_val)
## Format output
local format=$(get_tmux_option @upload_speed_format "%s")
printf "$format" "$vel"
}
main

View file

@ -0,0 +1,132 @@
#!/bin/bash -
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS="$CURRENT_DIR/../../scripts"
source "$CURRENT_DIR/../test_utils.sh"
##
# Description:
# General setup before each test
##
setup()
{
source "$SCRIPTS/helpers.sh"
}
##
# get_tmux_option
##
setup_get_tmux_option()
{
setup
## Set generic property
tmux set @get_tmux_option_name "get_tmux_option_val"
}
cleanup_get_tmux_option()
{
# Unset value
tmux set -u @get_tmux_option_name
}
test_get_tmux_option()
{
##
# Should return set value
##
setup_get_tmux_option
result=$( get_tmux_option "@get_tmux_option_name")
assertEqual "$result" "get_tmux_option_val" "should get tmux prop when given no default" -v
cleanup_get_tmux_option
##
# Should show set value
##
setup_get_tmux_option
result=$( get_tmux_option "@get_tmux_option_name_unset")
assertEqual "$result" "" "should get empty string when tmux prop unset"
cleanup_get_tmux_option
##
# Should show set value
##
setup_get_tmux_option
result=$( get_tmux_option @get_tmux_option_name_unset my_default)
assertEqual "$result" "my_default" "should get default if provided for unset prop"
cleanup_get_tmux_option
}
##
# get_velocity
##
setup_get_velocity()
{
setup
}
cleanup_get_velocity() { :; }
test_get_velocity()
{
setup_get_velocity
let input=200
result=$(get_velocity $input 0)
assertEqual "$result" "200 B/s" "should show B/s"
cleanup_get_velocity
setup_get_velocity
let input=2*1024
result=$(get_velocity $input 0)
assertEqual "$result" "2 KB/s" "should show KB/s"
cleanup_get_velocity
setup_get_velocity
let input=3*1048576
result=$(get_velocity $input 0)
assertEqual "$result" "3 MB/s" "should show MB/s"
cleanup_get_velocity
setup_get_velocity
let subtract_from=100*1048576
let subtract_with=50*1048576
result=$(get_velocity $subtract_from subtract_with)
assertEqual "$result" "50 MB/s" "should show MB/s if subraction done"
cleanup_get_velocity
}
##
# get_interfaces
##
setup_get_interfaces()
{
setup
}
cleanup_get_interfaces() { :; }
test_get_interfaces()
{
setup_get_interfaces
result=$(get_interfaces)
assertEqual "$result" "eth0 lo wlan0" "should output space-delimited list of interfaces" -v
cleanup_get_interfaces
}
suites()
{
#test_get_tmux_option
#test_get_velocity
test_get_interfaces
}
# Run tests
suites

View file

@ -0,0 +1,91 @@
#!/bin/bash -
###############################################################################
# Author: Travis Goldie
# Purpose: Util funcs for unit tests
###############################################################################
##
# Description:
# Asserts if `$1` equals `$2`
##
assertEqual()
{
local input=$1
local expected=$2
local msg=$3
if [[ "$4" == "-v" ]] ; then
echo $@
fi
if [[ -z msg ]] ; then
msg="Failed test"
fi
test "$1" == "$2"
err=$?
if [[ $err == 0 ]] ; then
echo "[PASSED]: ${msg}"
echo
return $err
fi
if [[ $err != 0 ]] ; then
echo "[FAILED]: ${msg}"
echo
return $err
fi
}
##
# Description:
# Asserts if `$1` not equals `$2`
##
assertNotEqual()
{
local input=$1
local expected=$2
local msg=$3
if [[ -z msg ]] ; then
msg="Failed test"
fi
test "$1" != "$2"
err=$?
if [[ $err == 0 ]] ; then
echo "[PASSED]: ${msg}"
echo
return $err
fi
if [[ $err != 0 ]] ; then
echo "[FAILED]: ${msg}"
echo
return $err
fi
}
##
# @description
# Checks to see if error code is non-zero. If so, echo message and exit
# with the given error code.
#
# ``` bash
# $ someCmd blah blah2
# $ err=$?
# $ die $err "If err is non-zero this script will exit"
# ```
##
die()
{
local err=$1
local msg=$2
local name=$( basename $0 )
if [[ $err != 0 ]] ; then
echo "[ERROR]:${name}:code $err:${msg}"
exit $err
fi
}

View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Erick Pintor
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,86 @@
# Tmux prefix highlight
Plugin that highlights when you press tmux prefix key. Inspired by
[this](http://stackoverflow.com/questions/12003726/give-a-hint-when-press-prefix-key-in-tmux)
thread on stackoverflow.
Many thanks to [@obxhdx](https://github.com/obxhdx) for showing me this trick.
Prefix off:
![prefix_off](screenshots/prefix_off.png)
Prefix on:
![prefix_on](screenshots/prefix_on.png)
### Usage
Just add `#{prefix_highlight}` to your left/right status bar.
```tmux.confi
set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'
```
The plugin can also be configured to show when copy mode is active; see the
**Configurations** section for details.
### Installation with Tmux Plugin Manager (recommended)
Add plugin to the list of TPM plugins:
```tmux.conf
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
```
Press prefix + I to install it.
### Manual Installation
Clone the repo:
```bash
$ git clone https://github.com/tmux-plugins/tmux-prefix-highlight.git ~/clone/path
```
Add this line to your .tmux.conf:
```tmux.conf
run-shell ~/clone/path/prefix_highlight.tmux
```
Reload TMUX environment with:
```bash
$ tmux source-file ~/.tmux.conf
```
### Configurations
The colors used for the prefix highlight can be configured:
```tmux.conf
set -g @prefix_highlight_fg 'white' # default is 'colour231'
set -g @prefix_highlight_bg 'blue' # default is 'colour04'
```
The plugin can also be configured to show when copy mode is active. If enabled,
the `#{prefix_highlight}` token will be replaced with the string `Copy` when
copy mode is enabled. The style for copy mode can be configured as a
comma-separated list of colors and attributes:
```tmux.conf
set -g @prefix_highlight_show_copy_mode 'on'
set -g @prefix_highlight_copy_mode_attr 'fg=black,bg=yellow,bold' # default is 'fg=default,bg=yellow'
```
Additionally, the plugin can be configured to attach optional affixes to the
value contained in `#{prefix_highlight}`.
(e.g. `< ^B >`)
```tmux.conf
set -g @prefix_highlight_output_prefix '< '
set -g @prefix_highlight_output_suffix ' >'
```
### License
[MIT](LICENSE)

View file

@ -0,0 +1,92 @@
#!/usr/bin/env bash
set -e
# Place holder for status left/right
place_holder="\#{prefix_highlight}"
# Possible configurations
fg_color_config='@prefix_highlight_fg'
bg_color_config='@prefix_highlight_bg'
output_prefix='@prefix_highlight_output_prefix'
output_suffix='@prefix_highlight_output_suffix'
show_copy_config='@prefix_highlight_show_copy_mode'
copy_attr_config='@prefix_highlight_copy_mode_attr'
# Defaults
default_fg='colour231'
default_bg='colour04'
default_copy_attr='fg=default,bg=yellow'
tmux_option() {
local -r value=$(tmux show-option -gqv "$1")
local -r default="$2"
if [ ! -z "$value" ]; then
echo "$value"
else
echo "$default"
fi
}
highlight() {
local -r \
status="$1" \
prefix="$2" \
prefix_highlight="$3" \
show_copy_mode="$4" \
copy_highlight="$5" \
output_prefix="$6" \
output_suffix="$7" \
copy="Copy"
local -r status_value="$(tmux_option "$status")"
local -r prefix_with_optional_affixes="$output_prefix$prefix$output_suffix"
local -r copy_with_optional_affixes="$output_prefix$copy$output_suffix"
if [[ "on" = "$show_copy_mode" ]]; then
local -r fallback="${copy_highlight}#{?pane_in_mode,$copy_with_optional_affixes,}"
else
local -r fallback=""
fi
local -r highlight_on_prefix="${prefix_highlight}#{?client_prefix,$prefix_with_optional_affixes,$fallback}#[default]"
tmux set-option -gq "$status" "${status_value/$place_holder/$highlight_on_prefix}"
}
main() {
local -r \
prefix=$(tmux_option prefix) \
fg_color=$(tmux_option "$fg_color_config" "$default_fg") \
bg_color=$(tmux_option "$bg_color_config" "$default_bg") \
show_copy_mode=$(tmux_option "$show_copy_config" "off") \
output_prefix=$(tmux_option "$output_prefix" " ") \
output_suffix=$(tmux_option "$output_suffix" " ") \
copy_attr=$(tmux_option "$copy_attr_config" "$default_copy_attr")
local -r short_prefix=$(
echo "$prefix" | tr "[:lower:]" "[:upper:]" | sed 's/C-/\^/'
)
local -r \
prefix_highlight="#[fg=$fg_color,bg=$bg_color]" \
copy_highlight="${copy_attr:+#[default,$copy_attr]}"
highlight "status-right" \
"$short_prefix" \
"$prefix_highlight" \
"$show_copy_mode" \
"$copy_highlight" \
"$output_prefix" \
"$output_suffix"
highlight "status-left" \
"$short_prefix" \
"$prefix_highlight" \
"$show_copy_mode" \
"$copy_highlight" \
"$output_prefix" \
"$output_suffix"
}
main

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,14 @@
# generic packages and latest Tmux 1.9a
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 add-apt-repository -y ppa:pi-rho/dev
- sudo apt-get update
- sudo apt-get install -y tmux=1.9a-1~ppa1~p
install:
- git fetch --unshallow --recurse-submodules || git fetch --recurse-submodules
- lib/tmux-test/setup
script: ./tests/run_tests_in_isolation

View file

@ -0,0 +1,140 @@
# Changelog
### master
- save and restore tmux pane contents (@laomaiweng)
- update tmux-test to solve issue with recursing git submodules in that project
- set options quietly in `resurrect.tmux` script
- improve pane contents restoration: `cat <file>` is no longer shown in pane
content history
- refactoring: drop dependency on `paste` command
- bugfix for pane contents restoration
- expand tilde char `~` if used with `@resurrect-dir`
- do not save empty trailing lines when pane content is saved
- do not save pane contents if pane is empty (only for 'save pane contents'
feature)
- "save pane contents" feature saves files to a separate directory
- archive and compress pane contents file
- make archive & compress pane contents process more portable
- `mutt` added to the list of automatically restored programs
- added guide for migrating from tmuxinator
### v2.4.0, 2015-02-23
- add "tmux-test"
- add test for "resurrect save" feature
- add test for "resurrect restore" feature
- make the tests work and pass on travis
- add travis badge to the readme
### v2.3.0, 2015-02-12
- Improve fetching proper window_layout for zoomed windows. In order to fetch
proper value, window has to get unzoomed. This is now done faster so that
"unzoom,fetch value,zoom" cycle is almost unnoticable to the user.
### v2.2.0, 2015-02-12
- bugfix: zoomed windows related regression
- export save and restore script paths so that 'tmux-resurrect-save' plugin can
use them
- enable "quiet" saving (used by 'tmux-resurrect-save' plugin)
### v2.1.0, 2015-02-12
- if restore is started when there's only **1 pane in the whole tmux server**,
assume the users wants the "full restore" and overrwrite that pane.
### v2.0.0, 2015-02-10
- add link to the wiki page for "first pane/window issue" to the README as well
as other tweaks
- save and restore grouped sessions (used with multi-monitor workflow)
- save and restore active and alternate windows in grouped sessions
- if there are no grouped sessions, do not output empty line to "last" file
- restore active and alternate windows only if they are present in the "last" file
- refactoring: prefer using variable with tab character
- remove deprecated `M-s` and `M-r` key bindings (breaking change)
### v1.5.0, 2014-11-09
- add support for restoring neovim sessions
### v1.4.0, 2014-10-25
- plugin now uses strategies when fetching pane full command. Implemented
'default' strategy.
- save command strategy: 'pgrep'. It's here only if fallback is needed.
- save command strategy: 'gdb'
- rename default strategy name to 'ps'
- create `expect` script that can fully restore tmux environment
- fix default save command strategy `ps` command flags. Flags are different for
FreeBSD.
- add bash history saving and restoring (@rburny)
- preserving layout of zoomed windows across restores (@Azrael3000)
### v1.3.0, 2014-09-20
- remove dependency on `pgrep` command. Use `ps` for fetching process names.
### v1.2.1, 2014-09-02
- tweak 'new_pane' creation strategy to fix #36
- when running multiple tmux server and for a large number of panes (120 +) when
doing a restore, some panes might not be created. When that is the case also
don't restore programs for those panes.
### v1.2.0, 2014-09-01
- new feature: inline strategies when restoring a program
### v1.1.0, 2014-08-31
- bugfix: sourcing `variables.sh` file in save script
- add `Ctrl` key mappings, deprecate `Alt` keys mappings.
### v1.0.0, 2014-08-30
- show spinner during the save process
- add screencast script
- make default program running list even more conservative
### v0.4.0, 2014-08-29
- change plugin name to `tmux-resurrect`. Change all the variable names.
### v0.3.0, 2014-08-29
- bugfix: when top is running the pane `$PWD` can't be saved. This was causing
issues during the restore and is now fixed.
- restoring sessions multiple times messes up the whole environment - new panes
are all around. This is now fixed - pane restorations are now idempotent.
- if pane exists from before session restore - do not restore the process within
it. This makes the restoration process even more idempotent.
- more panes within a window can now be restored
- restore window zoom state
### v0.2.0, 2014-08-29
- bugfix: with vim 'session' strategy, if the session file does not exist - make
sure vim does not contain `-S` flag
- enable restoring programs with arguments (e.g. "rails console") and also
processes that contain program name
- improve `irb` restore strategy
### v0.1.0, 2014-08-28
- refactor checking if saved tmux session exists
- spinner while tmux sessions are restored
### v0.0.5, 2014-08-28
- restore pane processes
- user option for disabling pane process restoring
- enable whitelisting processes that will be restored
- expand readme with configuration options
- enable command strategies; enable restoring vim sessions
- update readme: explain restoring vim sessions
### v0.0.4, 2014-08-26
- restore pane layout for each window
- bugfix: correct pane ordering in a window
### v0.0.3, 2014-08-26
- save and restore current and alternate session
- fix a bug with non-existing window names
- restore active pane for each window that has multiple panes
- restore active and alternate window for each session
### v0.0.2, 2014-08-26
- saving a new session does not remove the previous one
- make the directory where sessions are stored configurable
- support only Tmux v1.9 or greater
- display a nice error message if saved session file does not exist
- added README
### v0.0.1, 2014-08-26
- started a project
- basic saving and restoring works

View file

@ -0,0 +1,12 @@
### Contributing
Code contributions are welcome!
### Reporting a bug
If you find a bug please report it in the issues. When reporting a bug please
attach:
- a file symlinked to `~/.tmux/resurrect/last`.
- your `.tmux.conf`
- if you're getting an error paste it to a [gist](https://gist.github.com/) and
link it in the issue

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,135 @@
# Tmux Resurrect
[![Build Status](https://travis-ci.org/tmux-plugins/tmux-resurrect.png?branch=master)](https://travis-ci.org/tmux-plugins/tmux-resurrect)
Restore `tmux` environment after system restart.
Tmux is great, except when you have to restart the computer. You lose all the
running programs, working directories, pane layouts etc.
There are helpful management tools out there, but they require initial
configuration and continuous updates as your workflow evolves or you start new
projects.
`tmux-resurrect` saves all the little details from your tmux environment so it
can be completely restored after a system restart (or when you feel like it).
No configuration is required. You should feel like you never quit tmux.
It even (optionally)
[restores vim and neovim sessions](docs/restoring_vim_and_neovim_sessions.md)!
Automatic restoring and continuous saving of tmux env is also possible with
[tmux-continuum](https://github.com/tmux-plugins/tmux-continuum) plugin.
### Screencast
[![screencast screenshot](/video/screencast_img.png)](https://vimeo.com/104763018)
### Key bindings
- `prefix + Ctrl-s` - save
- `prefix + Ctrl-r` - restore
### About
This plugin goes to great lengths to save and restore all the details from your
`tmux` environment. Here's what's been taken care of:
- all sessions, windows, panes and their order
- current working directory for each pane
- **exact pane layouts** within windows (even when zoomed)
- active and alternative session
- active and alternative window for each session
- windows with focus
- active pane for each window
- "grouped sessions" (useful feature when using tmux with multiple monitors)
- programs running within a pane! More details in the
[restoring programs doc](docs/restoring_programs.md).
Optional:
- [restoring vim and neovim sessions](docs/restoring_vim_and_neovim_sessions.md)
- [restoring pane contents](docs/restoring_pane_contents.md)
- [restoring bash history](docs/restoring_bash_history.md) (experimental)
Requirements / dependencies: `tmux 1.9` or higher, `bash`.
Tested and working on Linux, OSX and Cygwin.
`tmux-resurrect` is idempotent! It will not try to restore panes or windows that
already exist.<br/>
The single exception to this is when tmux is started with only 1 pane in order
to restore previous tmux env. Only in this case will this single pane be
overwritten.
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
Add plugin to the list of TPM plugins in `.tmux.conf`:
set -g @plugin 'tmux-plugins/tmux-resurrect'
Hit `prefix + I` to fetch the plugin and source it. You should now be able to
use the plugin.
### Manual Installation
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-resurrect ~/clone/path
Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/resurrect.tmux
Reload TMUX environment with: `$ tmux source-file ~/.tmux.conf`.
You should now be able to use the plugin.
### Docs
- [Guide for migrating from tmuxinator](docs/migrating_from_tmuxinator.md)
**Configuration**
- [Changing the default key bindings](docs/custom_key_bindings.md).
- Only a conservative list of programs is restored by default:<br/>
`vi vim nvim emacs man less more tail top htop irssi mutt`.<br/>
[Restoring programs doc](docs/restoring_programs.md) explains how to restore
additional programs.
- [Change a directory](docs/save_dir.md) where `tmux-resurrect` saves tmux
environment.
**Optional features**
- [Restoring vim and neovim sessions](docs/restoring_vim_and_neovim_sessions.md)
is nice if you're a vim/neovim user.
- [Restoring pane contents](docs/restoring_pane_contents.md) feature.
**Experimental features (also optional)**
- [restoring bash history](docs/restoring_bash_history.md)
### Other goodies
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for
regex searches in tmux and fast match selection
- [tmux-yank](https://github.com/tmux-plugins/tmux-yank) - enables copying
highlighted text to system clipboard
- [tmux-open](https://github.com/tmux-plugins/tmux-open) - a plugin for quickly
opening highlighted file or a url
- [tmux-continuum](https://github.com/tmux-plugins/tmux-continuum) - automatic
restoring and continuous saving of tmux env
You might want to follow [@brunosutic](https://twitter.com/brunosutic) on
twitter if you want to hear about new tmux plugins or feature updates.
### Reporting bugs and contributing
Both contributing and bug reports are welcome. Please check out
[contributing guidelines](CONTRIBUTING.md).
### Credits
[Mislav Marohnić](https://github.com/mislav) - the idea for the plugin came from his
[tmux-session script](https://github.com/mislav/dotfiles/blob/2036b5e03fb430bbcbc340689d63328abaa28876/bin/tmux-session).
### License
[MIT](LICENSE.md)

View file

@ -0,0 +1,11 @@
# Custom key bindings
The default key bindings are:
- `prefix + Ctrl-s` - save
- `prefix + Ctrl-r` - restore
To change these, add to `.tmux.conf`:
set -g @resurrect-save 'S'
set -g @resurrect-restore 'R'

View file

@ -0,0 +1,72 @@
# Migrating from `tmuxinator`
### Why migrate to `tmux-resurrect`?
Here are some reasons why you'd want to migrate from `tmuxinator` to
`tmux-resurrect`:
- **Less dependencies**<br/>
`tmuxinator` depends on `ruby` which can be a hassle to set up if you're not a
rubyist.<br/>
`tmux-resurrect` depends just on `bash` which is virtually
omnipresent.
- **Simplicity**<br/>
`tmuxinator` has an executable, CLI interface with half dozen commands and
command completion.<br/>
`tmux-resurrect` defines just 2 tmux key bindings.
- **No configuration**<br/>
`tmuxinator` is all about config files (and their constant updating).<br/>
`tmux-resurrect` requires no configuration to work.
- **Better change handling**<br/>
When you make a change to any aspect of tmux layout, you also have to
update related `tmuxinator` project file (and test to make sure change is
ok).<br/>
With `tmux-resurrect` there's nothing to do: your change will be
remembered on the next save.
### How to migrate?
1. Install `tmux-resurrect`.
2. Open \*all* existing `tmuxinator` projects.<br/>
Verify all projects are open by pressing `prefix + s` and checking they are
all on the list.
3. Perform a `tmux-resurrect` save.
That's it! You can continue using just `tmux-resurrect` should you choose so.
Note: it probably makes no sense to use both tools at the same time as they do
the same thing (creating tmux environment for you to work in).
Technically however, there should be no issues.
### Usage differences
`tmuxinator` focuses on managing individual tmux sessions (projects).
`tmux-resurrect` keeps track of the \*whole* tmux environment: all sessions are
saved and restored together.
A couple tips if you decide to switch to `tmux-resurrect`:
- Keep all tmux sessions (projects) running all the time.<br/>
If you want to work on an existing project, you should be able to just
\*switch* to an already open session using `prefix + s`.<br/>
This is different from `tmuxinator` where you'd usually run `mux new [project]`
in order to start working on something.
- No need to kill sessions with `tmux kill-session` (unless you really don't
want to work on it ever).<br/>
It's the recurring theme by now: just keep all the sessions running all the
time. This is convenient and also cheap in terms of resources.
- The only 2 situations when you need `tmux-resurrect`:<br/>
1) Save tmux environment just before restarting/shutting down your
computer.<br/>
2) Restore tmux env after you turn the computer on.
### Other questions?
Still have questions? Feel free to open an
[issue](ihttps://github.com/tmux-plugins/tmux-resurrect/issues). We'll try to
answer it and also update this doc.

View file

@ -0,0 +1,12 @@
# Restoring bash history (experimental)
Enable feature with this option in `.tmux.conf`:
set -g @resurrect-save-bash-history 'on'
Bash `history` for individual panes will now be saved and restored. Due to
technical limitations, this only works for panes which have no program running
in foreground when saving. `tmux-resurrect` will send history write command to
each such pane. To prevent these commands from being added to history
themselves, add `HISTCONTROL=ignoreboth` to your `.bashrc`
(this is set by default in Ubuntu).

View file

@ -0,0 +1,31 @@
# Restoring pane contents
This plugin enables saving and restoring tmux pane contents.
This feature can be enabled by adding this line to `.tmux.conf`:
set -g @resurrect-capture-pane-contents 'on'
##### Known issue
When using this feature, please check the value of `default-command`
tmux option. That can be done with `$ tmux show -g default-command`.
The value should NOT contain `&&` or `||` operators. If it does, simplify the
option so those operators are removed.
Example:
- this will cause issues (notice the `&&` and `||` operators):
set -g default-command "which reattach-to-user-namespace > /dev/null && reattach-to-user-namespace -l $SHELL || $SHELL -l"
- this is ok:
set -g default-command "reattach-to-user-namespace -l $SHELL"
Related [bug](https://github.com/tmux-plugins/tmux-resurrect/issues/98).
Alternatively, you can let
[tmux-sensible](https://github.com/tmux-plugins/tmux-sensible)
handle this option in a cross-platform way and you'll have no problems.

View file

@ -0,0 +1,100 @@
# Restoring programs
Only a conservative list of programs is restored by default:<br/>
`vi vim nvim emacs man less more tail top htop irssi mutt`.
This can be configured with `@resurrect-processes` option in `.tmux.conf`. It
contains space-separated list of additional programs to restore.
- Example restoring additional programs:
set -g @resurrect-processes 'ssh psql mysql sqlite3'
- Programs with arguments should be double quoted:
set -g @resurrect-processes 'some_program "git log"'
- Start with tilde to restore a program whose process contains target name:
set -g @resurrect-processes 'irb pry "~rails server" "~rails console"'
- Use `->` to specify a command to be used when restoring a program (useful if
the default restore command fails ):
set -g @resurrect-processes 'some_program "grunt->grunt development"'
- Don't restore any programs:
set -g @resurrect-processes 'false'
- Restore **all** programs (be careful with this!):
set -g @resurrect-processes ':all:'
### Clarifications
> I don't understand tilde `~`, what is it and why is it used when restoring
programs?
Let's say you use `rails server` command often. You want `tmux-resurrect` to
save and restore it automatically. You might try adding `rails server` to the
list of programs that will be restored:
set -g @resurrect-processes '"rails server"' # will NOT work
Upon save, `rails server` command will actually be saved as this command:
`/Users/user/.rbenv/versions/2.0.0-p481/bin/ruby script/rails server`
(if you wanna see how is any command saved, check it yourself in
`~/.tmux/resurrect/last` file).
When programs are restored, the `rails server` command will NOT be restored
because it does not **strictly** match the long
`/Users/user/.rbenv/versions/2.0.0-p481/bin/ruby script/rails server` string.
The tilde `~` at the start of the string relaxes process name matching.
set -g @resurrect-processes '"~rails server"' # OK
The above option says: "restore full process if `rails server` string is found
ANYWHERE in the process name".
If you check long process string, there is in fact a `rails server` string at
the end, so now the process will be successfully restored.
> What is arrow `->` and why is is used?
(Please read the above clarification about tilde `~`).
Continuing with our `rails server` example, when the process is finally restored
correctly it might not look pretty as you'll see the whole
`/Users/user/.rbenv/versions/2.0.0-p481/bin/ruby script/rails server` string in
the command line.
Naturally, you'd rather want to see just `rails server` (what you initially
typed), but that information is now unfortunately lost.
To aid this, you can use arrow `->`:
set -g @resurrect-processes '"~rails server->rails server"' # OK
This option says: "when this process is restored use `rails server` as the
command name".
Full (long) process name is now ignored and you'll see just `rails server` in
the command line when the program is restored.
> Now I understand the tilde and the arrow, but things still don't work for me
Here's the general workflow for figuring this out:
- Set up your whole tmux environment manually.<br/>
In our example case, we'd type `rails server` in a pane where we want it to
run.
- Save tmux env (it will get saved to `~/.tmux/resurrect/last`).
- Open `~/.tmux/resurrect/last` file and try to find full process string for
your program.<br/>
Unfortunately this is a little vague but it should be easy. A smart
thing to do for our example is to search for string `rails` in the `last`
file.
- Now that you know the full and the desired process string use tilde `~` and
arrow `->` in `.tmux.conf` to make things work.

View file

@ -0,0 +1,15 @@
# Restoring vim and neovim sessions
- save vim/neovim sessions. I recommend
[tpope/vim-obsession](https://github.com/tpope/vim-obsession) (as almost every
plugin, it works for both vim and neovim).
- in `.tmux.conf`:
# for vim
set -g @resurrect-strategy-vim 'session'
# for neovim
set -g @resurrect-strategy-nvim 'session'
`tmux-resurrect` will now restore vim and neovim sessions if `Session.vim` file
is present.

View file

@ -0,0 +1,6 @@
# Resurrect save dir
By default Tmux environment is saved to a file in `~/.tmux/resurrect` dir.
Change this with:
set -g @resurrect-dir '/some/path'

View file

@ -0,0 +1,2 @@
.vagrant/
lib/

View file

@ -0,0 +1,14 @@
# generic packages and latest Tmux 1.9a
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 add-apt-repository -y ppa:pi-rho/dev
- sudo apt-get update
- sudo apt-get install -y tmux=1.9a-1~ppa1~p
install:
- git clone https://github.com/tmux-plugins/tmux-test lib/tmux-test
- lib/tmux-test/setup
script: ./tests/run_tests_in_isolation

View file

@ -0,0 +1,38 @@
# Changelog
### master
- move `setup` task to `.travis.yml` for travis tests
- "merge" travis.yml and travis_for_plugins.yml files (no need to keep em
separate)
- add more useful helper functions
- remove tmux-test repo as a submodule from self, this causes issues with
`$ git submodule update --recursive --init` command that some users use for
managing other plugins
### v0.2.0, 2015-02-22
- `setup` script gitignores `tests/helpers.sh`
- move `tests/helpers.sh` to `tests/helpers/helpers.sh`
- `setup` undo removes added lines from gitignore file
### v0.1.0, 2015-02-22
- changes so that 'tmux-test' can be included with tmux plugins
- do not gitignore submodules directory
- add installation and usage instructions
- copy `.travis.yml` to the project root when running `setup` script
- add a brief mention of travis CI to the readme
- add test helpers
- `setup` script symlinks helpers file to `tests/` directory
- `setup` script can undo most of its actions
- add a tmux scripting test
- `tmux-test` uses `tmux-test` to test itself
- update `tmux-test` submodule
- a different `travis.yml` for `tmux-test` and for plugins
### v0.0.1, 2015-02-21
- git init
- add vagrant provisioning scripts for ubuntu and debian
- add a ".travis.yml" file
- generic "run_tests" script
- "run_tests_in_isolation" script
- add "Vagrantfile"
- enable passing VM names as arguments to "run_tests" script

View file

@ -0,0 +1,19 @@
Copyright (C) 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,134 @@
# tmux-test
[![Build Status](https://travis-ci.org/tmux-plugins/tmux-test.png?branch=master)](https://travis-ci.org/tmux-plugins/tmux-test)
A small framework for isolated testing of tmux plugins. Isolation is achieved by
running the tests in `Vagrant`. Works on [travis](travis-ci.org) too.
Extracted from [tmux plugin manager](https://github.com/tmux-plugins/tpm) and
[tmux-copycat](https://github.com/tmux-plugins/tmux-copycat).
Dependencies: `Vagrant` (no required when running on travis).
### Setup
Let's say you made tmux plugin with the following file hierarchy:
```text
/tmux-plugin
|-- plugin.tmux
`-- scripts
`-- plugin_script.sh
```
From your project root directory (tmux-plugin/) execute the following shell
command to fetch `tmux-test` and add it as a submodule:
$ git submodule add https://github.com/tmux-plugins/tmux-test.git lib/tmux-test
Run the `setup` script:
$ lib/tmux-test/setup
The project directory will now look like this (additions have comments):
```text
/tmux-plugin
|-- plugin.tmux
|-- run_tests # symlink, gitignored
|-- .gitignore # 2 lines appended to gitignore
|-- .travis.yml # added
|-- lib/tmux-test/ # git submodule
|-- scripts
| `-- plugin_script.sh
`-- tests # dir to put the tests in
`-- run_tests_in_isolation.sh # symlink, gitignored
`-- helpers
`-- helpers.sh # symlinked bash helpers, gitignored
```
`tmux-test` is now set up. You are ok to commit the additions to the repo.
### Writing and running tests
A test is any executable with a name starting with `test_` in `tests/`
directory.
Now that you installed `tmux-test` let's create an example test.
- create a `tests/test_example.sh` file with the following content (it's a
`bash` script but it can be any executable):
#/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# bash helpers provided by 'tmux-test'
source $CURRENT_DIR/helpers/helpers.sh
# installs plugin from current repo in Vagrant (or on Travis)
install_tmux_plugin_under_test_helper
# start tmux in background (plugin under test is sourced)
tmux new -d
# get first session name
session_name="$(tmux list-sessions -F "#{session_name}")"
# fail the test if first session name is not "0"
if [ "$session_name" == "0" ]; then
# fail_helper is also provided by 'tmux-test'
fail_helper "First session name is not '0' by default"
fi
# sets the right script exit code ('tmux-test' helper)
exit_helper
- make the test file executable with `$ chmod +x tests/test_example.sh`
- run the test by executing `./run_tests` from the project root directory
- the first invocation might take some time because Vagrant's ubuntu virtual
machine is downloading. You should see `Success, tests pass!` message when it's
done.
Check out more example test scripts in this project's [tests/ directory](tests/).
### Continuous integration
The setup script (`lib/tmux-test/setup`) added a `.travis.yml` file to the
project root. To setup continuous integration, just add/enable the project on
[travis](travis-ci.org).
### Notes
- The `tests/` directory for tests and `lib/tmux-test/` for cloning `tmux-test`
into cannot be changed currently
- Don't run `tests/run_tests_in_isolation` script on your local development
environment. That's an internal test runner meant to be executed in an
isolated environment like `vagrant` or `travis`.<br/>
Use `./run_tests` script.
- You can use `KEEP_RUNNING=true ./run_tests` for faster test running cycle.
If this case `Vagrant` will keep running even after the tests are done.
- You can use `VAGRANT_CWD=lib/tmux-text/ vagrant ssh ubuntu` for ssh login to
`Vagrant`.
### Running `tmux-test` framework tests
`tmux-test` uses itself to test itself. To run framework tests:
- clone this project `$ git clone git@github.com:tmux-plugins/tmux-test.git`
- `$ cd tmux-test`
- run `$ ./run_framework_tests`
### Other goodies
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for
regex searches in tmux and fast match selection
- [tmux-continuum](https://github.com/tmux-plugins/tmux-continuum) - automatic
restoring and continuous saving of tmux env
You might want to follow [@brunosutic](https://twitter.com/brunosutic) on
twitter if you want to hear about new tmux plugins or feature updates.
### License
[MIT](LICENSE.md)

View file

@ -0,0 +1,17 @@
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder "../../", "/vagrant"
config.vm.define :ubuntu do |ubuntu|
ubuntu.vm.box = "hashicorp/precise64"
ubuntu.vm.provision "shell", path: "vagrant_ubuntu_provisioning.sh"
end
config.vm.define :centos do |centos|
centos.vm.box = "chef/centos-6.5"
centos.vm.provision "shell", path: "vagrant_centos_provisioning.sh"
end
end

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# This file is used to run "tmux-test" framework tests.
# "setup" script is needed to run the tests, but it overrides some working dir
# files. To address that, "setup" is run before the tests and it's actions are
# undone after.
main() {
git clone https://github.com/tmux-plugins/tmux-test lib/tmux-test
lib/tmux-test/setup
./run_tests
local exit_value=$?
lib/tmux-test/setup "undo"
exit "$exit_value"
}
main

View file

@ -0,0 +1,91 @@
#!/usr/bin/env bash
# This file is a symlink from 'tmux-test' plugin.
# You probably don't want to edit it.
# Invoke this script when running a test suite.
# Example invocations:
# ./run_tests # runs tests on default VM ubuntu
# ./run_tests ubuntu # runs tests on ubuntu VM
# ./run_tests ubuntu centos # runs tests on ubuntu and cents VMs
# For each virtual machine where tests run, this script performs the following:
# - starts VM
# - starts the test suite witin a VM
# - stops the VM after the test suite is done
export BOXES="$*"
# global variable for script exit value
export EXIT_VALUE=0
register_failing_tests() {
EXIT_VALUE=1
}
run_vagrant() {
local box="$1"
VAGRANT_CWD=lib/tmux-test/ vagrant up "$box"
}
# Halt vagrant after tests are done running, unless KEEP_RUNNING environment
# variable is set to 'true'.
stop_vagrant() {
local box="$1"
if [ -z "$KEEP_RUNNING" ]; then
VAGRANT_CWD=lib/tmux-test/ vagrant halt "$box"
else
echo
echo "KEEP_RUNNING is set. Vagrant not halted."
fi
}
run_tests() {
local box="$1"
local test_file="/vagrant/tests/run_tests_in_isolation"
echo "Running test suite on $box from: $test_file"
echo
VAGRANT_CWD=lib/tmux-test/ vagrant ssh "$box" -c "cd /vagrant; $test_file"
}
exit_message() {
local exit_val="$1"
echo
if [ "$exit_val" == 0 ]; then
echo "Success, tests pass!"
else
echo "Tests failed!" 1>&2
fi
}
run_tests_on_vm() {
local vm="$1"
run_vagrant "$vm"
run_tests "$vm"
local tests_exit_value="$?"
stop_vagrant "$vm"
if [ "$tests_exit_value" -gt 0 ]; then
register_failing_tests
fi
}
run_tests_on_virtual_machines() {
if [ -z "$BOXES" ]; then
# no script arguments, run on 'ubuntu' by default
run_tests_on_vm "ubuntu"
else
# run on VMs provided as script arguments
local box
for box in $BOXES; do
run_tests_on_vm "$box"
done
fi
}
main() {
echo "$BOXES"
run_tests_on_virtual_machines
exit_message "$EXIT_VALUE"
exit "$EXIT_VALUE"
}
main

View file

@ -0,0 +1,93 @@
#!/usr/bin/env bash
# invoke this script from your projects root directory
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# pass "undo" as a script arg to undo most of the setup actions
UNDO_SETUP="$1"
undo() {
[ "$UNDO_SETUP" == "undo" ]
}
restore() {
local file="$1"
rm -f "$file"
git checkout -- "$file" 2>/dev/null
}
gitignore() {
local file="$1"
grep -q "^${file}$" .gitignore 2>/dev/null || echo "$file" >> .gitignore
}
remove_from_gitignore() {
local file="$1"
local escaped_filename="$(echo "$file" | sed "s,/,\\\/,g")"
sed -i"" "/^${escaped_filename}$/d" .gitignore
}
add_files_to_gitignore() {
if ! undo; then
gitignore "run_tests"
gitignore "tests/run_tests_in_isolation"
gitignore "tests/helpers/helpers.sh"
else
remove_from_gitignore "run_tests"
remove_from_gitignore "tests/run_tests_in_isolation"
remove_from_gitignore "tests/helpers/helpers.sh"
fi
}
symlink_user_test_runner() {
local file="run_tests"
if ! undo; then
ln -sf "lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
create_directory_for_tests() {
if ! undo; then
mkdir -p tests/helpers/
fi
}
symlink_internal_test_runner() {
local file="tests/run_tests_in_isolation"
if ! undo; then
ln -sf "../lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
symlink_test_helpers() {
local file="tests/helpers/helpers.sh"
if ! undo; then
ln -sf "../../lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
copy_travis_yml() {
local file=".travis.yml"
if ! undo; then
cp "lib/tmux-test/${file}" "$file"
else
restore "$file"
fi
}
main() {
add_files_to_gitignore
symlink_user_test_runner
create_directory_for_tests
symlink_internal_test_runner
symlink_test_helpers
copy_travis_yml
}
main

View file

@ -0,0 +1,60 @@
# This file is a symlink from 'tmux-test' plugin.
# You probably don't want to edit it.
# Global variable that keeps the value of test status (success/fail).
# Suggested usage is via `fail_helper` and `exit_helper` functions.
TEST_STATUS="success"
# PRIVATE FUNCTIONS
_teardown() {
rm -f ~/.tmux.conf
rm -rf ~/.tmux/
tmux kill-server >/dev/null 2>&1
}
_clone_the_plugin() {
local plugin_path="${HOME}/.tmux/plugins/tmux-plugin-under-test/"
rm -rf "$plugin_path"
git clone --recursive "${CURRENT_DIR}/../" "$plugin_path" >/dev/null 2>&1
}
_add_plugin_to_tmux_conf() {
set_tmux_conf_helper<<-HERE
run-shell '~/.tmux/plugins/tmux-plugin-under-test/*.tmux'
HERE
}
# PUBLIC HELPER FUNCTIONS
set_tmux_conf_helper() {
> ~/.tmux.conf # empty tmux.conf file
while read -r line; do
echo "$line" >> ~/.tmux.conf
done
}
fail_helper() {
local message="$1"
echo "$message" >&2
TEST_STATUS="fail"
}
exit_helper() {
_teardown
if [ "$TEST_STATUS" == "fail" ]; then
echo "FAIL!"
echo
exit 1
else
echo "SUCCESS"
echo
exit 0
fi
}
install_tmux_plugin_under_test_helper() {
_clone_the_plugin
_add_plugin_to_tmux_conf
}

View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# This file is a symlink from 'tmux-test' plugin.
# You probably don't want to edit it.
# This script should be run within an isolated enviroment (Vagrant, travis).
# Depending on what the tests do, it might NOT be safe to run this script
# directly on the development machine.
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
EXIT_VALUE=0 # running a test suite is successful by default
test_files() {
ls -1 "$CURRENT_DIR" | # test files are in the current dir
\grep -i "^test" | # test file names start with "test"
xargs # file names in a single line
}
set_exit_val_to_false() {
EXIT_VALUE=1
}
run_tests() {
local test_file
for test_file in $(test_files); do
echo "Running test: $test_file"
"${CURRENT_DIR}/${test_file}"
# handling exit value
local test_exit_value="$?"
if [ "$test_exit_value" -ne 0 ]; then
set_exit_val_to_false
fi
done
}
main() {
run_tests
exit "$EXIT_VALUE"
}
main

View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
exit 0

View file

@ -0,0 +1,24 @@
#/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# bash helpers provided by 'tmux-test'
source $CURRENT_DIR/helpers/helpers.sh
# installs plugin from current repo in Vagrant (or on Travis)
install_tmux_plugin_under_test_helper
# start tmux in background (plugin under test is sourced)
tmux new -d
# get first session name
session_name="$(tmux list-sessions -F "#{session_name}")"
# fail the test if first session name is not "0"
if ! [ "$session_name" == "0" ]; then
# fail_helper is also provided by 'tmux-test'
fail_helper "First session name is not '0' by default"
fi
# sets the right script exit code ('tmux-test' helper)
exit_helper

View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/helpers/helpers.sh
number_of_windows() {
tmux list-windows |
wc -l |
sed "s/ //g"
}
main() {
# start tmux in the background
tmux new -d
tmux new-window
local number_of_windows="$(number_of_windows)"
if ! [ "$number_of_windows" -eq 2 ]; then
fail_helper "Incorrect number of windows. Expected 2, got $number_of_windows"
fi
exit_helper
}
main

View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# tmux installation instructions from here
# https://gist.github.com/rschuman/6168833
sudo su -
yum -y install gcc kernel-devel make ncurses-devel
yum -y install git-core expect vim ruby ruby-devel ruby-irb
# download tmux and libevent
mkdir ~/downloads && cd ~/downloads
curl http://sourceforge.net/projects/levent/files/latest/download?source=files -L -o libevent2.tar.gz -w 'Last URL was: %{url_effective}'
curl http://sourceforge.net/projects/tmux/files/latest/download?source=files -L -o tmux.tar.gz -w 'Last URL was: %{url_effective}'
# compile libevent
cd ~/downloads
tar zxvf libevent2.tar.gz
cd libevent-*-stable
./configure --prefix=/usr/local
make
make install
# compile tmux
cd ~/downloads
tar zxvf tmux.tar.gz
cd tmux-*
LDFLAGS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib" ./configure --prefix=/usr/local
make
make install

View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install -y git-core expect vim
sudo apt-get install -y python-software-properties software-properties-common
# install latest Tmux 1.9a
sudo add-apt-repository -y ppa:pi-rho/dev
sudo apt-get update
sudo apt-get install -y tmux=1.9a-1~ppa1~p

View file

@ -0,0 +1,39 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/variables.sh"
source "$CURRENT_DIR/scripts/helpers.sh"
set_save_bindings() {
local key_bindings=$(get_tmux_option "$save_option" "$default_save_key")
local key
for key in $key_bindings; do
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/save.sh"
done
}
set_restore_bindings() {
local key_bindings=$(get_tmux_option "$restore_option" "$default_restore_key")
local key
for key in $key_bindings; do
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/restore.sh"
done
}
set_default_strategies() {
tmux set-option -gq "${restore_process_strategy_option}irb" "default_strategy"
}
set_script_path_options() {
tmux set-option -gq "$save_path_option" "$CURRENT_DIR/scripts/save.sh"
tmux set-option -gq "$restore_path_option" "$CURRENT_DIR/scripts/restore.sh"
}
main() {
set_save_bindings
set_restore_bindings
set_default_strategies
set_script_path_options
}
main

View file

@ -0,0 +1 @@
lib/tmux-test/run_tests

Some files were not shown because too many files have changed in this diff Show more