# HG changeset patch # User Markus Mützel # Date 1649688052 -7200 # Node ID b78e2d064effecd0cf1e48642b5185a1fecc78e5 # Parent 18bf227e5af5038e9b559570e748bfa75d9bf109# Parent 5044c6918fdf7970d276fba964e5d6fd953a5907 maint: Merge stable to default. diff -r 18bf227e5af5 -r b78e2d064eff scripts/miscellaneous/ls.m --- a/scripts/miscellaneous/ls.m Sun Apr 10 14:34:42 2022 -0700 +++ b/scripts/miscellaneous/ls.m Mon Apr 11 16:40:52 2022 +0200 @@ -32,9 +32,9 @@ ## ## List directory contents. ## -## The @code{ls} command is implemented by calling the native operating -## system's directory listing command---available @var{options} will vary from -## system to system. +## The @code{ls} function forwards to the @code{ls} command if it is available. +## It falls back to calling the native operating system's directory listing +## command. Available @var{options} may vary from system to system. ## ## Filenames are subject to shell expansion if they contain any wildcard ## characters @samp{*}, @samp{?}, @samp{[]}. To find a literal example of a @@ -64,14 +64,29 @@ error ("ls: all arguments must be character strings"); endif + ls_cmd = ls_command (); + if (nargin > 0) args = tilde_expand (varargin); + if (ispc () && ! isunix ()) - idx = ! strncmp (args, '/', 1); - ## Enclose paths, potentially having spaces, in double quotes: - args(idx) = strcat ('"', args(idx), '"'); - ## shell (cmd.exe) on MinGW uses '^' as escape character - args = regexprep (args, '([^\w.*?])', '^$1'); + if (strncmp (ls_cmd, "ls", 2)) + ## Replace backslashes with forward slashes (unless they escape a glob + ## pattern) + args = regexprep (args, '\\(?![\*\?\[\]])', '/'); + ## Enclose paths, potentially having spaces, in double quotes: + args = strcat ('"', args, '"'); + ## Exclude glob patterns from quoted part of FILENAMES string + args = regexprep (args, '(? 0 && strncmp (ls_cmd, "ls", 2)) args = ["-1 ", args]; endif