mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-12-28 11:50:56 +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<()> {
|
||||
#[path = "src/cmd/_cmd.rs"]
|
||||
#[path = "src/cmd/cmd.rs"]
|
||||
mod cmd;
|
||||
|
||||
use clap::CommandFactory;
|
||||
|
12
rustfmt.toml
12
rustfmt.toml
@ -1,12 +1,10 @@
|
||||
# comment_width = 100
|
||||
# error_on_line_overflow = true
|
||||
# error_on_unformatted = true
|
||||
# group_imports = "StdExternalCrate"
|
||||
# imports_granularity = "Module"
|
||||
comment_width = 100
|
||||
group_imports = "StdExternalCrate"
|
||||
imports_granularity = "Module"
|
||||
max_width = 120
|
||||
newline_style = "Native"
|
||||
use_field_init_shorthand = true
|
||||
use_small_heuristics = "Max"
|
||||
use_try_shorthand = true
|
||||
# wrap_comments = true
|
||||
# version = "Two"
|
||||
wrap_comments = true
|
||||
version = "Two"
|
||||
|
@ -1,8 +1,10 @@
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use crate::cmd::{Add, Run};
|
||||
use crate::db::DatabaseFile;
|
||||
use crate::{config, util};
|
||||
use anyhow::{bail, Result};
|
||||
use std::path::Path;
|
||||
|
||||
impl Run for Add {
|
||||
fn run(&self) -> Result<()> {
|
||||
|
@ -1,6 +1,9 @@
|
||||
use clap::{ArgEnum, Parser, ValueHint};
|
||||
#![allow(clippy::module_inception)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{ArgEnum, Parser, ValueHint};
|
||||
|
||||
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
|
||||
_ZO_DATA_DIR Path for zoxide data files
|
||||
_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::config;
|
||||
use crate::db::{Database, DatabaseFile, Dir};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::fs;
|
||||
|
||||
impl Run for Import {
|
||||
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::config;
|
||||
use crate::error::BrokenPipeHandler;
|
||||
use crate::shell::{self, Opts};
|
||||
use anyhow::{Context, Result};
|
||||
use askama::Template;
|
||||
use std::io::{self, Write};
|
||||
|
||||
impl Run for Init {
|
||||
fn run(&self) -> Result<()> {
|
||||
|
@ -1,14 +1,14 @@
|
||||
mod _cmd;
|
||||
mod add;
|
||||
mod cmd;
|
||||
mod import;
|
||||
mod init;
|
||||
mod query;
|
||||
mod remove;
|
||||
|
||||
pub use crate::cmd::_cmd::*;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
pub use crate::cmd::cmd::*;
|
||||
|
||||
pub trait Run {
|
||||
fn run(&self) -> Result<()>;
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
use std::io::{self, Write};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use crate::cmd::{Query, Run};
|
||||
use crate::config;
|
||||
use crate::db::{Database, DatabaseFile};
|
||||
use crate::error::BrokenPipeHandler;
|
||||
use crate::util::{self, Fzf};
|
||||
use anyhow::{Context, Result};
|
||||
use std::io::{self, Write};
|
||||
|
||||
impl Run for Query {
|
||||
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::config;
|
||||
use crate::db::DatabaseFile;
|
||||
use crate::util::{self, Fzf};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::io::{self, Write};
|
||||
|
||||
impl Run for Remove {
|
||||
fn run(&self) -> Result<()> {
|
||||
|
@ -1,10 +1,12 @@
|
||||
use crate::db::Rank;
|
||||
use anyhow::{Context, Result};
|
||||
use glob::Pattern;
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use glob::Pattern;
|
||||
|
||||
use crate::db::Rank;
|
||||
|
||||
pub fn data_dir() -> Result<PathBuf> {
|
||||
let path = match env::var_os("_ZO_DATA_DIR") {
|
||||
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::fmt::{self, Display, Formatter};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use bincode::Options as _;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct DirList<'a>(#[serde(borrow)] pub Vec<Dir<'a>>);
|
||||
|
||||
@ -141,9 +142,10 @@ pub type Epoch = u64;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn zero_copy() {
|
||||
let dirs = DirList(vec![Dir { path: "/".into(), rank: 0.0, last_accessed: 0 }]);
|
||||
|
@ -1,14 +1,14 @@
|
||||
mod dir;
|
||||
mod stream;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{fs, io};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
pub use dir::{Dir, DirList, Epoch, Rank};
|
||||
pub use stream::Stream;
|
||||
|
||||
use crate::util;
|
||||
use anyhow::{Context, Result};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Database<'file> {
|
||||
|
@ -1,9 +1,10 @@
|
||||
use crate::db::{Database, Dir, Epoch};
|
||||
use crate::util;
|
||||
use std::iter::Rev;
|
||||
use std::ops::Range;
|
||||
use std::{fs, path};
|
||||
|
||||
use crate::db::{Database, Dir, Epoch};
|
||||
use crate::util;
|
||||
|
||||
pub struct Stream<'db, 'file> {
|
||||
db: &'db mut Database<'file>,
|
||||
idxs: Rev<Range<usize>>,
|
||||
@ -119,10 +120,12 @@ impl<'db, 'file> Stream<'db, 'file> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rstest::rstest;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
// Case normalization
|
||||
#[case(&["fOo", "bAr"], "/foo/bar", true)]
|
||||
|
@ -1,7 +1,8 @@
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::io;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
|
||||
/// Custom error type for early exit.
|
||||
#[derive(Debug)]
|
||||
pub struct SilentExit {
|
||||
|
@ -11,13 +11,15 @@ mod error;
|
||||
mod shell;
|
||||
mod util;
|
||||
|
||||
use crate::cmd::{Cmd, Run};
|
||||
use crate::error::SilentExit;
|
||||
use clap::Parser;
|
||||
use std::env;
|
||||
use std::io::{self, Write};
|
||||
use std::process::ExitCode;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::cmd::{Cmd, Run};
|
||||
use crate::error::SilentExit;
|
||||
|
||||
pub fn main() -> ExitCode {
|
||||
// Forcibly disable backtraces.
|
||||
env::remove_var("RUST_LIB_BACKTRACE");
|
||||
|
@ -35,12 +35,13 @@ make_template!(Zsh, "zsh.txt");
|
||||
#[cfg(feature = "nix-dev")]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use askama::Template;
|
||||
use assert_cmd::Command;
|
||||
use rstest::rstest;
|
||||
use rstest_reuse::{apply, template};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[template]
|
||||
#[rstest]
|
||||
fn opts(
|
||||
|
31
src/util.rs
31
src/util.rs
@ -1,17 +1,17 @@
|
||||
use crate::config;
|
||||
use crate::db::Epoch;
|
||||
use crate::error::SilentExit;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||
use std::time::SystemTime;
|
||||
use std::{env, mem};
|
||||
|
||||
#[cfg(windows)]
|
||||
use anyhow::anyhow;
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::env;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::mem;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::process::{Child, ChildStdin, Stdio};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::config;
|
||||
use crate::db::Epoch;
|
||||
use crate::error::SilentExit;
|
||||
|
||||
pub struct Fzf {
|
||||
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).
|
||||
#[cfg(unix)]
|
||||
if let Ok(metadata) = path.metadata() {
|
||||
use nix::unistd::{self, Gid, Uid};
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
use nix::unistd::{self, Gid, Uid};
|
||||
|
||||
let uid = Uid::from_raw(metadata.uid());
|
||||
let gid = Gid::from_raw(metadata.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.
|
||||
pub fn to_lowercase<S: AsRef<str>>(s: S) -> String {
|
||||
let s = s.as_ref();
|
||||
if s.is_ascii() {
|
||||
s.to_ascii_lowercase()
|
||||
} else {
|
||||
s.to_lowercase()
|
||||
}
|
||||
if s.is_ascii() { 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::ffi::OsStr;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{self, Command};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use clap::Parser;
|
||||
use ignore::Walk;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
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<()> {
|
||||
// Run cargo-fmt.
|
||||
let check_args: &[&str] = if check { &["--check", "--files-with-diff"] } else { &[] };
|
||||
Command::new("cargo").args(&["fmt", "--all", "--"]).args(check_args).run()?;
|
||||
// let check_args: &[&str] = if check { &["--check", "--files-with-diff"] } else { &[] };
|
||||
// Command::new("cargo").args(&["fmt", "--all", "--"]).args(check_args).run()?;
|
||||
|
||||
// Run nixfmt.
|
||||
if nix_enabled {
|
||||
|
Loading…
Reference in New Issue
Block a user