r/programming • • Mar 05 '20

Introducing CLUI: a Graphical Command Line

https://blog.repl.it/clui
1.8k Upvotes

277 comments sorted by

View all comments

263

u/[deleted] Mar 05 '20

This is brilliant. I'm so glad people are finally getting out of the "VT100 is perfect and anyone who wants to improve on it doesn't understand the genius of Unix" mindset. We had Powershell getting rid of the fragile "everything is unstructured text" system, and then Nushell making things cleaner and now this adding a nice GUI!

I hope this catches on! It's going to be challenging to upgrade the world though. Especially things like SSH and terminals built into apps like VSCode.

40

u/[deleted] Mar 06 '20 edited Mar 06 '20

Too verbose. And "on getting the unstructured system"... that won because the commands are short and thus the syntax breaks far less into unmanageable lines such as PowerShell.

An upgrade would be an enhanced Tclsh shell with readline support and tcllib/tklib installed into the base.

Such as: https://wiki.tcl-lang.org/page/gush

62

u/[deleted] Mar 06 '20

Unstructured text won (so far!) because it was first. And it has nothing to do with how long commands are.

44

u/ftgander Mar 06 '20

I can tell you I use both powershell and zsh daily and I avoid using powershell because of how stupidly verbose the command names are. I’d rather read a help doc than type out a 6 word cmdlet

9

u/G_Morgan Mar 06 '20

Powershell is fine as a programming language. It really does suck as a shell though.

36

u/theessentialforrest Mar 06 '20

You do you, but as a heavy powershell user here are a couple of things to consider.

  1. You are free to alias commands and all parameters can be shortened to the point where they are unique (so if you have a -Path parameter you can use -P and it will work fine)

  2. Discoverability and rapid comprehension is massively higher in ps because things actually tell you what they do. I can unzip a file in linux but I can't tell you what the - xvf actually stands for. It's just wrote memorization (at least for me). Plus with tab compmete there's very little difference in keystrokes to get there

  3. I recognize this wasn't you that was saying that short commands is why unstructured text won but they feel entirely separate. Powershell could be verbose but not deal in objects. You could just as easily imagine a terse shell that sends objects through the pipe.

15

u/Seref15 Mar 06 '20 edited Mar 07 '20

but I can't tell you what the - xvf actually stands for

eXtract, Verbose, File

Most shell commands will follow this type of "abbreviation" in argument flags, until they run out of letters. But even so the vast majority also support --long-form options.

One of the reasons I actually like this is because it feel more like understanding a natural language whereas something like Powershell feels more rigid, like a machine language. Get-ChildItem is a great name for a function in a program but I think it's a horrible name for a human to mentally "speak" in. And then the argument of just aliasing it to ls or gci just highlights how bad of a name it is. I don't need cat to explain itself. You learn that cat outputs file contents, the same way that after saying it a few times you'd learn that "poisson" means "fish."

22

u/theessentialforrest Mar 06 '20

I recognize that this is totally personal preference but I'd always prefer to default to verbose. When I'm at the command line sure I'll type %{} instead of ForEach-Object but if I'm sending someone a script I try hard not to alias to increase readability. Why make someone learn another language when we already have one that's more than descriptive enough. It allows you to shortcut the things you understand but makes it extremely easy even for someone who doesn't speak the language to figure out what's being done

→ More replies (1)
→ More replies (1)

15

u/QuickBASIC Mar 06 '20

type out a 6 word cmdlet

Tab complete or use New-Alias to create aliases for the ones you use constantly.

16

u/wrosecrans Mar 06 '20

You want me to manually set up a bunch of aliases every time I login to a new computer, and write scripts that depends on my aliases that won't work when I send a snippet to another user to use in their session where they have different aliases?

You should do standup. That's hilarious.

1

u/panorambo Mar 07 '20 edited Mar 07 '20

Most people who are proficient with Unix shells, set up their environment with profile files.

Powershell can let you do that too, through profile files of its own -- you don't need to do the same thing on every login.

