mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-25 09:44:03 +01:00
feat: start nushell hooks
This commit is contained in:
parent
72f2f59a11
commit
16f661cbe6
19
README.md
19
README.md
@ -165,6 +165,25 @@ Then setup Atuin
|
|||||||
echo 'eval "$(atuin init bash)"' >> ~/.bashrc
|
echo 'eval "$(atuin init bash)"' >> ~/.bashrc
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### nushell
|
||||||
|
|
||||||
|
#### Manual
|
||||||
|
|
||||||
|
Open up your config file in your editor (run `config path` to locate the file).
|
||||||
|
|
||||||
|
Add these two items to your startup section
|
||||||
|
|
||||||
|
```
|
||||||
|
"atuin init nushell | save ~/.atuin.nu",
|
||||||
|
"source ~/.atuin.nu",
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Automatic
|
||||||
|
|
||||||
|
```nu
|
||||||
|
config get startup | append 'atuin init nushell | save ~/.atuin.nu' | append 'source ~/.atuin.nu' | config set_into startup
|
||||||
|
```
|
||||||
|
|
||||||
## ...what's with the name?
|
## ...what's with the name?
|
||||||
|
|
||||||
Atuin is named after "The Great A'Tuin", a giant turtle from Terry Pratchett's
|
Atuin is named after "The Great A'Tuin", a giant turtle from Terry Pratchett's
|
||||||
|
@ -6,9 +6,9 @@ use eyre::Result;
|
|||||||
use crate::history::History;
|
use crate::history::History;
|
||||||
|
|
||||||
pub mod bash;
|
pub mod bash;
|
||||||
|
pub mod nu;
|
||||||
pub mod resh;
|
pub mod resh;
|
||||||
pub mod zsh;
|
pub mod zsh;
|
||||||
pub mod nu;
|
|
||||||
|
|
||||||
// this could probably be sped up
|
// this could probably be sped up
|
||||||
fn count_lines(buf: &mut BufReader<impl Read + Seek>) -> Result<usize> {
|
fn count_lines(buf: &mut BufReader<impl Read + Seek>) -> Result<usize> {
|
||||||
|
@ -35,10 +35,7 @@ impl Importer for Nu {
|
|||||||
let mut hist = history::History::new();
|
let mut hist = history::History::new();
|
||||||
hist.load(path)?;
|
hist.load(path)?;
|
||||||
let len = hist.len();
|
let len = hist.len();
|
||||||
Ok(Self {
|
Ok(Self { hist, iter: 0..len })
|
||||||
hist,
|
|
||||||
iter: 0..len,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ pub enum Cmd {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
pub fn print_list(h: &[History], human: bool, cmd_only: bool) {
|
pub fn print_list(h: &[History], human: bool, cmd_only: bool) {
|
||||||
let mut writer = TabWriter::new(std::io::stdout()).padding(2);
|
let mut writer = TabWriter::new(std::io::stdout()).padding(2);
|
||||||
|
|
||||||
|
@ -37,8 +37,9 @@ pub enum Cmd {
|
|||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
about="import history from the nu history file",
|
about="import history from the nu history file",
|
||||||
|
aliases=&["nu"],
|
||||||
)]
|
)]
|
||||||
Nu,
|
Nushell,
|
||||||
}
|
}
|
||||||
|
|
||||||
const BATCH_SIZE: usize = 100;
|
const BATCH_SIZE: usize = 100;
|
||||||
@ -72,7 +73,7 @@ impl Cmd {
|
|||||||
Self::Zsh => import::<Zsh<_>, _>(db, BATCH_SIZE).await,
|
Self::Zsh => import::<Zsh<_>, _>(db, BATCH_SIZE).await,
|
||||||
Self::Bash => import::<Bash<_>, _>(db, BATCH_SIZE).await,
|
Self::Bash => import::<Bash<_>, _>(db, BATCH_SIZE).await,
|
||||||
Self::Resh => import::<Resh, _>(db, BATCH_SIZE).await,
|
Self::Resh => import::<Resh, _>(db, BATCH_SIZE).await,
|
||||||
Self::Nu => import::<Nu, _>(db, BATCH_SIZE).await,
|
Self::Nushell => import::<Nu, _>(db, BATCH_SIZE).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ pub enum Cmd {
|
|||||||
Zsh,
|
Zsh,
|
||||||
#[structopt(about = "bash setup")]
|
#[structopt(about = "bash setup")]
|
||||||
Bash,
|
Bash,
|
||||||
|
#[structopt(about = "nu setup")]
|
||||||
|
Nushell,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_zsh() {
|
fn init_zsh() {
|
||||||
@ -19,11 +21,17 @@ fn init_bash() {
|
|||||||
println!("{}", full);
|
println!("{}", full);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_nu() {
|
||||||
|
let full = include_str!("../shell/atuin.nu");
|
||||||
|
println!("{}", full);
|
||||||
|
}
|
||||||
|
|
||||||
impl Cmd {
|
impl Cmd {
|
||||||
pub fn run(&self) -> Result<()> {
|
pub fn run(&self) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::Zsh => init_zsh(),
|
Self::Zsh => init_zsh(),
|
||||||
Self::Bash => init_bash(),
|
Self::Bash => init_bash(),
|
||||||
|
Self::Nushell => init_nu(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ struct State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
#[allow(clippy::clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
fn durations(&self) -> Vec<(String, String)> {
|
fn durations(&self) -> Vec<(String, String)> {
|
||||||
self.results
|
self.results
|
||||||
.iter()
|
.iter()
|
||||||
@ -179,7 +179,7 @@ async fn key_handler(
|
|||||||
app: &mut State,
|
app: &mut State,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
match input {
|
match input {
|
||||||
Key::Esc | Key::Ctrl('c') | Key::Ctrl('d') | Key::Ctrl('g') => {
|
Key::Esc | Key::Ctrl('c' | 'd' | 'g') => {
|
||||||
return Some(String::from(""))
|
return Some(String::from(""))
|
||||||
}
|
}
|
||||||
Key::Char('\n') => {
|
Key::Char('\n') => {
|
||||||
@ -241,7 +241,7 @@ async fn key_handler(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
fn draw<T: Backend>(f: &mut Frame<'_, T>, history_count: i64, app: &mut State) {
|
fn draw<T: Backend>(f: &mut Frame<'_, T>, history_count: i64, app: &mut State) {
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
@ -312,7 +312,7 @@ fn draw<T: Backend>(f: &mut Frame<'_, T>, history_count: i64, app: &mut State) {
|
|||||||
// this is a big blob of horrible! clean it up!
|
// this is a big blob of horrible! clean it up!
|
||||||
// for now, it works. But it'd be great if it were more easily readable, and
|
// for now, it works. But it'd be great if it were more easily readable, and
|
||||||
// modular. I'd like to add some more stats and stuff at some point
|
// modular. I'd like to add some more stats and stuff at some point
|
||||||
#[allow(clippy::clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
async fn select_history(
|
async fn select_history(
|
||||||
query: &[String],
|
query: &[String],
|
||||||
search_mode: SearchMode,
|
search_mode: SearchMode,
|
||||||
@ -350,7 +350,7 @@ async fn select_history(
|
|||||||
|
|
||||||
// This is supposed to more-or-less mirror the command line version, so ofc
|
// This is supposed to more-or-less mirror the command line version, so ofc
|
||||||
// it is going to have a lot of args
|
// it is going to have a lot of args
|
||||||
#[allow(clippy::clippy::clippy::too_many_arguments)]
|
#[allow(clippy::clippy::too_many_arguments)]
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
cwd: Option<String>,
|
cwd: Option<String>,
|
||||||
|
24
src/shell/atuin.nu
Normal file
24
src/shell/atuin.nu
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Default prompt for Nushell.
|
||||||
|
def __atuin_prompt [] {
|
||||||
|
let git = $'(do -i {git rev-parse --abbrev-ref HEAD} | str trim)'
|
||||||
|
let git = (if ($git | str length) == 0 {
|
||||||
|
''
|
||||||
|
} {
|
||||||
|
build-string (char lparen) (ansi cb) $git (ansi reset) (char rparen)
|
||||||
|
})
|
||||||
|
build-string (ansi gb) (pwd) (ansi reset) $git '> '
|
||||||
|
}
|
||||||
|
|
||||||
|
# Hook to add new entries to the database.
|
||||||
|
def __atuin_hook [] {
|
||||||
|
echo command took $CMD_DURATION_MS
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize hook.
|
||||||
|
let-env PROMPT_STRING = (
|
||||||
|
let prompt = (if ($nu.env | select PROMPT_STRING | empty?) {
|
||||||
|
if ($nu.config | select prompt | empty?) { '__atuin_prompt' } { $nu.config.prompt }
|
||||||
|
} { $nu.env.PROMPT_STRING });
|
||||||
|
|
||||||
|
if ($prompt | str contains '__atuin_hook') { $prompt } { $'__atuin_hook;($prompt)' }
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user