Skip to content

Commit

Permalink
Provide relative paths from ls func. on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Feb 20, 2024
1 parent 822c118 commit 4929892
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions l3experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ this project uses date-based 'snapshot' version identifiers.

### Fixed
- Normalize `/` in `\sys_shell_split_ls:nN` on Windows
- Return paths relative to working directory in `\sys_shell_split_ls:nN` on Windows

## [2024-01-04]

Expand Down
39 changes: 33 additions & 6 deletions l3experimental/l3sys-shell/l3sys-shell.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@
% enabled, no action is taken.
% \end{function}
%
% \begin{function}[added = 2018-07-28]{\sys_shell_split_ls:nN}
% \begin{function}[added = 2018-07-28, updated = 2024-02-20]
% {\sys_shell_split_ls:nN}
% \begin{syntax}
% \cs{sys_shell_split_ls:N} \Arg{glob} \meta{seq}
% \end{syntax}
% Sets the \meta{seq var} to contain one entry per directory listing
% (equivalent to |ls -1| or |dir /b|) as specified by the \meta{glob}: the
% entries are strings. If unrestricted shell is not enabled, no action is
% taken.
% (equivalent to |ls -1| or |dir /b /s| with relative paths) as specified by
% the \meta{glob}: the entries are strings. If unrestricted shell is not
% enabled, no action is taken.
% \end{function}
%
% \end{documentation}
Expand Down Expand Up @@ -328,9 +329,10 @@
% \end{macrocode}
% \end{macro}
%
% \begin{variable}{\l_@@_tmp_tl}
% \begin{variable}{\l_@@_tmp_seq, \l_@@_tmp_tl}
% Scratch space.
% \begin{macrocode}
\seq_new:N \l_@@_tmp_seq
\tl_new:N \l_@@_tmp_tl
% \end{macrocode}
% \end{variable}
Expand Down Expand Up @@ -366,6 +368,8 @@
% \end{macro}
%
% \begin{macro}{\sys_shell_split_ls:nN}
% \begin{macro}{\@@_shell_split_ls:nN}
% \begin{macro}{\@@_shell_split_ls:w}
% Getting a one-per-line listing is easy enough. We need to set
% \cs{ExplSyntaxOff} as that deals with the end-of-line character. After that,
% just a case of tidying up. The listing always ends in |^^M| so there is an
Expand All @@ -379,7 +383,7 @@
{
\sys_if_platform_unix:T { ls~-1~ #1 }
\sys_if_platform_windows:T
{ dir~/b~ \exp_not:N \@@_path_to_win:n {#1} }
{ dir~/b~/s~ \exp_not:N \@@_path_to_win:n {#1} }
}
{
\ExplSyntaxOff
Expand All @@ -396,10 +400,33 @@
\seq_pop_right:NN #2 \exp_not:N \l_@@_tmp_tl
\exp_not:N \tl_if_blank:eTF { \exp_not:N \seq_item:Nn #2 { 1 } }
{ \seq_clear:N #2 }
\sys_if_platform_windows:T
{
\sys_get_shell_pwd:N \exp_not:N \l_@@_tmp_tl
\exp_not:N \exp_args:NV \exp_not:N \@@_shell_split_ls:nN
\exp_not:N \l_@@_tmp_tl #2
}
}
}
\sys_if_platform_windows:T
{
\cs_new_protected:Npe \@@_shell_split_ls:nN #1#2
{
\cs_set:Npn \exp_not:N \@@_shell_split_ls:w #1 \c_backslash_str { }
\seq_set_eq:NN \exp_not:N \l_@@_tmp_seq #2
\seq_clear:N #2
\seq_map_inline:Nn \exp_not:N \l_@@_tmp_seq
{
\seq_put_right:Ne #2
{ \exp_not:N \@@_shell_split_ls:w ##1 }
}
}
\cs_new:Npn \@@_shell_split_ls:w { }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macrocode}
%</package>
Expand Down

0 comments on commit 4929892

Please sign in to comment.