Skip to content

Commit

Permalink
use a set to only show unique links
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Feb 21, 2020
1 parent cfc0219 commit 6c1bce2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "leth"
version = "0.1.1"
version = "0.1.2"
authors = ["fcd <[email protected]>"]
edition = "2018"

Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate regex;
extern crate skim;

use std::collections::HashSet;
use std::io::Cursor;
use std::io::{self, Read};
use std::process::Command;
Expand All @@ -20,16 +21,17 @@ pub fn main() {
io::stdin().read_to_string(&mut buffer).unwrap();
let lines = buffer.split("\n");

let mut matches: Vec<&str> = Vec::new();
let mut matches: HashSet<&str> = HashSet::new();

for line in lines {
for capture in re.captures_iter(line) {
let url_match = capture.get(1).unwrap().as_str();
matches.push(url_match);
matches.insert(url_match);
}
}

let items = matches.join("\n");
let unique_items: Vec<&str> = matches.into_iter().collect();
let items = unique_items.join("\n");
// `run_with` would read and show items from the stream
let selected_items = Skim::run_with(&options, Some(Box::new(Cursor::new(items))))
.map(|out| out.selected_items)
Expand Down

0 comments on commit 6c1bce2

Please sign in to comment.