Skip to content

Commit d331047

Browse files
committed
Some cleanups, minor functionality and README and LICENSE changes
1 parent 4194873 commit d331047

File tree

9 files changed

+423
-787
lines changed

9 files changed

+423
-787
lines changed

Cargo.lock

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dialoguer = "0.10.3"
3030
anyhow = "1.0.70"
3131
log = "0.4.17"
3232
pretty_env_logger = "0.4.0"
33+
env_logger = "0.10.0"
3334

3435
[profile.release]
3536
codegen-units = 1 # reduce parallel code generation units

LICENSE

Lines changed: 21 additions & 674 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Session Buddy Helper
2+
====================
3+
4+
`Command line tool to do various things with your Session Buddy database`
5+
6+
What
7+
----
8+
9+
[Session Buddy](https://sessionbuddy.com/) is a Google Chrome [extension](https://chrome.google.com/webstore/detail/session-buddy/edacconmaakjimmfgnblocblbcdcpbko) to store and restore browser tabs. All its data is stored in a SQLite3 database. There is a Google Group where some discussion about Session Buddy takes place and, it seems, people sometimes lose their data or are having problems exporting or importing their stuff. This utility aims to do various operations on that database and help out those in need.
10+
11+
Features
12+
--------
13+
14+
* **Backup:** Create a JSON file similar to what the extension would do. The produced output is not exactly the same, but should be viable to be imported into Session Buddy again.
15+
16+
* **Import:** Import a backup file created by either the extension or this tool into a database.
17+
18+
* **Search:** Search your disk for Session Buddy databases. Sometimes it's a little bit cumbersome to figure out the path to the extension's database, so this should make things easier.
19+
20+
* **New:** Create a new and empty Session Buddy database. It will have the same schema as when created by the extension.
21+
22+
* **Debug:** Try to figure out if something is wrong with a database or a backup file.
23+
24+
* **Stats:** Print various stats about a database. Useful to figure out what happened after executing some other task on the database.
25+
26+
* **Dump:** Print all links to stdout.
27+
28+
Current State & Motivation
29+
--------------------------
30+
31+
So far it seems to work.
32+
33+
Over the years I have aggregated multiple databases with in summary around 5,000 stored sessions consisting of around 15,000 windows and more than 130.0000 tabs. The extension would choke on exporting or just crash the extension or make the browser itself freeze. By doing all the stuff on the SQLite database itself, all that works.
34+
35+
But still, it may be not advisable to carry all your stuff around in a Chrome extension all the time. By scheduling regular backups and pruning operations on the database Session Buddy probably won't lose it and, you have convenient (and performant) access to all your data.
36+
37+
If you have any ideas or wishes regarding this tool or need help rescuing your thousands of tabs, feel free to reach out in the [discussions](https://github.com/rxw1/sbh/discussions).
38+
39+
Installation
40+
------------
41+
42+
```
43+
cargo install sbh
44+
```
45+
46+
```
47+
git clone https://www.github.com/rxw1/sbh
48+
cd sbh
49+
cargo install --release .
50+
```
51+
52+
```sh
53+
curl -LSfs https://japaric.github.io/trust/install.sh |\
54+
sh -s -- --git rxw/sbh
55+
```
56+
57+
Or download precompiled packages from [here](http://www.github.com/rxw1/sbh/releases).
58+
59+
Usage Examples
60+
--------------
61+
62+
### Search for databases
63+
64+
Search for databases and print out the paths. By default, we're trying to figure out the proper path automatically depending on the operating system. For more information about these paths have a look at [dirs-rs](https://github.com/dirs-dev/dirs-rs).
65+
66+
```
67+
sbh search
68+
```
69+
70+
Or you can pass any path to search there:
71+
72+
```
73+
sbh search ~/.config
74+
```
75+
76+
### Backup a database to JSON
77+
78+
```sh
79+
sbh backup -o whatever.json
80+
```
81+
82+
If you do not specify an output file, the produced JSON will be printed to the standard output.
83+
84+
### Search and backup each found database to a timestamped file
85+
86+
```sh
87+
for db in "$(sbh search)"; do
88+
o=sb-$(sbh id $db)-$(date +%Y%m%d%H%M%S).json
89+
sbh backup -o $o $db
90+
sbh validate backup $o
91+
done
92+
```
93+
94+
### Dump sort and count all URLs stored in a database
95+
96+
```sh
97+
sbh search | while read -r l; do
98+
sbh dump "$l" | grep -Ev 'chrome(|-.*)://' | sort | uniq -c | sort -g
99+
done
100+
```
101+
102+
TODO (Maybe)
103+
-----------
104+
105+
* CSV export
106+
* Prune the database using certain criteria
107+
* Have config file to configure stuff
108+
* Handle `CurrentSession` and `PreviousSession` sessions
109+
110+
Is it any good?
111+
---------------
112+
113+
Yes, of course. It is written in Rust, and it's blazingly fast.
114+
115+
Findings
116+
--------
117+
118+
* For whatever reason, the JSON backups produced by the extension have `<feff>` as the first byte, i.e. a `BOM character` aka `Zero Width No-Break Space`, which breaks it for most parsers. I don't think having this in the beginning of a JSON file is a good thing. After removal, everything is fine. Here's some discussion about that on Stack Overflow: [https://stackoverflow.com/q/4990095/220472](https://stackoverflow.com/q/4990095/220472).
119+
120+
Disclaimer
121+
----------
122+
123+
Neither me or this tool is in any way affiliated with the developers of Session Buddy.

src/args.rs

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,28 @@ pub struct Args {
1111

1212
#[derive(Subcommand, Debug)]
1313
pub enum Action {
14-
/// Dump database to stdout
15-
Dump {
16-
/// Dump all URLs
17-
#[arg()]
18-
path: PathBuf
19-
},
20-
21-
/// Print database statistics
22-
Stats {
23-
/// Path to search for databases
24-
#[arg()]
25-
path: PathBuf
26-
},
27-
28-
/// Search for Session Buddy databases and print out their path
14+
/// Search for databases and print out their path
2915
Search {
30-
/// Path to search for databases
16+
/// Path to search for databases. If no path argument is
17+
/// given we're trying to figure it out.
3118
#[arg()]
3219
path: Option<PathBuf>
3320
},
3421

3522
/// Create JSON backups from a Session Buddy database
3623
Backup {
24+
/// Search for databases
25+
//#[arg(conflicts_with = "path")]
26+
//search: bool,
27+
28+
/// Output <FILENAME>
29+
#[arg(short, long, value_name = "FILENAME")]
30+
out: Option<PathBuf>,
31+
3732
/// Database to backup
3833
#[arg(value_name = "DATABASE")]
3934
path: PathBuf,
4035

41-
/// Output <FILENAME>
42-
#[arg(short, long, value_name = "FILENAME")]
43-
out: Option<PathBuf>
4436
},
4537

4638
/// Import JSON backups to a Session Buddy database
@@ -57,21 +49,51 @@ pub enum Action {
5749

5850
/// Create a new database
5951
New {
52+
/// Path to database
6053
#[arg()]
6154
path: PathBuf
6255
},
6356

64-
/// Various debug actions
65-
Debug {
57+
/// Print some database statistics
58+
Stats {
59+
/// Path to database
60+
#[arg()]
61+
path: PathBuf
62+
},
63+
64+
/// Print all URLs of a database to stdout
65+
Dump {
66+
/// Path to database
67+
#[arg()]
68+
path: PathBuf
69+
},
70+
71+
72+
/// Print the id of a database
73+
Id {
74+
/// Path to database
75+
#[arg()]
76+
path: PathBuf
77+
},
78+
79+
/// Validate a database or JSON backup
80+
Validate {
6681
#[command(subcommand)]
67-
action: DebugAction
68-
}
82+
action: ValidateAction
83+
},
6984
}
7085

7186
#[derive(Subcommand, Debug)]
72-
pub enum DebugAction {
87+
pub enum ValidateAction {
7388
Database {
89+
/// Path to database
7490
#[arg()]
75-
path: String
91+
path: PathBuf
92+
},
93+
94+
Backup {
95+
/// Path to database
96+
#[arg()]
97+
path: PathBuf
7698
}
7799
}

0 commit comments

Comments
 (0)