Skip to content

Commit c82ef66

Browse files
committed
Release v0.5.0
1 parent 9dd1679 commit c82ef66

13 files changed

+92
-95
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## Unreleased
8+
## [0.5.0] - 2020-10-30
99

1010
### Added
1111

1212
- Inaccessible directories are no longer removed; zoxide can now remember paths on removable devices.
1313
- `$_ZO_EXCLUDE_DIRS` now supports globs.
1414
- `zoxide init` now defines `__zoxide_z*` functions that can be aliased as needed.
15+
- Support for the [xonsh](https://xon.sh/) shell.
16+
- `zoxide import` can now import from Autojump.
1517

1618
### Changed
1719

1820
- `zoxide init --no-aliases` no longer generates `z` or `zi`.
1921

2022
### Fixed
2123

22-
- Clobber conflicting alias definitions in Bash/POSIX/Zsh shells.
24+
- Clobber conflicting alias definitions in bash/fish/zsh/POSIX shells.
2325

2426
### Removed
2527

@@ -176,6 +178,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
176178
- GitHub Actions pipeline to build and upload releases.
177179
- Support for the `zsh` shell.
178180

181+
[0.5.0]: https://github.com/ajeetdsouza/zoxide/compare/v0.4.3...v0.5.0
179182
[0.4.3]: https://github.com/ajeetdsouza/zoxide/compare/v0.4.2...v0.4.3
180183
[0.4.2]: https://github.com/ajeetdsouza/zoxide/compare/v0.4.1...v0.4.2
181184
[0.4.1]: https://github.com/ajeetdsouza/zoxide/compare/v0.4.0...v0.4.1

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zoxide"
3-
version = "0.4.3"
3+
version = "0.5.0"
44
authors = ["Ajeet D'Souza <[email protected]>"]
55
description = "A faster way to navigate your filesystem"
66
repository = "https://github.com/ajeetdsouza/zoxide/"

README.md

+9-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ A faster way to navigate your filesystem
1717
- [fish](#fish)
1818
- [POSIX](#posix-shells)
1919
- [PowerShell](#powershell)
20+
- [xonsh](#xonsh)
2021
- [zsh](#zsh)
2122
- [Configuration](#configuration)
2223
- [`init` flags](#init-flags)
@@ -168,21 +169,6 @@ Add the following line to your shell's configuration file:
168169
eval "$(zoxide init posix --hook prompt)"
169170
```
170171

171-
The `prompt` hook is recommended for POSIX shells because the default `pwd`
172-
hook creates a temporary file for every session, which are only deleted upon
173-
reboot. If you do want to use `pwd` hooks instead, you may want to set up traps
174-
to perform a cleanup once the shell exits:
175-
176-
```sh
177-
trap '_zoxide_cleanup' EXIT HUP KILL TERM
178-
trap '_zoxide_cleanup; trap - INT; kill -s INT "$$"' INT
179-
trap '_zoxide_cleanup; trap - QUIT; kill -s QUIT "$$"' QUIT
180-
```
181-
182-
NOTE: If you modify your `PS1` at any point, you may need to re-run the above
183-
command. This is due to the fact that the hook is stored in `PS1`, in order to
184-
be evaluated every time the prompt is displayed.
185-
186172
#### PowerShell
187173

188174
Add the following line to your profile:
@@ -194,6 +180,14 @@ Invoke-Expression (& {
194180
})
195181
```
196182

183+
#### xonsh
184+
185+
Add the following line to your profile (usually `~/.xonshrc`):
186+
187+
```xonsh
188+
execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
189+
```
190+
197191
#### zsh
198192

199193
Add the following line to your `~/.zshrc`:

src/cmd/add.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cmd::Cmd;
1+
use super::Cmd;
22
use crate::config;
33
use crate::util;
44

src/cmd/import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cmd::Cmd;
1+
use super::Cmd;
22
use crate::config;
33
use crate::import::{Autojump, Import as _, Z};
44
use crate::util;

src/cmd/init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cmd::Cmd;
1+
use super::Cmd;
22
use crate::config;
33
use crate::shell::{self, Hook, Opts};
44

src/cmd/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod query;
55
mod remove;
66

77
use anyhow::Result;
8+
use clap::{AppSettings, Clap};
89

910
pub use add::Add;
1011
pub use import::Import;
@@ -15,3 +16,25 @@ pub use remove::Remove;
1516
pub trait Cmd {
1617
fn run(&self) -> Result<()>;
1718
}
19+
20+
#[derive(Debug, Clap)]
21+
#[clap(about, author, global_setting(AppSettings::GlobalVersion), global_setting(AppSettings::VersionlessSubcommands), version = env!("ZOXIDE_VERSION"))]
22+
pub enum App {
23+
Add(Add),
24+
Import(Import),
25+
Init(Init),
26+
Query(Query),
27+
Remove(Remove),
28+
}
29+
30+
impl Cmd for App {
31+
fn run(&self) -> Result<()> {
32+
match self {
33+
App::Add(cmd) => cmd.run(),
34+
App::Import(cmd) => cmd.run(),
35+
App::Init(cmd) => cmd.run(),
36+
App::Query(cmd) => cmd.run(),
37+
App::Remove(cmd) => cmd.run(),
38+
}
39+
}
40+
}

src/cmd/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cmd::Cmd;
1+
use super::Cmd;
22
use crate::config;
33
use crate::fzf::Fzf;
44
use crate::util;

src/cmd/remove.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cmd::Cmd;
1+
use super::Cmd;
22
use crate::config;
33
use crate::fzf::Fzf;
44
use crate::store::Query;
@@ -49,7 +49,11 @@ impl Cmd for Remove {
4949
};
5050

5151
if !store.remove(path) {
52-
bail!("path not found in store: {}", &path)
52+
let path = util::resolve_path(&path)?;
53+
let path = util::path_to_str(&path)?;
54+
if !store.remove(path) {
55+
bail!("path not found in store: {}", &path)
56+
}
5357
}
5458

5559
Ok(())

src/import/autojump.rs

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use super::Import;
2-
use crate::util;
32

43
use crate::store::{Dir, Epoch, Store};
54
use anyhow::{Context, Result};
65

7-
use std::fs::File;
8-
use std::io::{BufRead, BufReader};
6+
use std::fs;
97
use std::path::Path;
108

119
pub struct Autojump {
@@ -15,44 +13,50 @@ pub struct Autojump {
1513

1614
impl Import for Autojump {
1715
fn import<P: AsRef<Path>>(&self, store: &mut Store, path: P) -> Result<()> {
18-
let file = File::open(path).context("could not open autojump database")?;
19-
let reader = BufReader::new(file);
16+
let path = path.as_ref();
17+
let buffer = fs::read_to_string(path)
18+
.with_context(|| format!("could not open autojump database: {}", path.display()))?;
2019

21-
for (idx, line) in reader.lines().enumerate() {
20+
let mut entries = Vec::new();
21+
for (idx, line) in buffer.lines().enumerate() {
2222
(|| -> Result<()> {
23-
let line = line?;
2423
if line.is_empty() {
2524
return Ok(());
2625
}
2726

28-
let split_idx = line
29-
.find('\t')
30-
.with_context(|| format!("invalid entry: {}", line))?;
31-
let (rank, path) = line.split_at(split_idx);
27+
let (rank, path) = (|| {
28+
let mut split = line.splitn(2, '\t');
29+
let rank = split.next()?;
30+
let path = split.next()?;
31+
Some((rank, path))
32+
})()
33+
.with_context(|| format!("invalid entry: {}", line))?;
3234

3335
let rank = rank
34-
.parse()
36+
.parse::<f64>()
3537
.with_context(|| format!("invalid rank: {}", rank))?;
3638

37-
let path = if self.resolve_symlinks {
38-
util::canonicalize
39-
} else {
40-
util::resolve_path
41-
}(&path)?;
42-
let path = util::path_to_str(&path)?;
43-
44-
if store.dirs.iter_mut().find(|dir| dir.path == path).is_none() {
45-
store.dirs.push(Dir {
46-
path: path.into(),
47-
rank,
48-
last_accessed: self.now,
49-
});
50-
store.modified = true;
51-
}
52-
39+
entries.push((path, rank));
5340
Ok(())
5441
})()
55-
.with_context(|| format!("line {}: error reading from z database", idx + 1))?;
42+
.with_context(|| format!("line {}: error reading from autojump database", idx + 1))?;
43+
}
44+
45+
let rank_sum = entries.iter().map(|(_, rank)| rank).sum::<f64>();
46+
for (path, rank) in entries.iter() {
47+
if store
48+
.dirs
49+
.iter_mut()
50+
.find(|dir| &dir.path == path)
51+
.is_none()
52+
{
53+
store.dirs.push(Dir {
54+
path: path.to_string(),
55+
rank: rank / rank_sum,
56+
last_accessed: self.now,
57+
});
58+
store.modified = true;
59+
}
5660
}
5761

5862
Ok(())

src/import/z.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::Import;
2-
use crate::util;
32

43
use crate::store::{Dir, Store};
54
use anyhow::{Context, Result};
@@ -33,13 +32,6 @@ impl Import for Z {
3332
})()
3433
.with_context(|| format!("invalid entry: {}", line))?;
3534

36-
let path = if self.resolve_symlinks {
37-
util::canonicalize
38-
} else {
39-
util::resolve_path
40-
}(&path)?;
41-
let path = util::path_to_str(&path)?;
42-
4335
let rank = rank
4436
.parse()
4537
.with_context(|| format!("invalid rank: {}", rank))?;
@@ -54,7 +46,7 @@ impl Import for Z {
5446
dir.last_accessed = dir.last_accessed.max(last_accessed);
5547
}
5648
None => store.dirs.push(Dir {
57-
path: path.into(),
49+
path: path.to_string(),
5850
rank,
5951
last_accessed,
6052
}),

src/main.rs

+9-32
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,20 @@ mod shell;
77
mod store;
88
mod util;
99

10-
use crate::cmd::{Add, Cmd, Import, Init, Query, Remove};
10+
use crate::cmd::{App, Cmd};
1111
use crate::error::SilentExit;
1212

1313
use anyhow::Result;
14-
use clap::{AppSettings, Clap};
14+
use clap::Clap;
1515

1616
use std::process;
1717

18-
#[derive(Debug, Clap)]
19-
#[clap(
20-
about,
21-
author,
22-
global_setting(AppSettings::GlobalVersion),
23-
global_setting(AppSettings::VersionlessSubcommands),
24-
version = env!("ZOXIDE_VERSION"))]
25-
enum Opts {
26-
Add(Add),
27-
Import(Import),
28-
Init(Init),
29-
Query(Query),
30-
Remove(Remove),
31-
}
32-
3318
pub fn main() -> Result<()> {
34-
let opts = Opts::parse();
35-
36-
let result: Result<()> = match opts {
37-
Opts::Add(cmd) => cmd.run(),
38-
Opts::Import(cmd) => cmd.run(),
39-
Opts::Init(cmd) => cmd.run(),
40-
Opts::Query(cmd) => cmd.run(),
41-
Opts::Remove(cmd) => cmd.run(),
42-
};
43-
44-
result.map_err(|e| match e.downcast::<SilentExit>() {
45-
Ok(SilentExit { code }) => process::exit(code),
46-
// TODO: change the error prefix to `zoxide:`
47-
Err(e) => e,
48-
})
19+
App::parse()
20+
.run()
21+
.map_err(|e| match e.downcast::<SilentExit>() {
22+
Ok(SilentExit { code }) => process::exit(code),
23+
// TODO: change the error prefix to `zoxide:`
24+
Err(e) => e,
25+
})
4926
}

0 commit comments

Comments
 (0)