Skip to content

Commit 1c9eaae

Browse files
authored
Merge pull request #4 from Kristories/develop
Fix navigation and refactoring
2 parents 3d7f3a6 + d344afb commit 1c9eaae

2 files changed

Lines changed: 63 additions & 22 deletions

File tree

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
# MySSH
22

3-
Checking for existing SSH keys.
3+
MySSH is a simple tool to check for existing SSH keys in your `.ssh` directory and view their contents.
44

55
![Cover](art/cover.png)
66

77
## Installation
88

9-
Install via brew
9+
You can install MySSH using Homebrew:
10+
11+
### Step 1: Add the formula to Homebrew
12+
13+
If this is your first time installing from the `devtical` tap, you'll need to add it:
14+
15+
```bash
16+
brew tap devtical/formulae
17+
```
18+
19+
### Step 2: Install MySSH
20+
21+
After adding the tap, install MySSH by running:
22+
1023
```bash
1124
brew install devtical/formulae/myssh
12-
```
25+
```
26+
27+
## Usage
28+
29+
Once installed, you can run MySSH directly from your terminal:
30+
31+
```bash
32+
myssh
33+
```
34+
35+
This will display a list of SSH keys available in your `.ssh` directory. Select any key to view its contents.
36+
37+
## License
38+
39+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for more details.
40+

src/main.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,49 @@ use std::fs;
66
use std::path::Path;
77

88
fn main() {
9-
let home = std::env::var("HOME").unwrap();
10-
let path = Path::new(&home).join(".ssh");
11-
let mut arr = Vec::new();
9+
let mut siv = cursive::default();
10+
show_file_selection(&mut siv);
11+
siv.run();
12+
}
1213

13-
for entry in fs::read_dir(path).expect("Unable to list") {
14-
let entry = entry.expect("unable to get entry");
14+
fn show_file_selection(siv: &mut Cursive) {
15+
let home = std::env::var("HOME").expect("HOME environment variable not set");
16+
let ssh_path = Path::new(&home).join(".ssh");
17+
let mut keys = Vec::new();
18+
19+
for entry in fs::read_dir(&ssh_path).expect("Unable to list directory") {
20+
let entry = entry.expect("Unable to read entry");
1521
let path = entry.path();
16-
let str = path.display().to_string();
22+
let file_path = path.display().to_string();
1723

18-
if !str.contains("known_hosts") {
19-
arr.push(str);
24+
if !file_path.contains("known_hosts") {
25+
keys.push(file_path);
2026
}
2127
}
2228

2329
let mut select = SelectView::new().h_align(HAlign::Center).autojump();
24-
25-
select.add_all_str(arr);
30+
select.add_all_str(keys);
2631
select.set_on_submit(show_next_window);
2732

28-
let mut siv = cursive::default();
29-
30-
siv.add_layer(Dialog::around(select.scrollable().fixed_size((40, 10))).title("My Keys"));
31-
siv.run();
33+
siv.add_layer(
34+
Dialog::around(select.scrollable().fixed_size((40, 10)))
35+
.title("My SSH Keys")
36+
.button("Quit", |s| s.quit()),
37+
);
3238
}
3339

34-
fn show_next_window(siv: &mut Cursive, str: &str) {
40+
fn show_next_window(siv: &mut Cursive, file_path: &str) {
3541
siv.pop_layer();
3642

37-
let contents = fs::read_to_string(str).expect("Should have been able to read the file");
38-
let text = contents;
39-
40-
siv.add_layer(Dialog::around(TextView::new(text)).button("Quit", |s| s.quit()));
43+
let contents = fs::read_to_string(file_path).expect("Unable to read the file");
44+
let text_view = TextView::new(contents);
45+
46+
siv.add_layer(
47+
Dialog::around(text_view)
48+
.button("Back", move |s| {
49+
s.pop_layer();
50+
show_file_selection(s);
51+
})
52+
.button("Quit", |s| s.quit()),
53+
);
4154
}

0 commit comments

Comments
 (0)