zsh bin is sometimes /usr/bin/zsh or might be elsewhere too (#8)
zsh also uses ~/.zsh_history get better errors for not found history file
This commit is contained in:
parent
ea020f1b82
commit
6636f5878a
5 changed files with 45 additions and 38 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aead"
|
||||
version = "0.2.0"
|
||||
|
@ -109,7 +111,6 @@ dependencies = [
|
|||
"chrono",
|
||||
"directories",
|
||||
"eyre",
|
||||
"home",
|
||||
"hostname",
|
||||
"indicatif",
|
||||
"log 0.4.14",
|
||||
|
@ -543,15 +544,6 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hostname"
|
||||
version = "0.3.1"
|
||||
|
@ -1341,7 +1333,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||
dependencies = [
|
||||
"getrandom 0.2.2",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
19
Cargo.toml
19
Cargo.toml
|
@ -7,19 +7,18 @@ license = "MIT"
|
|||
description = "atuin - sync your shell history"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.*"
|
||||
pretty_env_logger = "0.4.*"
|
||||
chrono = "0.4.*"
|
||||
eyre = "0.6.*"
|
||||
shellexpand = "2.*"
|
||||
structopt = "0.3.*"
|
||||
directories = "3.*"
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
home = "0.5.3"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
chrono = "0.4"
|
||||
eyre = "0.6"
|
||||
shellexpand = "2"
|
||||
structopt = "0.3"
|
||||
directories = "3"
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
indicatif = "0.15.0"
|
||||
hostname = "0.3.1"
|
||||
rocket = "0.4.7"
|
||||
|
||||
[dependencies.rusqlite]
|
||||
version = "0.24.*"
|
||||
version = "0.24"
|
||||
features = ["bundled"]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use directories::UserDirs;
|
||||
use eyre::{eyre, Result};
|
||||
use home::home_dir;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::local::database::{Database, Sqlite};
|
||||
|
@ -39,7 +39,7 @@ impl Cmd {
|
|||
Self::Auto => {
|
||||
let shell = env::var("SHELL").unwrap_or_else(|_| String::from("NO_SHELL"));
|
||||
|
||||
if shell.as_str() == "/bin/zsh" {
|
||||
if shell.ends_with("/zsh") {
|
||||
println!("Detected ZSH");
|
||||
import_zsh(db)
|
||||
} else {
|
||||
|
@ -61,21 +61,34 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
|
|||
let histpath = env::var("HISTFILE");
|
||||
|
||||
let histpath = if let Ok(p) = histpath {
|
||||
PathBuf::from(p)
|
||||
let histpath = PathBuf::from(p);
|
||||
|
||||
if !histpath.exists() {
|
||||
return Err(eyre!(
|
||||
"Could not find history file at {}",
|
||||
histpath.to_str().unwrap()
|
||||
));
|
||||
}
|
||||
|
||||
histpath
|
||||
} else {
|
||||
let mut home = home_dir().unwrap();
|
||||
home.push(".zhistory");
|
||||
let user_dirs = UserDirs::new().unwrap();
|
||||
let home_dir = user_dirs.home_dir();
|
||||
|
||||
home
|
||||
let mut candidates = [".zhistory", ".zsh_history"].iter();
|
||||
loop {
|
||||
match candidates.next() {
|
||||
Some(candidate) => {
|
||||
let histpath = home_dir.join(candidate);
|
||||
if histpath.exists() {
|
||||
break histpath;
|
||||
}
|
||||
}
|
||||
None => return Err(eyre!("Could not find history file. try setting $HISTFILE")),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if !histpath.exists() {
|
||||
return Err(eyre!(
|
||||
"Could not find history file at {}, try setting $HISTFILE",
|
||||
histpath.to_str().unwrap()
|
||||
));
|
||||
}
|
||||
|
||||
let zsh = Zsh::new(histpath.to_str().unwrap())?;
|
||||
|
||||
let progress = ProgressBar::new(zsh.loc);
|
||||
|
|
|
@ -26,6 +26,10 @@ pub enum AtuinCmd {
|
|||
Uuid,
|
||||
}
|
||||
|
||||
pub fn uuid_v4() -> String {
|
||||
Uuid::new_v4().to_simple().to_string()
|
||||
}
|
||||
|
||||
impl AtuinCmd {
|
||||
pub fn run(self, db: &mut Sqlite) -> Result<()> {
|
||||
match self {
|
||||
|
@ -34,7 +38,7 @@ impl AtuinCmd {
|
|||
Self::Server(server) => server.run(),
|
||||
|
||||
Self::Uuid => {
|
||||
println!("{}", Uuid::new_v4().to_simple().to_string());
|
||||
println!("{}", uuid_v4());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::env;
|
||||
|
||||
use uuid::Uuid;
|
||||
use crate::command::uuid_v4;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct History {
|
||||
|
@ -26,12 +26,12 @@ impl History {
|
|||
) -> Self {
|
||||
let session = session
|
||||
.or_else(|| env::var("ATUIN_SESSION").ok())
|
||||
.unwrap_or_else(|| Uuid::new_v4().to_simple().to_string());
|
||||
.unwrap_or_else(uuid_v4);
|
||||
let hostname =
|
||||
hostname.unwrap_or_else(|| hostname::get().unwrap().to_str().unwrap().to_string());
|
||||
|
||||
Self {
|
||||
id: Uuid::new_v4().to_simple().to_string(),
|
||||
id: uuid_v4(),
|
||||
timestamp,
|
||||
command,
|
||||
cwd,
|
||||
|
|
Loading…
Reference in a new issue