-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Shizcow/develop
Develop
- Loading branch information
Showing
14 changed files
with
253 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION = 5.4.0 | ||
VERSION = 5.5.0 | ||
|
||
# paths | ||
PREFIX = /usr/local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
rink = "0.4.5" | ||
rink-core = "0.5.1" | ||
async-std = {version = "1.7.0", features = ["unstable"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! /bin/sh | ||
|
||
if [ "$depcheck" != "false" ]; then | ||
printf "Checking for xdg-open... " | ||
if command -v xdg-open &> /dev/null | ||
then | ||
echo "yes" | ||
else | ||
echo "no" | ||
>&2 echo "xdg-open required for plugin 'lookup' but not available. Install xdg or run make depcheck=false to continue anyway" | ||
exit 1 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
phf = { version = "0.8.0", features = ["macros"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Edit the following to add/remove/change search engines | ||
// The keys are the parameters for the --engine arguement | ||
// The values are the URLs. "%s" will be replaced with the search string. | ||
pub static ENGINES: phf::Map<&'static str, &'static str> = phf::phf_map! { | ||
"ddg" => "https://duckduckgo.com/%s", | ||
"crates" => "https://crates.io/crates/%s", | ||
"docs" => "https://docs.rs/%s", | ||
"rust" => "https://doc.rust-lang.org/std/?search=%s", | ||
"github" => "https://github.com/search?q=%s", | ||
"archwiki" => "https://wiki.archlinux.org/index.php?search=%s", | ||
"dictionary" => "https://www.merriam-webster.com/dictionary/%s", | ||
"thesaurus" => "https://www.merriam-webster.com/thesaurus/%s", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use overrider::*; | ||
use std::process::Command; | ||
|
||
use crate::clapflags::CLAP_FLAGS; | ||
use crate::config::ConfigDefault; | ||
use crate::drw::Drw; | ||
use crate::result::*; | ||
use itertools::Itertools; | ||
|
||
mod engines; | ||
use engines::ENGINES; | ||
|
||
// Format engine as prompt | ||
// eg "ddg" -> "[Search ddg]" | ||
fn create_search_input(engine: &str) -> CompResult<String> { | ||
// fail early if engine is wrong | ||
match ENGINES.get(engine) { | ||
Some(_) => Ok(format!("[Search {}]", engine)), | ||
None => { | ||
return Err(Die::Stderr(format!( | ||
"Invalid search search engine {}. Valid options are: {}", | ||
engine, | ||
ENGINES.keys().map(|e| format!("\"{}\"", e)).join(", ") | ||
))) | ||
} | ||
} | ||
} | ||
|
||
// Take the output of create_search_input as prompt | ||
// It's not very clean but hey it works | ||
fn do_dispose(output: &str, prompt: &str) -> CompResult<()> { | ||
let mut engine: String = prompt.chars().skip("[Search ".len()).collect(); | ||
engine.pop(); | ||
|
||
// just unwrap since the check was performed before | ||
let search_prompt = ENGINES.get(engine.as_str()) | ||
.unwrap().to_string().replace("%s", output); | ||
|
||
// TODO: consider user defined open command for cross-platform awareness | ||
Command::new("xdg-open") | ||
.arg(search_prompt) | ||
.spawn() | ||
.map_err(|_| Die::Stderr("Failed to spawn child process".to_owned()))?; | ||
Ok(()) | ||
} | ||
|
||
// Important: engine must become before lookup. It's a bug in overrider. | ||
#[override_flag(flag = engine, priority = 2)] | ||
impl Drw { | ||
pub fn dispose(&mut self, output: String, recommendation: bool) -> CompResult<bool> { | ||
do_dispose(&output, &self.config.prompt)?; | ||
Ok(recommendation) | ||
} | ||
pub fn format_stdin(&mut self, _lines: Vec<String>) -> CompResult<Vec<String>> { | ||
self.config.prompt = create_search_input(CLAP_FLAGS.value_of("engine").unwrap())?; | ||
Ok(vec![]) // turns into prompt | ||
} | ||
} | ||
|
||
#[override_flag(flag = listEngines, priority = 2)] | ||
impl Drw { | ||
pub fn format_stdin(&mut self, _: Vec<String>) -> CompResult<Vec<String>> { | ||
Err(Die::Stdout(ENGINES.keys().join("\n"))) | ||
} | ||
} | ||
#[override_flag(flag = listEngines, priority = 2)] | ||
impl ConfigDefault { | ||
pub fn nostdin() -> bool { | ||
true // if called with --list-engines, takes no stdin (only prints) | ||
} | ||
} | ||
|
||
#[override_flag(flag = engine, priority = 2)] | ||
impl ConfigDefault { | ||
pub fn nostdin() -> bool { | ||
true // if called with --engine ENGINE, takes no stdin | ||
} | ||
} | ||
|
||
#[override_flag(flag = lookup, priority = 1)] | ||
impl Drw { | ||
pub fn dispose(&mut self, output: String, recommendation: bool) -> CompResult<bool> { | ||
do_dispose(&output, &self.config.prompt)?; | ||
Ok(recommendation) | ||
} | ||
pub fn format_stdin(&mut self, lines: Vec<String>) -> CompResult<Vec<String>> { | ||
self.config.prompt = create_search_input(&lines[0])?; | ||
Ok(vec![]) // turns into prompt | ||
} | ||
} | ||
|
||
#[override_flag(flag = lookup, priority = 1)] | ||
impl ConfigDefault { | ||
pub fn nostdin() -> bool { | ||
false // if called without --engine, takes stdin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
about: | | ||
Open a search query in the browser. Pass --lookup to enable. | ||
Use --engine to specify a search engine or pipe through stdin. | ||
See src/plugins/lookup/engines.rs for custom engines at build time. | ||
entry: main.rs | ||
cargo_dependencies: deps.toml | ||
build: "sh build.sh" | ||
|
||
args: | ||
- lookup: | ||
help: Enter lookup mode | ||
long_help: > | ||
The input in the prompt will be used as the search term in the selected | ||
engine. XDG-OPEN will be used for opening generated links. | ||
short: L | ||
long: lookup | ||
conflicts_with: prompt | ||
- engine: | ||
help: Engine to use | ||
long_help: > | ||
Engine to lookup with. Run `dmenu --lookup --list-engines` | ||
to show available engines. More engines can be added at | ||
src/plugins/lookup/engines.rs during build time. | ||
long: engine | ||
takes_value: true | ||
requires: lookup | ||
- listEngines: # overrider doesn't like underscores | ||
help: List available engines | ||
long_help: > | ||
List available engines for lookup. Prints a newline seperated list to stdout. | ||
long: list-engines | ||
requires: lookup | ||
conflicts_with: engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use overrider::*; | ||
|
||
use crate::config::ConfigDefault; | ||
use crate::drw::Drw; | ||
use crate::item::Item; | ||
use crate::result::*; | ||
use crate::clapflags::CLAP_FLAGS; | ||
|
||
use unicode_segmentation::UnicodeSegmentation; | ||
|
||
#[override_flag(flag = maxlength)] | ||
impl Drw { | ||
pub fn postprocess_matches(&mut self, current_matches: Vec<Item>) -> CompResult<Vec<Item>> { | ||
let max_length_str_option = CLAP_FLAGS.value_of( "maxlength" ); | ||
|
||
match max_length_str_option | ||
{ | ||
None => { | ||
Err(Die::Stderr("Please specificy max length".to_owned())) | ||
}, | ||
Some( max_length_str ) => | ||
{ | ||
let max_length_result = max_length_str.parse::<usize>(); | ||
match max_length_result | ||
{ | ||
Err( _ ) => Err(Die::Stderr("Please specificy a positive integer for max length".to_owned())), | ||
Ok( 0 ) => Ok( current_matches ), | ||
Ok( max_length ) => { | ||
// >= in place of = in case someoen pastes stuff in | ||
// when there is a paste functionality. | ||
if self.input.graphemes(true).count() >= max_length | ||
{ | ||
self.dispose( self.input.graphemes(true).take( max_length ).collect(), true )?; | ||
Err(Die::Stdout("".to_owned())) | ||
} | ||
else | ||
{ | ||
Ok(current_matches) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[override_flag(flag = maxlength)] | ||
impl ConfigDefault { | ||
pub fn nostdin() -> bool { | ||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
about: | | ||
Specify a maximum length of input, | ||
usually used without menu items. | ||
Acts as a replacement for `i3-input -l` | ||
Pass --maxlength=<MAXLENGTH> to use | ||
entry: main.rs | ||
|
||
args: | ||
- maxlength: | ||
help: Limit maximum length of input | ||
long: maxlength | ||
takes_value: true | ||
value_name: MAXLENGTH | ||
# short: |