1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! A backup & restore solution for Tmux sessions.
//!
//! Version requirement: _rustc 1.88+_
//!
//! ## Features
//!
//! - Backup and restore of your tmux environment:
//! - tmux sessions windows, panes, with layout, titles & pane history
//! - current and last session.
//! - Fast: less than 1 sec for 16 sessions, 45 windows and 80 panes.
//! - Show the catalog of backups, with age, file size, content description & archive format
//! - 2 strategies are available:
//! - keep the `n` most recent backups
//! - classic backup strategy:
//! - the lastest backup per hour for the past 24 hours (max 23 backups - exclude the past hour),
//! - the lastest backup per day for the past 7 days (max 6 backups - exclude the past 24 hours),
//! - the lastest backup per week of the past 4 weeks (max 3 backups - exclude the past week),
//! - the lastest backup per month of this year (max 11 backups - exclude the past month).
//! - Because you decide where backups are stored, you can use both strategies, combining the
//! benefits of high-frequency backups and on demand backups like in tmux-resurrect.
//!
//! ## Getting started
//!
//! After installation (see below), you can either use it from the command line, or via tmux
//! bindings.
//!
//! The catalog is located by default in `$XDG_STATE_HOME/tmux-backup/`, or
//! `§HOME/.state/tmux-backup` otherwise. The default strategy is "most-recent", but you can change
//! it with `--strategy classic`. Check usage with `tmux-backup --help` for detailed help.
//!
//! ### View the catalog of existing backups
//!
//! ```console
//! $ tmux-backup catalog list --details
//! Strategy: KeepMostRecent: 10
//! Location: `$HOME/.local/state/tmux-backup`
//!
//! NAME AGE STATUS FILESIZE VERSION CONTENT
//! 11. backup-20220907T224553.156103.tar.zst 2 days purgeable 644.17 kB 1.0 16 sessions 43 windows 79 panes
//! 10. backup-20220907T224926.103771.tar.zst 2 days retainable 644.38 kB 1.0 16 sessions 43 windows 79 panes
//! 9. backup-20220908T092341.125258.tar.zst 2 days retainable 654.76 kB 1.0 16 sessions 43 windows 79 panes
//! 8. backup-20220909T224742.781818.tar.zst 18 hours retainable 599.64 kB 1.0 16 sessions 42 windows 77 panes
//! 7. backup-20220909T225158.305403.tar.zst 18 hours retainable 600.32 kB 1.0 16 sessions 42 windows 79 panes
//! 6. backup-20220910T152551.807672.tar.zst 1 hour retainable 608.79 kB 1.0 16 sessions 43 windows 80 panes
//! 5. backup-20220910T165118.250800.tar.zst 29 minutes retainable 614.16 kB 1.0 16 sessions 43 windows 80 panes
//! 4. backup-20220910T171812.893389.tar.zst 2 minutes retainable 614.33 kB 1.0 16 sessions 43 windows 80 panes
//! 3. backup-20220910T172016.924711.tar.zst 11 seconds retainable 614.44 kB 1.0 16 sessions 43 windows 80 panes
//! 2. backup-20220910T172019.320809.tar.zst 8 seconds retainable 614.42 kB 1.0 16 sessions 43 windows 80 panes
//! 1. backup-20220910T172024.141993.tar.zst 3 seconds retainable 614.38 kB 1.0 16 sessions 43 windows 80 panes
//!
//! 11 backups: 10 retainable, 1 purgeable
//! ```
//!
//! If you installed the plugin config into tmux, then the default tmux bindings for listing
//! backups are
//!
//! - `prefix + b + l` to show the simple catalog
//! - `prefix + b + L` to show the detailed catalog (adds the filesize, version & content columns)
//!
//! Both of these bindings will open a tmux popup showing the catalog content.
//!
//! ### Save the current tmux environment
//!
//! ```console
//! $ tmux-backup save
//! ✅ 16 sessions 43 windows 80 panes, persisted to `/Users/graelo/.local/state/tmux-backup/backup-20220910T171812.893389.tar.zst`
//! ```
//!
//! By default, the tmux binding for saving a new backup are
//!
//! - `prefix + b + s` save and compact (delete purgeable backups)
//! - `prefix + b + b` save but not compact the catalog
//!
//! Both of these bindings will print the same report as above in the tmux status bar.
//!
//! ### Restore from a backup
//!
//! Typing `tmux-backup restore` in your shell outside of tmux will
//!
//! - start a tmux server if none is running
//! - restore all sessions from the latest backup
//! - but you still have to `tmux attach -t <your-last-session>`
//!
//! The same command typed in a shell inside tmux will erase session `0` (the default start
//! session) and restore your tmux environment in place.
//!
//! By default, the tmux binding for restoring the latest backup is
//!
//! - `prefix + b + r` restore sessions from the latest backup
//!
//! ## Installation
//!
//! ### Installing the binary
//!
//! On macOS
//!
//! ```shell
//! brew install graelo/homebrew-tap/tmux-backup # will also install shell completions
//! ```
//!
//! On linux
//!
//! ```shell
//! curl \
//! https://github.com/graelo/tmux-backup/releases/download/v0.4.0/tmux-backup-x86_64-unknown-linux-gnu.tar.xz \
//! | tar xf - > /usr/local/bin/tmux-backup
//! chmod +x /usr/local/bin/tmux-backup
//! ```
//!
//! On linux, to install completions, type
//!
//! ```shell
//! tmux-backup generate-completion zsh|bash|fish > /path/to/your/completions/folder
//! ```
//!
//! ### Installing the tmux plugin hook
//!
//! Type
//!
//! ```shell
//! mkdir ~/.tmux/plugins/tmux-backup
//! tmux-backup init > ~/.tmux/plugins/tmux-backup/tmux-backup.tmux
//! ```
//!
//! If you don't use [tpm](https://github.com/tmux-plugins/tpm), just add this to your
//! `.tmux.conf`:
//!
//! ```text
//! source-file ~/.tmux/plugins/tmux-backup/tmux-backup.tmux
//! ```
//!
//! Alternatively, if you use tpm, declare the tmux-backup plugin to TPM in your `~/.tmux.conf`:
//!
//! ```tmux
//! set -g @tpm_plugins ' \
//! tmux-plugins/tpm \
//! tmux-plugins/tmux-backup \ <-- here
//! tmux-plugins/tmux-copyrat \
//! tmux-plugins/tmux-yank \
//! tmux-plugins/tmux-resurrect \
//! tmux-plugins/tmux-sessionist \
//! '
//! ```
//!
//! The next time you start tmux, the `tmux-backup.tmux` configuration will be loaded.
//!
//! ## Caveats
//!
//! - This is a beta version
//! - Does not handle multiple clients: help is welcome if you have clear scenarios for this.
//! - Does not handle session groups: help is also welcome.
//!
//! ## License
//!
//! Licensed under either of
//!
//! - [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
//! - [MIT license](http://opensource.org/licenses/MIT)
//!
//! at your option.
//!
//! ### Contribution
//!
//! Unless you explicitly state otherwise, any contribution intentionally submitted
//! for inclusion in the work by you, as defined in the Apache-2.0 license, shall
//! be dual licensed as above, without any additional terms or conditions.
pub use tmux_lib as tmux;
/// Result type for this crate.
pub type Result<T> = Result;