Skip to content

Commit

Permalink
feat!: remove --no-quotes in favor of --quotes=always,auto,never and …
Browse files Browse the repository at this point in the history
…support EZA_QUOTING_STYLE
  • Loading branch information
PThorpe92 committed Oct 31, 2023
1 parent 9ba9c65 commit 6391c3b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 24 deletions.
7 changes: 6 additions & 1 deletion completions/fish/eza.fish
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ complete -c eza -l icons -d "When to display icons" -x -a "
automatic\t'Display icons if standard output is a terminal'
never\t'Never display icons'
"
complete -c eza -l no-quotes -d "Don't quote file names with spaces"
complete -c eza -l quotes -d "When to quote filenames" -x -a "
always\t'Always quote filenames, even filenames with no spaces/special characters'
auto\t'Quote filenames if they contain spaces or special characters'
automatic\t'Quote filenames if they contain spaces or special characters'
never\t'Never quote filenames'
"
complete -c eza -l hyperlink -d "Display entries as hyperlinks"
complete -c eza -l smart-group -d "Only show group if it has a different name from owner"

Expand Down
2 changes: 1 addition & 1 deletion completions/nush/eza.nu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export extern "eza" [
--color-scale # Highlight levels of file sizes distinctly
--colour-scale # Highlight levels of file sizes distinctly
--icons # When to display icons
--no-quotes # Don't quote file names with spaces
--quotes # When to quote filenames (always, auto, never)
--hyperlink # Display entries as hyperlinks
--group-directories-first # Sort directories before other files
--git-ignore # Ignore files mentioned in '.gitignore'
Expand Down
2 changes: 1 addition & 1 deletion completions/zsh/_eza
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ __eza() {
--colo{,u}r="[When to use terminal colours]:(when):(always auto automatic never)" \
--colo{,u}r-scale"[Highlight levels of file sizes distinctly]" \
--icons="[When to display icons]:(when):(always auto automatic never)" \
--no-quotes"[Don't quote filenames with spaces]" \
--quotes="[When to quote filenames]: (when): (always auto automatic never) \
--hyperlink"[Display entries as hyperlinks]" \
--group-directories-first"[Sort directories before other files]" \
--git-ignore"[Ignore files mentioned in '.gitignore']" \
Expand Down
16 changes: 14 additions & 2 deletions man/eza.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ The default value is ‘`automatic`’.

`automatic` or `auto` will display icons only when the standard output is connected to a real terminal. If `eza` is ran while in a `tty`, or the output of `eza` is either redirected to a file or piped into another program, icons will not be used. Setting this option to ‘`always`’ causes `eza` to always display icons, while ‘`never`’ disables the use of icons.

`--no-quotes`
: Don't quote file names with spaces.
`--quotes=WHEN`
: When to quote file names. Default is `auto` which is only when there are spaces in the name.

Valid settings are `always`, `automatic`(`auto` for short), or `never`
`always` will quote every file name, `never` will never quote any file name, and `automatic` will only quote file names when there are spaces in the name.

`--hyperlink`
: Display entries as hyperlinks
Expand Down Expand Up @@ -302,6 +305,15 @@ For more information on the format of these environment variables, see the [eza_

Overrides any `--git` or `--git-repos` argument

## `EZA_QUOTING_STYLE`

Options are 'never' | 'always' | 'auto'

'never' is equivalent to the `ls`' `-N` option or `QUOTING_STYLE=literal` option, where file names are never quoted

'auto' is the default, and equivalent to the `ls`' `-Q` option or `QUOTING_STYLE=shell-escape` option, where file names are quoted when they contain spaces.

'always' is equivalent to the `ls` `QUOTING_STYLE=shell-escape-always` option, where all file names are quoted.

EXIT STATUSES
=============
Expand Down
23 changes: 19 additions & 4 deletions src/options/file_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,29 @@ impl ShowIcons {

impl QuoteStyle {
pub fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
if matches.has(&flags::NO_QUOTES)? {
Ok(Self::NoQuotes)
if let Ok(env) = std::env::var("EZA_QUOTE_STYLE") {
match env.as_str() {
"always" => return Ok(Self::Always),
"never" => return Ok(Self::Never),
&_ => return Ok(Self::Auto),
};
} else if matches.get(&flags::QUOTES)?.is_some() {
// prioritize the command line flag over the environment variable
let word = matches.get(&flags::QUOTES)?.unwrap();
match word.to_str() {
Some("always") => return Ok(Self::Always),
Some("never") => return Ok(Self::Never),
Some("auto") => return Ok(Self::Auto),
None => return Err(OptionsError::BadArgument(&flags::QUOTES, word.into())),
_ => return Err(OptionsError::BadArgument(&flags::QUOTES, word.into())),
}
} else {
Ok(Self::QuoteSpaces)
}
return Ok(Self::Auto);
};
}
}


impl EmbedHyperlinks {
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
let flagged = matches.has(&flags::HYPERLINK)?;
Expand Down
15 changes: 7 additions & 8 deletions src/options/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ pub static TREE: Arg = Arg { short: Some(b'T'), long: "tree", take
pub static CLASSIFY: Arg = Arg { short: Some(b'F'), long: "classify", takes_value: TakesValue::Forbidden };
pub static DEREF_LINKS: Arg = Arg { short: Some(b'X'), long: "dereference", takes_value: TakesValue::Forbidden };
pub static WIDTH: Arg = Arg { short: Some(b'w'), long: "width", takes_value: TakesValue::Necessary(None) };
pub static NO_QUOTES: Arg = Arg { short: None, long: "no-quotes", takes_value: TakesValue::Forbidden };
pub static QUOTES: Arg = Arg { short: None, long: "quotes", takes_value: TakesValue::Necessary(Some(WHEN)) };

pub static COLOR: Arg = Arg { short: None, long: "color", takes_value: TakesValue::Optional(Some(WHEN)) };
pub static COLOUR: Arg = Arg { short: None, long: "colour", takes_value: TakesValue::Optional(Some(WHEN)) };
const WHEN: &[&str] = &["always", "auto", "never"];

pub static COLOR_SCALE: Arg = Arg { short: None, long: "color-scale", takes_value: TakesValue::Forbidden };
pub static COLOUR_SCALE: Arg = Arg { short: None, long: "colour-scale", takes_value: TakesValue::Forbidden };
Expand All @@ -35,9 +34,6 @@ pub static GIT_IGNORE: Arg = Arg { short: None, long: "git-ignore", t
pub static DIRS_FIRST: Arg = Arg { short: None, long: "group-directories-first", takes_value: TakesValue::Forbidden };
pub static ONLY_DIRS: Arg = Arg { short: Some(b'D'), long: "only-dirs", takes_value: TakesValue::Forbidden };
pub static ONLY_FILES: Arg = Arg { short: Some(b'f'), long: "only-files", takes_value: TakesValue::Forbidden };
const SORTS: Values = &[ "name", "Name", "size", "extension",
"Extension", "modified", "changed", "accessed",
"created", "inode", "type", "none" ];

// display options
pub static BINARY: Arg = Arg { short: Some(b'b'), long: "binary", takes_value: TakesValue::Forbidden };
Expand All @@ -59,8 +55,6 @@ pub static TIME_STYLE: Arg = Arg { short: None, long: "time-style", take
pub static HYPERLINK: Arg = Arg { short: None, long: "hyperlink", takes_value: TakesValue::Forbidden };
pub static MOUNTS: Arg = Arg { short: Some(b'M'), long: "mounts", takes_value: TakesValue::Forbidden };
pub static SMART_GROUP: Arg = Arg { short: None, long: "smart-group", takes_value: TakesValue::Forbidden };
const TIMES: Values = &["modified", "changed", "accessed", "created"];
const TIME_STYLES: Values = &["default", "long-iso", "full-iso", "iso", "relative"];

// suppressing columns
pub static NO_PERMISSIONS: Arg = Arg { short: None, long: "no-permissions", takes_value: TakesValue::Forbidden };
Expand All @@ -77,11 +71,16 @@ pub static EXTENDED: Arg = Arg { short: Some(b'@'), long: "extended",
pub static OCTAL: Arg = Arg { short: Some(b'o'), long: "octal-permissions", takes_value: TakesValue::Forbidden };
pub static SECURITY_CONTEXT: Arg = Arg { short: Some(b'Z'), long: "context", takes_value: TakesValue::Forbidden };

const TIMES: Values = &["modified", "changed", "accessed", "created"];
const TIME_STYLES: Values = &["default", "long-iso", "full-iso", "iso", "relative"];
const WHEN: Values = &["always", "auto", "never"];
const SORTS: Values = &[ "name", "Name", "size", "extension", "Extension", "modified", "changed", "accessed", "created", "inode", "type", "none" ];

pub static ALL_ARGS: Args = Args(&[
&VERSION, &HELP,

&ONE_LINE, &LONG, &GRID, &ACROSS, &RECURSE, &TREE, &CLASSIFY, &DEREF_LINKS,
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE, &WIDTH, &NO_QUOTES,
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE, &WIDTH, &QUOTES,

&ALL, &ALMOST_ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
&IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS, &ONLY_FILES,
Expand Down
2 changes: 1 addition & 1 deletion src/output/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn escape(
}
}

if quote_style != QuoteStyle::NoQuotes && needs_quotes {
if quote_style != QuoteStyle::Never && needs_quotes || quote_style == QuoteStyle::Always {
bits.insert(0, quote_bit.clone());
bits.push(quote_bit);
}
Expand Down
12 changes: 6 additions & 6 deletions src/output/file_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ pub enum EmbedHyperlinks {
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum QuoteStyle {
/// Don't ever quote file names.
NoQuotes,

/// Use single quotes for file names that contain spaces and no single quotes
/// Use double quotes for file names that contain single quotes.
QuoteSpaces,
Never,
/// Quote file names that contain spaces
Auto,
/// Always quote file names.
Always,
}

/// A **file name** holds all the information necessary to display the name
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
if !target.name.is_empty() {
let target_options = Options {
classify: Classify::JustFilenames,
quote_style: QuoteStyle::QuoteSpaces,
quote_style: QuoteStyle::Auto,
show_icons: ShowIcons::Never,
embed_hyperlinks: EmbedHyperlinks::Off,
is_a_tty: self.options.is_a_tty,
Expand Down

0 comments on commit 6391c3b

Please sign in to comment.