summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2021-02-14 18:40:51 +0000
committerGitHub <noreply@github.com>2021-02-14 18:40:51 +0000
commit6636f5878ac11d6461b9958af025021486a7d58f (patch)
tree697d4c22700d0333213f66b88e36bdc2b25b6c99
parentea020f1b827e144cd3afcaf8c53423559f0b2233 (diff)
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
-rw-r--r--Cargo.lock13
-rw-r--r--Cargo.toml19
-rw-r--r--src/command/import.rs41
-rw-r--r--src/command/mod.rs6
-rw-r--r--src/local/history.rs6
5 files changed, 46 insertions, 39 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9d9fec56..588231d6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
@@ -544,15 +545,6 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1341,7 +1333,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom 0.2.2",
- "serde",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index c7184238..29d7df0e 100644
--- a/Cargo.toml
+++ b/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"]
diff --git a/src/command/import.rs b/src/command/import.rs
index 77db1c84..5a91b6b7 100644
--- a/src/command/import.rs
+++ b/src/command/import.rs
@@ -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,20 +61,33 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
let histpath = env::var("HISTFILE");
let histpath = if let Ok(p) = histpath {
- PathBuf::from(p)
- } else {
- let mut home = home_dir().unwrap();
- home.push(".zhistory");
+ let histpath = PathBuf::from(p);
- home
- };
+ if !histpath.exists() {
+ return Err(eyre!(
+ "Could not find history file at {}",
+ histpath.to_str().unwrap()
+ ));
+ }
- if !histpath.exists() {
- return Err(eyre!(
- "Could not find history file at {}, try setting $HISTFILE",
- histpath.to_str().unwrap()
- ));
- }
+ histpath
+ } else {
+ let user_dirs = UserDirs::new().unwrap();
+ let home_dir = user_dirs.home_dir();
+
+ 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")),
+ }
+ }
+ };
let zsh = Zsh::new(histpath.to_str().unwrap())?;
diff --git a/src/command/mod.rs b/src/command/mod.rs
index 4ac62385..2e8d4778 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -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(())
}
}
diff --git a/src/local/history.rs b/src/local/history.rs
index d88353f9..05600b80 100644
--- a/src/local/history.rs
+++ b/src/local/history.rs
@@ -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,