This Space for Rent

Grotesque windows hack of the evening

ls, written in CMD:

@echo off

set args=
set opts=

    set foo=%1
    set "isflag=%foo:~0,1%"
    if "%isflag%"=="-" (
        set "opts=%opts%%foo:-=/%"
        goto getopt

if [%opts%]==[] set opts=/d

    if NOT [%1]==[] (
        set foo=%1
        set "args=%args% %foo:/=\%"
        goto concat

dir %opts% %args% | findstr /v /b /c:" "

Notice the horrible hoops I need to jump through to change options from -opt to /opt and to convert forward slashes in filenames to backwards slashes. And oh my god CMD is fragile; if I pass it any filenames with spaces in them it will explode on me (there are ways to get around it, I think, but they aren’t trivial and I just want to be able to do the simple cases of ls on the windows machine I’m using as a minecraft server.)

It’s nice that Microsoft is stubbornly clinging to backwards compatibility, but wow CMD is a weirdly assembled shell and I wish they’d do a native port of ksh.