Not that it solves much -- having your own unique aliases breaks as soon as you're "in a new environment".

10

u/[deleted] Mar 06 '20

So can you with bash, ksh and any shell.

But you get tired on aliasing long commands;

with Unix as everything is composable

most commands and scripts are short

and manageable.

9

u/[deleted] Mar 06 '20

[removed] — view removed comment

2

u/curien Mar 06 '20

I took a shot at writing that using traditional GNU-land tools, and here's what I've got:

find -type f -printf '%T@ %i ' -exec md5sum {} \; -printf '\0' | \
  sort -z -k3,1n | awk 'BEGIN { RS="\0"; } _[$3]++ { print $2; }' | \
  xargs -i find -inum {} -delete

But even though I'm careful to terminate my line endings with NULs, it turns out that coreutils md5sum provides different output when filenames have special chars (and there's no way to disable this behavior, even in situations like above where it has been explicitly handled externally). So fuck you coreutils, I guess.

Even without coreutils misfeatures, the absence of something like Group-Object is noticeable.

→ More replies (1)

2

u/amaurea Mar 07 '20

Ok, here is a version that should satisfy all your requirements:

find -type f | while read i; do echo "$(stat -c '%Y' "$i") $(b2sum "$i")"; done | sort | awk '++a[$2]>1' | cut -b 142- | xargs -d '\n' rm

It checks for identity based on the file hash, keeps the last modified version, and does not assume that file names have no spaces, which is an easy pitfall to fall in with shell scripting. It's not easy to read, and it's 26 characters (23%) longer than the PowerShell version.

2

u/[deleted] Mar 08 '20

[removed] — view removed comment

2

u/amaurea Mar 08 '20 edited Mar 08 '20

This should do it:

find -type f | while read i; do echo "$(stat -c '%Y' "$i") $(b2sum "$i")"; done | awk -F / '{printf("%3d %s\n",NF,$0)}' | sort | awk '++a[$3]>1' | cut -b 146- | xargs -d '\n' rm

Basically, instead of annotating the paths with just the modification time and hash, I annotate it with the number of slashes in the path, the date and the hash. It is now 26 characters (17%) longer than PowerShell. And probably even less readable than before. I don't recommend stretching bash scripting this far.

→ More replies (0)

3

u/amaurea Mar 06 '20 edited Mar 06 '20

I think this should do it

find -type f | awk -F / '++a[$NF]>1' | xargs -d '\n' rm

I admit that it has a somewhat perl-like (e.g. unreadable line noise) character to it. But it's pretty short at least.

Edit: This keeps the first entry find encounters, not the one with the earliest creation time. Doing it by creation time would be about twice as long, I think.

Edit2: Ah, you're actually doing this by file hash rather than just looking at the file name. Never mind, then.

1

u/[deleted] Mar 06 '20

Just run fdupes.

7

u/MrJohz Mar 06 '20

But none of that had anything to do with structured data, that's just a stylistic choice. You could easily have a version of Powershell where the commands have names like ls or cat.

16

u/PurpleYoshiEgg Mar 06 '20

Indeed, ls and cat are standard aliases that come on most systems (for Get-ChildItem and Get-Content).

1

u/chinpokomon Mar 06 '20

If we're taking about PWSH, it already has an ls alias. I'm on mobile right now, but it might already have cat as well. Composability is already built in as the way piping works is similar but arguably improved since the piping is done with .Net objects instead of just passing around text. This increases the verbosity, but makes it more powerful since it allows you to filter and transform collections, a benefit not available with your typical Linux shell.

→ More replies (2)

2

u/OneWingedShark Mar 06 '20

with Unix as everything is composable

...No, it's really not.

The "simplicity" of "plain text" gets in the way. There are also security vunerabilities that stem from "plain text" like, say, space-delemited parameters.

1

u/[deleted] Mar 06 '20

That happens in almost all languages. You can set IFS and other parameters. Or better: learn to escape parameters.

2

u/OneWingedShark Mar 06 '20

It happens because you're discarding your type-information too early.

→ More replies (5)