elves / elvish

Powerful scripting language & versatile interactive shell

Home Page:https://elv.sh/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

special-case two paths, /dev/tty and /dev/null, on Windows

krader1961 opened this issue · comments

There was a recent IM discussion pointing out the challenge of writing an Elvish program that needs to use the UNIX paths /dev/tty and /dev/null on Windows. On Windows the equivalent are con and nul (or //./con and //./nul if using UNC names). It's a PITA to deal with this in a portable manner so it was suggested that it would be helpful if Elvish implicitly converted the UNIX device names to their Windows equivalent. Alternatively, have builtin vars that expand to the appropriate string for each platform; e.g., DevNul and DevTty. As a long time UNIX programmer I don't like that option but include it for discussion since it is explicit and avoids introducing behavior that might surprise a Windows programmer.

Wouldn't $path:dev-tty and $path:dev-null (and maybe $path:con and $path:nul) be appropriate places for this? Putting these variables in the global scope seems wrong, and PascalCase isn't used anywhere in Elvish.

Wouldn't $path:dev-tty and $path:dev-null (and maybe $path:con and $path:nul) be appropriate places for this?

Agreed, assuming we want to go the variable route. And having slept on the matter I'm now leaning towards variables rather than magically special-casing the /dev pathnames since doing so is likely to be hard to document in a discoverable fashion. Not to mention it feels wrong to privilege the UNIX device names and not the Windows equivalents.

Yes, variables are the way to go.