Add fuzzy history search and distinct arg
This commit is contained in:
parent
3e7af55a9c
commit
d8aacb4a80
6 changed files with 42 additions and 23 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -49,7 +49,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atuin"
|
name = "atuin"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"directories",
|
"directories",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "atuin"
|
name = "atuin"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
authors = ["Ellie Huxtable <e@elm.sh>"]
|
authors = ["Ellie Huxtable <e@elm.sh>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
10
README.md
10
README.md
|
@ -51,10 +51,20 @@ and then add `atuin` to your `plugins` list in `~/.zshrc`
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
By default A'tuin will rebind ctrl-r to use fzf to fuzzy search your history. You
|
||||||
|
can specify a different fuzzy tool by changing the value of `ATUIN_FUZZY`:
|
||||||
|
|
||||||
|
```
|
||||||
|
export ATUIN_FUZZY=fzy
|
||||||
|
```
|
||||||
|
|
||||||
### Import history
|
### Import history
|
||||||
|
|
||||||
```
|
```
|
||||||
atuin import auto # detect shell, then import
|
atuin import auto # detect shell, then import
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
atuin import zsh # specify shell
|
atuin import zsh # specify shell
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Source this in your ~/.zshrc
|
# Source this in your ~/.zshrc
|
||||||
export ATUIN_SESSION=$(atuin uuid)
|
export ATUIN_SESSION=$(atuin uuid)
|
||||||
|
export ATUIN_FUZZY=fzf
|
||||||
|
|
||||||
_atuin_preexec(){
|
_atuin_preexec(){
|
||||||
id=$(atuin history start $1)
|
id=$(atuin history start $1)
|
||||||
|
@ -14,5 +15,14 @@ _atuin_precmd(){
|
||||||
atuin history end $ATUIN_HISTORY_ID --exit $EXIT
|
atuin history end $ATUIN_HISTORY_ID --exit $EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_atuin_search(){
|
||||||
|
$(atuin history list --distinct | $ATUIN_FUZZY)
|
||||||
|
}
|
||||||
|
|
||||||
add-zsh-hook preexec _atuin_preexec
|
add-zsh-hook preexec _atuin_preexec
|
||||||
add-zsh-hook precmd _atuin_precmd
|
add-zsh-hook precmd _atuin_precmd
|
||||||
|
|
||||||
|
zle -N _atuin_search_widget _atuin_search
|
||||||
|
|
||||||
|
bindkey -r '^r'
|
||||||
|
bindkey '^r' _atuin_search_widget
|
||||||
|
|
|
@ -28,7 +28,10 @@ pub enum HistoryCmd {
|
||||||
about="list all items in history",
|
about="list all items in history",
|
||||||
aliases=&["l", "li", "lis"],
|
aliases=&["l", "li", "lis"],
|
||||||
)]
|
)]
|
||||||
List,
|
List {
|
||||||
|
#[structopt(long)]
|
||||||
|
distinct: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryCmd {
|
impl HistoryCmd {
|
||||||
|
@ -65,7 +68,7 @@ impl HistoryCmd {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryCmd::List => db.list(),
|
HistoryCmd::List { distinct } => db.list(*distinct),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub trait Database {
|
||||||
fn save(&mut self, h: History) -> Result<()>;
|
fn save(&mut self, h: History) -> Result<()>;
|
||||||
fn save_bulk(&mut self, h: &Vec<History>) -> Result<()>;
|
fn save_bulk(&mut self, h: &Vec<History>) -> Result<()>;
|
||||||
fn load(&self, id: &str) -> Result<History>;
|
fn load(&self, id: &str) -> Result<History>;
|
||||||
fn list(&self) -> Result<()>;
|
fn list(&self, distinct: bool) -> Result<()>;
|
||||||
fn update(&self, h: History) -> Result<()>;
|
fn update(&self, h: History) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,33 +149,29 @@ impl Database for SqliteDatabase {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(&self) -> Result<()> {
|
fn list(&self, distinct: bool) -> Result<()> {
|
||||||
debug!("listing history");
|
debug!("listing history");
|
||||||
|
|
||||||
let mut stmt = self.conn.prepare(
|
let mut stmt = match distinct {
|
||||||
"SELECT id, timestamp, duration, exit, command, cwd, session, hostname FROM history",
|
false => self
|
||||||
)?;
|
.conn
|
||||||
|
.prepare("SELECT command FROM history order by timestamp asc")?,
|
||||||
|
|
||||||
|
true => self
|
||||||
|
.conn
|
||||||
|
.prepare("SELECT distinct command FROM history order by timestamp asc")?,
|
||||||
|
};
|
||||||
|
|
||||||
let history_iter = stmt.query_map(params![], |row| {
|
let history_iter = stmt.query_map(params![], |row| {
|
||||||
Ok(History {
|
let command: String = row.get(0)?;
|
||||||
id: row.get(0)?,
|
|
||||||
timestamp: row.get(1)?,
|
Ok(command)
|
||||||
duration: row.get(2)?,
|
|
||||||
exit: row.get(3)?,
|
|
||||||
command: row.get(4)?,
|
|
||||||
cwd: row.get(5)?,
|
|
||||||
session: row.get(6)?,
|
|
||||||
hostname: row.get(7)?,
|
|
||||||
})
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
for h in history_iter {
|
for h in history_iter {
|
||||||
let h = h.unwrap();
|
let h = h.unwrap();
|
||||||
|
|
||||||
println!(
|
println!("{}", h);
|
||||||
"{} | {} | {} | {} | {} | {} | {}",
|
|
||||||
h.timestamp, h.hostname, h.session, h.cwd, h.duration, h.exit, h.command
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue