mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 11:33:10 +00:00
Fix path error on initial run (#313)
Fixes #312 This isn't idiomatic but it'll do for the time being
This commit is contained in:
parent
6ed7cd12b5
commit
65154663db
5 changed files with 29 additions and 19 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -250,7 +250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "navi"
|
||||
version = "2.4.0"
|
||||
version = "2.4.1"
|
||||
dependencies = [
|
||||
"anyhow 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "navi"
|
||||
version = "2.4.0"
|
||||
version = "2.4.1"
|
||||
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
|
||||
edition = "2018"
|
||||
description = "An interactive cheatsheet tool for the command-line"
|
||||
|
|
|
@ -5,7 +5,11 @@ export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
|
|||
|
||||
cd "$NAVI_HOME"
|
||||
|
||||
./scripts/action release x86_64-unknown-linux-musl
|
||||
|
||||
docker run \
|
||||
-e HOMEBREW_NO_AUTO_UPDATE=1 \
|
||||
-it linuxbrew/alpine \
|
||||
bash -c 'brew install denisidoro/tools/navirs; bash'
|
||||
-e HOMEBREW_NO_INSTALL_CLEANUP=1 \
|
||||
-v "$(pwd):/navi" \
|
||||
-it 'bashell/alpine-bash' \
|
||||
bash -c 'apk add git; apk add curl; git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && yes | ln -s /navi/target/debug/navi /usr/local/bin/navi; source $HOME/.bashrc; bash'
|
||||
|
|
|
@ -50,7 +50,7 @@ pub fn add(uri: String) -> Result<(), Error> {
|
|||
let tmp_path_str = filesystem::tmp_path_str()?;
|
||||
let tmp_path_str_with_trailing_slash = format!("{}/", &tmp_path_str);
|
||||
|
||||
filesystem::remove_dir(&tmp_path_str)?;
|
||||
let _ = filesystem::remove_dir(&tmp_path_str);
|
||||
filesystem::create_dir(&tmp_path_str)?;
|
||||
|
||||
eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);
|
||||
|
|
|
@ -3,10 +3,7 @@ use crate::filesystem;
|
|||
use crate::structures::cheat::VariableMap;
|
||||
use crate::structures::fnv::HashLine;
|
||||
use crate::structures::fzf::{Opts as FzfOpts, SuggestionType};
|
||||
use crate::structures::{
|
||||
error::filesystem::{InvalidPath, UnreadableDir},
|
||||
option::Config,
|
||||
};
|
||||
use crate::structures::{error::filesystem::InvalidPath, option::Config};
|
||||
use crate::welcome;
|
||||
use anyhow::{Context, Error};
|
||||
use regex::Regex;
|
||||
|
@ -226,21 +223,30 @@ pub fn read_all(
|
|||
let mut variables = VariableMap::new();
|
||||
let mut found_something = false;
|
||||
let mut visited_lines = HashSet::new();
|
||||
let paths = filesystem::cheat_paths(config)?;
|
||||
let paths = filesystem::cheat_paths(config);
|
||||
|
||||
if paths.is_err() {
|
||||
welcome::cheatsheet(stdin);
|
||||
return Ok(variables);
|
||||
}
|
||||
|
||||
let paths = paths.expect("Unable to get paths");
|
||||
let folders = paths_from_path_param(&paths);
|
||||
|
||||
for folder in folders {
|
||||
if let Ok(dir_entries) = fs::read_dir(folder) {
|
||||
for entry in dir_entries {
|
||||
let path = entry.map_err(|e| UnreadableDir::new(folder, e))?.path();
|
||||
let path_str = path
|
||||
.to_str()
|
||||
.ok_or_else(|| InvalidPath(path.to_path_buf()))?;
|
||||
if path_str.ends_with(".cheat")
|
||||
&& read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
|
||||
&& !found_something
|
||||
{
|
||||
found_something = true;
|
||||
if entry.is_ok() {
|
||||
let path = entry.expect("Impossible to read an invalid entry").path();
|
||||
let path_str = path
|
||||
.to_str()
|
||||
.ok_or_else(|| InvalidPath(path.to_path_buf()))?;
|
||||
if path_str.ends_with(".cheat")
|
||||
&& read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
|
||||
&& !found_something
|
||||
{
|
||||
found_something = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue