mirror of
https://github.com/tmux-plugins/tmux-continuum.git
synced 2024-12-03 09:58:47 +00:00
First working version
This commit is contained in:
commit
42ca2d4454
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Changelog
|
||||
|
||||
### master
|
||||
- first working version
|
15
CONTRIBUTING.md
Normal file
15
CONTRIBUTING.md
Normal 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
|
19
LICENSE.md
Normal file
19
LICENSE.md
Normal 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.
|
18
resurrect_auto.tmux
Executable file
18
resurrect_auto.tmux
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/scripts/helpers.sh"
|
||||
|
||||
save_command_interpolation="#($CURRENT_DIR/scripts/resurrect_auto_save.sh)"
|
||||
|
||||
add_resurrect_save_interpolation() {
|
||||
local status_right_value="$(get_tmux_option "status-right" "")"
|
||||
local new_value="${save_command_interpolation}${status_right_value}"
|
||||
set_tmux_option "status-right" "$new_value"
|
||||
}
|
||||
|
||||
main() {
|
||||
add_resurrect_save_interpolation
|
||||
}
|
||||
main
|
33
scripts/check_tmux_version.sh
Executable file
33
scripts/check_tmux_version.sh
Executable 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
|
16
scripts/helpers.sh
Normal file
16
scripts/helpers.sh
Normal file
@ -0,0 +1,16 @@
|
||||
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"
|
||||
}
|
41
scripts/resurrect_auto_save.sh
Executable file
41
scripts/resurrect_auto_save.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
source "$CURRENT_DIR/variables.sh"
|
||||
|
||||
supported_tmux_version_ok() {
|
||||
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
|
||||
}
|
||||
|
||||
current_timestamp() {
|
||||
echo "$(date +%s)"
|
||||
}
|
||||
|
||||
set_last_save_timestamp() {
|
||||
set_tmux_option "$last_auto_save_option" "$(current_timestamp)"
|
||||
}
|
||||
|
||||
enough_time_since_last_run_passed() {
|
||||
local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "0")"
|
||||
local interval_minutes="$(get_tmux_option "$auto_save_interval_option" "$auto_save_interval_default")"
|
||||
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 "no-spinner"
|
||||
set_last_save_timestamp
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
if supported_tmux_version_ok && enough_time_since_last_run_passed; then
|
||||
fetch_and_run_tmux_resurrect_save_script
|
||||
fi
|
||||
}
|
||||
main
|
11
scripts/variables.sh
Normal file
11
scripts/variables.sh
Normal file
@ -0,0 +1,11 @@
|
||||
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_default="15"
|
||||
auto_save_interval_option="@resurrect-auto-save-interval"
|
||||
|
||||
# time when the tmux environment was last saved (unix timestamp)
|
||||
last_auto_save_option="@resurrect-auto-save-last-timestamp"
|
Loading…
Reference in New Issue
Block a user