#http #client #cli-tools

bin+lib hors

instant coding answers via the command line(just like howdoi)

20 releases

0.7.1 Sep 15, 2020
0.6.2 Apr 19, 2020
0.6.1 Jan 30, 2020
0.5.0 Dec 9, 2019
0.3.3 Jun 3, 2019

#34 in Command line utilities

Download history 6/week @ 2020-06-08 17/week @ 2020-06-15 5/week @ 2020-06-22 15/week @ 2020-06-29 20/week @ 2020-07-06 36/week @ 2020-07-13 13/week @ 2020-07-20 4/week @ 2020-07-27 128/week @ 2020-08-03 163/week @ 2020-08-10 71/week @ 2020-08-17 73/week @ 2020-08-24 66/week @ 2020-08-31 74/week @ 2020-09-07 43/week @ 2020-09-14 44/week @ 2020-09-21

244 downloads per month

GPL-3.0 license

1.5MB
2K SLoC

Crate CI

hors

Awesome program howdoi which implemented in rust, along with easily usage lib.

For binary usage, please go through the rest of this file. For lib documentation, please check here.

Screenshot

Screenshots of hors

Installation

hors is written in Rust. The recommended way to install hors is through cargo.

cargo install hors

On Windows/Linux/macOS platform, you can download the pre-build-binary from github release page

On macOS

Hors can be installed from homebrew.

brew tap WindSoilder/hors && brew install hors

On Windows

Hors can be installed from scoop

scoop bucket add w-bucket https://github.com/WindSoilder/w-bucket; scoop install hors

Tested platforms

For now, hors has been tested with the following platforms:

  • Linux
  • OSX
  • Windows

Usage

USAGE:
    hors [FLAGS] [OPTIONS] [query]...

ARGS:
    <query>...

FLAGS:
    -a, --all              display the full text of answer.
    -d, --disable-proxy    Disable system proxy.
    -h, --help             Prints help information
    -l, --link             display only the answer link.
    -r, --raw              make raw output (not colorized).
    -V, --version          Prints version information

OPTIONS:
    -e, --engine <engine>                    select middle search engine, currently support `bing`, `google`,
                                             `duckduckgo`, `stackoverflow`. [env: HORS_ENGINE=bing]  [default:
                                             duckduckgo]
    -n, --number-answers <number-answers>    number of answers to return. [default: 1]
    -p, --paging <paging>                    specify how to page output, can be `auto`, `never` [default: auto]

Usage example

  1. Want to know how to export pandas dataframe to csv?
hors pandas dataframe to csv

Here it is:

- Answer from https://stackoverflow.com/questions/16923281/pandas-writing-dataframe-to-csv-file
df.to_csv(file_name, sep='\t')
  1. If we just want to know where is the answer existed?
hors pandas dataframe to csv -l

Here it is:

Title - pandas writing dataframe to csv file
https://stackoverflow.com/questions/16923281/pandas-writing-dataframe-to-csv-file
  1. If we want more about the answer detailed?
hors how to parse json in rust -a

Here it is:

- Answer from https://stackoverflow.com/questions/30292752/how-do-i-parse-a-json-file

Solved by the many helpful members of the Rust community:

extern crate rustc_serialize;
use rustc_serialize::json::Json;
use std::fs::File;
use std::io::Read;

fn main() {
    let mut file = File::open("text.json").unwrap();
    let mut data = String::new();
    file.read_to_string(&mut data).unwrap();

    let json = Json::from_str(&data).unwrap();
    println!("{}", json.find_path(&["Address", "Street"]).unwrap());
}
  1. How to get more than one answers
hors set git remote url -n 2 -a

Here it is:

- Answer from https://stackoverflow.com/questions/2432764/how-to-change-the-uri-url-for-a-remote-git-repository
You can

git remote set-url origin new.git.url/here

(see git help remote) or you can just edit .git/config and change the URLs there. You're not in any danger of losing history unless you do something very silly (and if you're worried, just make a copy of your repo, since your repo is your history.)


^_^ ==================================================== ^_^

- Answer from https://stackoverflow.com/questions/42830557/git-remote-add-origin-vs-remote-set-url-origin
below is used to a add a new remote:

git remote add origin git@github.com:User/UserRepo.git

below is used to change the url of an existing remote repository:

git remote set-url origin git@github.com:User/UserRepo.git

below will push your code to the master branch of the remote repository defined with origin and -u let you point your current local branch to the remote master branch:

git push -u origin master

Documentation
  1. The default search engine is bing, how can I use other search engine?
hors set git remote url -n 2 -a -e "google"

Proxy support

If the network seems blocked, you can try to configure proxy like this:

export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

Of course, it should be a valid proxy in your machine.

Paging feature on windows

Hors is using less command to make paging feature work, and it's not installed on Windows by default. You can use scoop to install less

scoop install less

Or use choco:

choco install less

Use hors as lib

Hors can be used as a lib, here is an example:

use std::str::FromStr;
use hors::{self, SearchEngine};

let search_engine: SearchEngine = SearchEngine::from_str("bing").unwrap();
let target_links: Vec<String> = hors::search_links(
    "how to parse json in rust",
    search_engine,
)
.await
.unwrap();
assert_ne!(target_links.len(), 0);
for link in target_links {
    assert!(link.contains("stackoverflow.com"));
}

For more information, please check the documentation

Special thanks

Very thanks for the awesome project and links :)

  • howdoi inspires hors (Fow now hors is howdoi which implements in rust).
  • stackoverflow helps users solve questions about coding.

About the name

hors is the abbreviation of howdoi in rust.

Dependencies

~10–15MB
~316K SLoC