Merge branch 'master' into feature/travis

This commit is contained in:
Ingolf Wagner 2020-03-16 20:48:59 +08:00
commit 8f0a686ddb
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
8 changed files with 80 additions and 48 deletions

View file

@ -38,5 +38,5 @@ jobs:
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/tar/navi.tar.gz
asset_name: navi-${{ matrix.target }}.tar.gz
tag: ${{ github.ref }}
tag: ${{ github.ref }}
asset_name: navi-${{ github.ref }}-${{ matrix.target }}.tar.gz

27
Cargo.lock generated
View file

@ -209,25 +209,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libssh2-sys"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
"vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libz-sys"
version = "1.0.25"
@ -259,7 +245,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "navi"
version = "2.1.1"
version = "2.1.2"
dependencies = [
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -282,14 +268,6 @@ name = "openssl-probe"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "openssl-src"
version = "111.6.1+1.1.1d"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "openssl-sys"
version = "0.9.54"
@ -298,7 +276,6 @@ dependencies = [
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-src 111.6.1+1.1.1d (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
"vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -685,14 +662,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
"checksum libgit2-sys 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4870c781f6063efb83150cd22c1ddf6ecf58531419e7570cdcced46970f64a16"
"checksum libssh2-sys 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "7bb70f29dc7c31d32c97577f13f41221af981b31248083e347b7f2c39225a6bc"
"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-src 111.6.1+1.1.1d (registry+https://github.com/rust-lang/crates.io-index)" = "c91b04cb43c1a8a90e934e0cd612e2a5715d976d2d6cff4490278a0cddf35005"
"checksum openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)" = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986"
"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"

View file

@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.1.1"
version = "2.1.2"
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
@ -22,13 +22,17 @@ raw_tty = "0.1.0"
lazy_static = "1.4.0"
dirs = "2.0.0"
terminal_size = "0.1.10"
git2 = "0.10.0"
walkdir = "2"
[dependencies.git2]
version = "0.10.0"
default-features = false
features = ["https"]
[target.'cfg(target_os = "macos")'.dependencies.git2]
features = [ "vendored-openssl" ]
[[bin]]
bench = false
path = "src/main.rs"

View file

@ -6,12 +6,12 @@ An interactive cheatsheet tool for the command-line.
![Demo](https://user-images.githubusercontent.com/3226564/76437136-ddc35900-6397-11ea-823c-d2da7615fe60.gif)
**navi** allows you to browse through cheatsheets (that you may write yourself or download from maintainers) and execute commands. Argument suggestions are prompted to you.
**navi** allows you to browse through cheatsheets (that you may write yourself or download from maintainers) and execute commands. Argument suggestions are prompted to you.
It will:
- make you type less;
- spare you from knowing CLIs by heart;
- teach you new one-liners.
#### Pros
- it will make you type less;
- it will spare you from knowing CLIs by heart;
- it will teach you new one-liners.
It uses [fzf](https://github.com/junegunn/fzf) under the hood and it can be either used as a command or as a shell widget (*à la* Ctrl-R).

View file

@ -64,7 +64,7 @@ asset_url() {
local -r variant="${2:-}"
if [[ -n "$variant" ]]; then
echo "https://github.com/denisidoro/navi/releases/download/v${version}/navi-${variant}.tar.gz"
echo "https://github.com/denisidoro/navi/releases/download/v${version}/navi-v${version}-${variant}.tar.gz"
else
echo "https://github.com/denisidoro/navi/archive/v${version}.tar.gz"
fi
@ -97,8 +97,8 @@ get_target() {
local target
case "$archi" in
Darwin*) target="x86_64-osx" ;;
Linux\ *x86*) is_android && target="aarch64-linux-android" || target="x86_64-unknown-linux-musl" ;;
*arm*) is_android && target="armv7-linux-androideabi" || target="armv7-unknown-linux-musleabihf" ;;
Linux\ *x86*) $is_android && target="aarch64-linux-android" || target="x86_64-unknown-linux-musl" ;;
*arm*) $is_android && target="armv7-linux-androideabi" || target="armv7-unknown-linux-musleabihf" ;;
*) target="" ;;
esac
@ -113,6 +113,18 @@ get_shell() {
echo $SHELL | xargs basename
}
installation_finish_instructions() {
local -r shell="$(get_shell)"
echoerr -e "Finished. To call navi, restart your shell or reload the config file:\n source ~/.${shell}rc"
local code
if [[ $shell = "zsh" ]]; then
code="navi widget ${shell} | source"
else
code="source <(navi widget ${shell})"
fi
echoerr -e "\nTo add the Ctrl-G keybinding, add the following to ~/.${shell}rc:\n ${code}"
}
install_navi() {
export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
export BIN_DIR="${BIN_DIR:-"$(get_bin_dir)"}"

View file

@ -1,6 +1,7 @@
use crate::cheat::SuggestionType;
use crate::filesystem;
use crate::fzf;
use crate::git;
use git2::Repository;
use std::error::Error;
use std::fs;
@ -8,15 +9,7 @@ use std::io::Write;
use walkdir::WalkDir;
pub fn add(uri: String) -> Result<(), Box<dyn Error>> {
let actual_uri = if uri.contains("://") || uri.contains('@') {
uri
} else {
format!("https://github.com/{}", uri)
};
let parts: Vec<&str> = actual_uri.split('/').collect();
let user = parts[parts.len() - 2];
let repo = parts[parts.len() - 1].replace(".git", "");
let (actual_uri, user, repo) = git::meta(uri.as_str());
let cheat_path_str = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap());
let tmp_path_str = format!("{}/tmp", cheat_path_str);

47
src/git.rs Normal file
View file

@ -0,0 +1,47 @@
pub fn meta(uri: &str) -> (String, String, String) {
let actual_uri = if uri.contains("://") {
uri.to_string()
} else if uri.contains('@') {
uri.replace(':', "/").replace("git@", "https://")
} else {
format!("https://github.com/{}", uri)
};
let parts: Vec<&str> = actual_uri.split('/').collect();
let user = parts[parts.len() - 2];
let repo = parts[parts.len() - 1].replace(".git", "");
(actual_uri.clone(), user.to_string(), repo)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_meta_github_https() {
let (actual_uri, user, repo) = meta("https://github.com/denisidoro/navi");
assert_eq!(actual_uri, "https://github.com/denisidoro/navi".to_string());
assert_eq!(user, "denisidoro".to_string());
assert_eq!(repo, "navi".to_string());
}
#[test]
fn test_meta_github_ssh() {
let (actual_uri, user, repo) = meta("git@github.com:denisidoro/navi.git");
assert_eq!(
actual_uri,
"https://github.com/denisidoro/navi.git".to_string()
);
assert_eq!(user, "denisidoro".to_string());
assert_eq!(repo, "navi".to_string());
}
#[test]
fn test_meta_gitlab_https() {
let (actual_uri, user, repo) = meta("https://gitlab.com/user/repo.git");
assert_eq!(actual_uri, "https://gitlab.com/user/repo.git".to_string());
assert_eq!(user, "user".to_string());
assert_eq!(repo, "repo".to_string());
}
}

View file

@ -6,6 +6,7 @@ mod cmds;
mod display;
mod filesystem;
mod fzf;
mod git;
mod handler;
mod option;
mod terminal;