REM Study options, no error detection. False options are just ignored.
REM Note: at the end of this file there's a sample how to detect false options.
:optiot
set index=%@eval[%index+1]^set %@ascii[%@substr[%1,%index,1]]=1
if %index lt %@eval[%@len[%1]-1] goto optiot^shift
REM All this trouble to make case matter! I must have missed something...
REM Note: Mike Bessy said it's a feature, that case doesn't matter. Ok.
REM Fix irrelevant user given options.
if "%[%@ascii[F]]"=="1" .and. "%[%@ascii[D]]"=="1" unset %@ascii[F] %@ascii[D]
set order=/o
if "%[%@ascii[e]]"=="1" set order=%order%e
if "%[%@ascii[E]]"=="1" set order=%order%-e
if "%[%@ascii[t]]"=="1" set order=%order%d
if "%[%@ascii[n]]"=="1" set order=%order%n
if "%[%@ascii[N]]"=="1" set order=%order%-n
if "%[%@ascii[T]]"=="1" set order=%order%-d
if "%[%@ascii[s]]"=="1" set order=%order%s
if "%[%@ascii[S]]"=="1" set order=%order%-s
if "%[%@ascii[r]]"=="1" set order=%order%r
if "%[%@ascii[f]]"=="1" set order=/ou
set add=/vklmb
if "%[%@ascii[C]]"=="1" set add=%add%w
if "%[%@ascii[x]]"=="1" set add=/%@substr[%add,2]
if "%[%@ascii[l]]"=="1" set add=%@substr[%add,0,%@eval[%@len[%add]-1]]t
if "%[%@ascii[1]]"=="1" set add=%@substr[%add,0,%@eval[%@len[%add]-1]]1
if "%[%@ascii[2]]"=="1" set add=%add%2
if "%[%@ascii[4]]"=="1" set add=%add%4
if "%[%@ascii[R]]"=="1" set g=global /qi
REM get current root directory for recursive listings
REM echos .\%@substr[%_cwps,%@len[%_root]]
set here=%_cwps
REM Special case for "historical reasons", sigh...
REM Unattractive output, but I'll fix it, if anybody needs it.
REM Idea to set "command" with "options" by Mike Bessy. FOR loop works now.
iff "%[%@ascii[m]]"=="1" then
alias dir `(%x %%z in (*.*) echos %%z,` `)^`
set x=for /a-d-h-s
iff "%[%@ascii[R]]"=="1" then
alias dir `(iff exist *.* then^echo rn[.\%@substr[%@upper[%_cwps],%@len[%here]]]^%x %%z in (*.*) echos %%z,` `^endiff)`
REM alias dir `(
REM iff exist *.* then
REM echo rn[.\%@substr[%@upper[%_cwps],%@len[%here]]]
REM %x %%z in (*.*) echos %%z,` `
REM endiff
REM )`
else
set g=cd .`^`
endiff
iff "%[%@ascii[a]]"=="1" then
alias global `*global /qih`
set x=for /a-d
endiff
unset/q add order atr %@ascii[a] %@ascii[D] %@ascii[F] %@ascii[R]
endiff
REM here set atr=l, if needed...
REM Note: Bug -> Feature: document it. For example...
REM You get path relatively to current dir, when you are listing directories
REM recursively above your dir level and then reach the current dir and below.
REM 1st _almost_ working version, saved here "just in case"..
REM iff "%[%@ascii[R]]"=="1" then alias dir `(if exist %mix .or. isdir %mix (set sub=%@upper[%_cwps]^if isdir %mix set sub=%sub%%@upper[%mix]\^echo [.\%@substr[%sub,%@len[%here]]]^%g *dir %&))`^endiff
REM Recursive
if "%[%@ascii[R]]"=="1" alias dir `(gosub deep^*dir %&)`