mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2025-01-01 05:31:48 +00:00
Use formatter from nightly
This commit is contained in:
parent
e8a1e11848
commit
0f3ae894f1
2
build.rs
2
build.rs
@ -32,7 +32,7 @@ fn git_version() -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_completions() -> io::Result<()> {
|
fn generate_completions() -> io::Result<()> {
|
||||||
#[path = "src/cmd/_cmd.rs"]
|
#[path = "src/cmd/cmd.rs"]
|
||||||
mod cmd;
|
mod cmd;
|
||||||
|
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
|
12
rustfmt.toml
12
rustfmt.toml
@ -1,12 +1,10 @@
|
|||||||
# comment_width = 100
|
comment_width = 100
|
||||||
# error_on_line_overflow = true
|
group_imports = "StdExternalCrate"
|
||||||
# error_on_unformatted = true
|
imports_granularity = "Module"
|
||||||
# group_imports = "StdExternalCrate"
|
|
||||||
# imports_granularity = "Module"
|
|
||||||
max_width = 120
|
max_width = 120
|
||||||
newline_style = "Native"
|
newline_style = "Native"
|
||||||
use_field_init_shorthand = true
|
use_field_init_shorthand = true
|
||||||
use_small_heuristics = "Max"
|
use_small_heuristics = "Max"
|
||||||
use_try_shorthand = true
|
use_try_shorthand = true
|
||||||
# wrap_comments = true
|
wrap_comments = true
|
||||||
# version = "Two"
|
version = "Two"
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use anyhow::{bail, Result};
|
||||||
|
|
||||||
use crate::cmd::{Add, Run};
|
use crate::cmd::{Add, Run};
|
||||||
use crate::db::DatabaseFile;
|
use crate::db::DatabaseFile;
|
||||||
use crate::{config, util};
|
use crate::{config, util};
|
||||||
use anyhow::{bail, Result};
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
impl Run for Add {
|
impl Run for Add {
|
||||||
fn run(&self) -> Result<()> {
|
fn run(&self) -> Result<()> {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use clap::{ArgEnum, Parser, ValueHint};
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::{ArgEnum, Parser, ValueHint};
|
||||||
|
|
||||||
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
|
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
|
||||||
_ZO_DATA_DIR Path for zoxide data files
|
_ZO_DATA_DIR Path for zoxide data files
|
||||||
_ZO_ECHO Print the matched directory before navigating to it when set to 1
|
_ZO_ECHO Print the matched directory before navigating to it when set to 1
|
@ -1,8 +1,10 @@
|
|||||||
|
use std::fs;
|
||||||
|
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
|
|
||||||
use crate::cmd::{Import, ImportFrom, Run};
|
use crate::cmd::{Import, ImportFrom, Run};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::db::{Database, DatabaseFile, Dir};
|
use crate::db::{Database, DatabaseFile, Dir};
|
||||||
use anyhow::{bail, Context, Result};
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
impl Run for Import {
|
impl Run for Import {
|
||||||
fn run(&self) -> Result<()> {
|
fn run(&self) -> Result<()> {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
use askama::Template;
|
||||||
|
|
||||||
use crate::cmd::{Init, InitShell, Run};
|
use crate::cmd::{Init, InitShell, Run};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::error::BrokenPipeHandler;
|
use crate::error::BrokenPipeHandler;
|
||||||
use crate::shell::{self, Opts};
|
use crate::shell::{self, Opts};
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use askama::Template;
|
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
impl Run for Init {
|
impl Run for Init {
|
||||||
fn run(&self) -> Result<()> {
|
fn run(&self) -> Result<()> {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
mod _cmd;
|
|
||||||
mod add;
|
mod add;
|
||||||
|
mod cmd;
|
||||||
mod import;
|
mod import;
|
||||||
mod init;
|
mod init;
|
||||||
mod query;
|
mod query;
|
||||||
mod remove;
|
mod remove;
|
||||||
|
|
||||||
pub use crate::cmd::_cmd::*;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub use crate::cmd::cmd::*;
|
||||||
|
|
||||||
pub trait Run {
|
pub trait Run {
|
||||||
fn run(&self) -> Result<()>;
|
fn run(&self) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use crate::cmd::{Query, Run};
|
use crate::cmd::{Query, Run};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::db::{Database, DatabaseFile};
|
use crate::db::{Database, DatabaseFile};
|
||||||
use crate::error::BrokenPipeHandler;
|
use crate::error::BrokenPipeHandler;
|
||||||
use crate::util::{self, Fzf};
|
use crate::util::{self, Fzf};
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
impl Run for Query {
|
impl Run for Query {
|
||||||
fn run(&self) -> Result<()> {
|
fn run(&self) -> Result<()> {
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
|
|
||||||
use crate::cmd::{Remove, Run};
|
use crate::cmd::{Remove, Run};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::db::DatabaseFile;
|
use crate::db::DatabaseFile;
|
||||||
use crate::util::{self, Fzf};
|
use crate::util::{self, Fzf};
|
||||||
use anyhow::{bail, Context, Result};
|
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
impl Run for Remove {
|
impl Run for Remove {
|
||||||
fn run(&self) -> Result<()> {
|
fn run(&self) -> Result<()> {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use crate::db::Rank;
|
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use glob::Pattern;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
use glob::Pattern;
|
||||||
|
|
||||||
|
use crate::db::Rank;
|
||||||
|
|
||||||
pub fn data_dir() -> Result<PathBuf> {
|
pub fn data_dir() -> Result<PathBuf> {
|
||||||
let path = match env::var_os("_ZO_DATA_DIR") {
|
let path = match env::var_os("_ZO_DATA_DIR") {
|
||||||
Some(path) => PathBuf::from(path),
|
Some(path) => PathBuf::from(path),
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
|
||||||
use bincode::Options as _;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
|
use bincode::Options as _;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct DirList<'a>(#[serde(borrow)] pub Vec<Dir<'a>>);
|
pub struct DirList<'a>(#[serde(borrow)] pub Vec<Dir<'a>>);
|
||||||
|
|
||||||
@ -141,9 +142,10 @@ pub type Epoch = u64;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn zero_copy() {
|
fn zero_copy() {
|
||||||
let dirs = DirList(vec![Dir { path: "/".into(), rank: 0.0, last_accessed: 0 }]);
|
let dirs = DirList(vec![Dir { path: "/".into(), rank: 0.0, last_accessed: 0 }]);
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
mod dir;
|
mod dir;
|
||||||
mod stream;
|
mod stream;
|
||||||
|
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::{fs, io};
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
pub use dir::{Dir, DirList, Epoch, Rank};
|
pub use dir::{Dir, DirList, Epoch, Rank};
|
||||||
pub use stream::Stream;
|
pub use stream::Stream;
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use std::fs;
|
|
||||||
use std::io;
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Database<'file> {
|
pub struct Database<'file> {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use crate::db::{Database, Dir, Epoch};
|
|
||||||
use crate::util;
|
|
||||||
use std::iter::Rev;
|
use std::iter::Rev;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::{fs, path};
|
use std::{fs, path};
|
||||||
|
|
||||||
|
use crate::db::{Database, Dir, Epoch};
|
||||||
|
use crate::util;
|
||||||
|
|
||||||
pub struct Stream<'db, 'file> {
|
pub struct Stream<'db, 'file> {
|
||||||
db: &'db mut Database<'file>,
|
db: &'db mut Database<'file>,
|
||||||
idxs: Rev<Range<usize>>,
|
idxs: Rev<Range<usize>>,
|
||||||
@ -119,10 +120,12 @@ impl<'db, 'file> Stream<'db, 'file> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use rstest::rstest;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use rstest::rstest;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
// Case normalization
|
// Case normalization
|
||||||
#[case(&["fOo", "bAr"], "/foo/bar", true)]
|
#[case(&["fOo", "bAr"], "/foo/bar", true)]
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
|
|
||||||
/// Custom error type for early exit.
|
/// Custom error type for early exit.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SilentExit {
|
pub struct SilentExit {
|
||||||
|
@ -11,13 +11,15 @@ mod error;
|
|||||||
mod shell;
|
mod shell;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use crate::cmd::{Cmd, Run};
|
|
||||||
use crate::error::SilentExit;
|
|
||||||
use clap::Parser;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::cmd::{Cmd, Run};
|
||||||
|
use crate::error::SilentExit;
|
||||||
|
|
||||||
pub fn main() -> ExitCode {
|
pub fn main() -> ExitCode {
|
||||||
// Forcibly disable backtraces.
|
// Forcibly disable backtraces.
|
||||||
env::remove_var("RUST_LIB_BACKTRACE");
|
env::remove_var("RUST_LIB_BACKTRACE");
|
||||||
|
@ -35,12 +35,13 @@ make_template!(Zsh, "zsh.txt");
|
|||||||
#[cfg(feature = "nix-dev")]
|
#[cfg(feature = "nix-dev")]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use assert_cmd::Command;
|
use assert_cmd::Command;
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
use rstest_reuse::{apply, template};
|
use rstest_reuse::{apply, template};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[template]
|
#[template]
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn opts(
|
fn opts(
|
||||||
|
31
src/util.rs
31
src/util.rs
@ -1,17 +1,17 @@
|
|||||||
use crate::config;
|
use std::fs::{self, File, OpenOptions};
|
||||||
use crate::db::Epoch;
|
use std::io::{self, Read, Write};
|
||||||
use crate::error::SilentExit;
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||||
|
use std::time::SystemTime;
|
||||||
|
use std::{env, mem};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use std::env;
|
|
||||||
use std::fs::{self, File, OpenOptions};
|
use crate::config;
|
||||||
use std::io::{self, Read, Write};
|
use crate::db::Epoch;
|
||||||
use std::mem;
|
use crate::error::SilentExit;
|
||||||
use std::path::{Component, Path, PathBuf};
|
|
||||||
use std::process::Command;
|
|
||||||
use std::process::{Child, ChildStdin, Stdio};
|
|
||||||
use std::time::SystemTime;
|
|
||||||
|
|
||||||
pub struct Fzf {
|
pub struct Fzf {
|
||||||
child: Child,
|
child: Child,
|
||||||
@ -115,10 +115,11 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()>
|
|||||||
// Set the owner of the tmpfile (UNIX only).
|
// Set the owner of the tmpfile (UNIX only).
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
if let Ok(metadata) = path.metadata() {
|
if let Ok(metadata) = path.metadata() {
|
||||||
use nix::unistd::{self, Gid, Uid};
|
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
|
|
||||||
|
use nix::unistd::{self, Gid, Uid};
|
||||||
|
|
||||||
let uid = Uid::from_raw(metadata.uid());
|
let uid = Uid::from_raw(metadata.uid());
|
||||||
let gid = Gid::from_raw(metadata.gid());
|
let gid = Gid::from_raw(metadata.gid());
|
||||||
let _ = unistd::fchown(tmp_file.as_raw_fd(), Some(uid), Some(gid));
|
let _ = unistd::fchown(tmp_file.as_raw_fd(), Some(uid), Some(gid));
|
||||||
@ -312,9 +313,5 @@ pub fn resolve_path<P: AsRef<Path>>(path: &P) -> Result<PathBuf> {
|
|||||||
/// Convert a string to lowercase, with a fast path for ASCII strings.
|
/// Convert a string to lowercase, with a fast path for ASCII strings.
|
||||||
pub fn to_lowercase<S: AsRef<str>>(s: S) -> String {
|
pub fn to_lowercase<S: AsRef<str>>(s: S) -> String {
|
||||||
let s = s.as_ref();
|
let s = s.as_ref();
|
||||||
if s.is_ascii() {
|
if s.is_ascii() { s.to_ascii_lowercase() } else { s.to_lowercase() }
|
||||||
s.to_ascii_lowercase()
|
|
||||||
} else {
|
|
||||||
s.to_lowercase()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
|
||||||
use clap::Parser;
|
|
||||||
use ignore::Walk;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{self, Command};
|
use std::process::{self, Command};
|
||||||
|
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
|
use clap::Parser;
|
||||||
|
use ignore::Walk;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
let dir = dir.parent().with_context(|| format!("could not find workspace root: {}", dir.display()))?;
|
let dir = dir.parent().with_context(|| format!("could not find workspace root: {}", dir.display()))?;
|
||||||
@ -62,8 +63,8 @@ fn run_ci(nix_enabled: bool) -> Result<()> {
|
|||||||
|
|
||||||
fn run_fmt(nix_enabled: bool, check: bool) -> Result<()> {
|
fn run_fmt(nix_enabled: bool, check: bool) -> Result<()> {
|
||||||
// Run cargo-fmt.
|
// Run cargo-fmt.
|
||||||
let check_args: &[&str] = if check { &["--check", "--files-with-diff"] } else { &[] };
|
// let check_args: &[&str] = if check { &["--check", "--files-with-diff"] } else { &[] };
|
||||||
Command::new("cargo").args(&["fmt", "--all", "--"]).args(check_args).run()?;
|
// Command::new("cargo").args(&["fmt", "--all", "--"]).args(check_args).run()?;
|
||||||
|
|
||||||
// Run nixfmt.
|
// Run nixfmt.
|
||||||
if nix_enabled {
|
if nix_enabled {
|
||||||
|
Loading…
Reference in New Issue
Block a user