Add init command (#12)
* Add init command This makes setting up the shell part of A'tuin much easier. Eval the output of "atuin init". * Update readme, add up binding
This commit is contained in:
parent
e980973ba0
commit
41f072a8b4
8 changed files with 115 additions and 17 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -106,7 +106,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "atuin"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"chrono-english",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "atuin"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Ellie Huxtable <e@elm.sh>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
|
70
README.md
70
README.md
|
@ -25,15 +25,26 @@ As well as the expected command, A'tuin stores
|
|||
- time
|
||||
- a unique session ID
|
||||
|
||||
## Supported Shells
|
||||
|
||||
- zsh
|
||||
|
||||
## Requirements
|
||||
|
||||
- [fzf](https://github.com/junegunn/fzf)
|
||||
|
||||
## Install
|
||||
|
||||
### AUR
|
||||
|
||||
A'tuin is available on the [AUR](https://aur.archlinux.org/packages/atuin/)
|
||||
|
||||
```
|
||||
yay -S atuin # or your AUR helper of choice
|
||||
```
|
||||
|
||||
### With cargo
|
||||
|
||||
`atuin` needs a nightly version of Rust + Cargo! It's best to use
|
||||
[rustup](https://rustup.rs/) for getting set up there.
|
||||
|
||||
|
@ -44,6 +55,7 @@ cargo install atuin
|
|||
```
|
||||
|
||||
### From source
|
||||
|
||||
```
|
||||
rustup default nightly
|
||||
git clone https://github.com/ellie/atuin.git
|
||||
|
@ -52,25 +64,51 @@ cargo install --path .
|
|||
```
|
||||
|
||||
### Shell plugin
|
||||
Once the binary is installed, the shell plugin requires installing:
|
||||
|
||||
zplug:
|
||||
Once the binary is installed, the shell plugin requires installing. Add
|
||||
|
||||
```
|
||||
zplug "ellie/atuin", at:main
|
||||
eval "$(atuin init)"
|
||||
```
|
||||
|
||||
otherwise, clone the repo and `source /path/to/repo/atuin.plugin.zsh` in your `.zshrc`
|
||||
to your `.zshrc`/`.bashrc`/whatever your shell uses.
|
||||
|
||||
## 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`:
|
||||
### History search
|
||||
|
||||
By default A'tuin will rebind ctrl-r to use fzf to fuzzy search your history.
|
||||
It will also rebind the up arrow to use fzf, just without sorting. You can
|
||||
prevent this by putting
|
||||
|
||||
```
|
||||
export ATUIN_FUZZY=fzy
|
||||
export ATUIN_BINDKEYS="false"
|
||||
```
|
||||
|
||||
into your shell config.
|
||||
|
||||
You may also change the default history selection. The default behaviour will search your entire history, however
|
||||
|
||||
```
|
||||
export ATUIN_HISTORY="atuin history list --cwd"
|
||||
```
|
||||
|
||||
will switch to only searching history for the current directory.
|
||||
|
||||
Similarly,
|
||||
|
||||
```
|
||||
export ATUIN_HISTORY="atuin history list --session"
|
||||
```
|
||||
|
||||
will search for the current session only, and
|
||||
|
||||
```
|
||||
export ATUIN_HISTORY="atuin history list --session --cwd"
|
||||
```
|
||||
|
||||
will do both!
|
||||
|
||||
### Import history
|
||||
|
||||
```
|
||||
|
@ -83,10 +121,28 @@ atuin import zsh # specify shell
|
|||
|
||||
### List history
|
||||
|
||||
List all history
|
||||
|
||||
```
|
||||
atuin history list
|
||||
```
|
||||
|
||||
List history for the current directory
|
||||
|
||||
```
|
||||
atuin history list --cwd
|
||||
|
||||
atuin h l -c # alternative, shorter version
|
||||
```
|
||||
|
||||
List history for the current session
|
||||
|
||||
```
|
||||
atuin history list --session
|
||||
|
||||
atuin h l -s # similarly short
|
||||
```
|
||||
|
||||
### Stats
|
||||
|
||||
A'tuin can calculate statistics for a single day, and accepts "natural language" style date input, as well as absolute dates:
|
||||
|
|
|
@ -30,7 +30,7 @@ pub enum Cmd {
|
|||
)]
|
||||
List {
|
||||
#[structopt(long, short)]
|
||||
dir: bool,
|
||||
cwd: bool,
|
||||
|
||||
#[structopt(long, short)]
|
||||
session: bool,
|
||||
|
@ -77,13 +77,13 @@ impl Cmd {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
Self::List { session, dir, .. } => {
|
||||
Self::List { session, cwd, .. } => {
|
||||
const QUERY_SESSION: &str = "select * from history where session = ?;";
|
||||
const QUERY_DIR: &str = "select * from history where cwd = ?;";
|
||||
const QUERY_SESSION_DIR: &str =
|
||||
"select * from history where cwd = ?1 and session = ?2;";
|
||||
|
||||
let params = (session, dir);
|
||||
let params = (session, cwd);
|
||||
|
||||
let cwd = env::current_dir()?.display().to_string();
|
||||
let session = env::var("ATUIN_SESSION")?;
|
||||
|
|
19
src/command/init.rs
Normal file
19
src/command/init.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use std::env;
|
||||
|
||||
use eyre::{eyre, Result};
|
||||
|
||||
fn init_zsh() {
|
||||
let full = include_str!("../shell/atuin.zsh");
|
||||
println!("{}", full);
|
||||
}
|
||||
|
||||
pub fn init() -> Result<()> {
|
||||
let shell = env::var("SHELL")?;
|
||||
|
||||
if shell.ends_with("zsh") {
|
||||
init_zsh();
|
||||
Ok(())
|
||||
} else {
|
||||
Err(eyre!("Could not detect shell, or shell unsupported"))
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ use crate::local::database::Database;
|
|||
|
||||
mod history;
|
||||
mod import;
|
||||
mod init;
|
||||
mod server;
|
||||
mod stats;
|
||||
|
||||
|
@ -26,6 +27,9 @@ pub enum AtuinCmd {
|
|||
#[structopt(about = "calculate statistics for your history")]
|
||||
Stats(stats::Cmd),
|
||||
|
||||
#[structopt(about = "output shell setup")]
|
||||
Init,
|
||||
|
||||
#[structopt(about = "generates a UUID")]
|
||||
Uuid,
|
||||
}
|
||||
|
@ -41,6 +45,7 @@ impl AtuinCmd {
|
|||
Self::Import(import) => import.run(db),
|
||||
Self::Server(server) => server.run(),
|
||||
Self::Stats(stats) => stats.run(db),
|
||||
Self::Init => init::init(),
|
||||
|
||||
Self::Uuid => {
|
||||
println!("{}", uuid_v4());
|
||||
|
|
|
@ -25,7 +25,7 @@ mod remote;
|
|||
#[derive(StructOpt)]
|
||||
#[structopt(
|
||||
author = "Ellie Huxtable <e@elm.sh>",
|
||||
version = "0.3.1",
|
||||
version = "0.3.2",
|
||||
about = "Magical shell history"
|
||||
)]
|
||||
struct Atuin {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Source this in your ~/.zshrc
|
||||
export ATUIN_SESSION=$(atuin uuid)
|
||||
export ATUIN_FUZZY=fzf
|
||||
export ATUIN_HISTORY="atuin history list"
|
||||
export ATUIN_BINDKEYS="true"
|
||||
|
||||
_atuin_preexec(){
|
||||
id=$(atuin history start $1)
|
||||
|
@ -19,10 +20,23 @@ _atuin_search(){
|
|||
emulate -L zsh
|
||||
zle -I
|
||||
|
||||
output=$(atuin history list --distinct | $ATUIN_FUZZY)
|
||||
output=$(eval $ATUIN_HISTORY | fzf)
|
||||
|
||||
if [[ -n $output ]] ; then
|
||||
LBUFFER=$output
|
||||
BUFFER=$output
|
||||
fi
|
||||
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
_atuin_up_search(){
|
||||
emulate -L zsh
|
||||
zle -I
|
||||
|
||||
output=$(eval $ATUIN_HISTORY | fzf --no-sort --tac)
|
||||
|
||||
if [[ -n $output ]] ; then
|
||||
BUFFER=$output
|
||||
fi
|
||||
|
||||
zle reset-prompt
|
||||
|
@ -32,5 +46,9 @@ add-zsh-hook preexec _atuin_preexec
|
|||
add-zsh-hook precmd _atuin_precmd
|
||||
|
||||
zle -N _atuin_search_widget _atuin_search
|
||||
zle -N _atuin_up_search_widget _atuin_up_search
|
||||
|
||||
bindkey '^r' _atuin_search_widget
|
||||
if [[ $ATUIN_BINDKEYS == "true" ]]; then
|
||||
bindkey '^r' _atuin_search_widget
|
||||
bindkey '^[[A' _atuin_up_search_widget
|
||||
fi
|
Loading…
Reference in a new issue