News for hackers. Stuff that matters.
Re:Show HN: Inshellisense – IDE style shell autocomplete by owlstuffing on Monday November 06, 2023 @03:04PM (#38168131)
Generally, a destructive shell command prompts for approval. But I suppose overfumbly fingers could still cause grief.

Type/command aware tooling is a night and day difference.

Re:Show HN: Inshellisense – IDE style shell autocomplete by tombert on Monday November 06, 2023 @03:10PM (#38168230)
I feel like I've trashed millions of files I shouldn't have with `rm` and trying to be clever with regular expressions.
Re:Show HN: Inshellisense – IDE style shell autocomplete by teddyh on Monday November 06, 2023 @03:36PM (#38168601)
Note: Normal shells use glob(7) expressions, not regular expressions.
Re:Show HN: Inshellisense – IDE style shell autocomplete by tombert on Monday November 06, 2023 @03:40PM (#38168666)
You know I googled this immediately after I posted it, and you're absolutely right, but a good chunk of the syntax still kind of looks like regular expressions so I don't think I was too far off!
Re:Show HN: Inshellisense – IDE style shell autocomplete by teddyh on Monday November 06, 2023 @04:08PM (#38169033)
Regular expressions and glob(7) expressions look superficially similar, but it is mostly an illusion; they both use * and ? as common metacharacters, but both of those characters mean different things in the two systems. Only the [ and ] characters are used more similarly, but even those have their differences. The two syntaxes only have one common function which functions identically in the two systems, but it is invoked by different characters; specifically the ? character in glob(7) exactly corresponds to the . (full stop) character in regular expressions.
Re:Show HN: Inshellisense – IDE style shell autocomplete by Per_Bothner on Monday November 06, 2023 @06:31PM (#38170789)
To be pedantic: You're conflating the syntax of regular exprssions, with the (computer science) concept. Glob patterns are a kind of very resticted regular pexressions. Ksh extended the glob syntax so it has the full power of regular expressions in the computer science sense - though without all the extensions of modern regular expressions.
Re:Show HN: Inshellisense – IDE style shell autocomplete by teddyh on Tuesday November 07, 2023 @05:06AM (#38175116)
No, globs are not regular expressions.

“Globs do not include syntax for the Kleene star which allows multiple repetitions of the preceding part of the expression; thus they are not considered regular expressions, which can describe the full set of regular languages over any given finite alphabet.”

— <https://en.wikipedia.org/w/index.php?title=Glob_(programming...>

Re:Show HN: Inshellisense – IDE style shell autocomplete by neuromanser on Tuesday November 07, 2023 @12:58PM (#38180358)
You're right, normal globs are not regular expressions regardless of syntax. Parent is correct too, ksh globs are regular expressions. See shopt -s extglob in bash, setopt kshglob in zsh (extendedglob for zsh's native, IMO inferior, quantifier syntax).
Re:Show HN: Inshellisense – IDE style shell autocomplete by doubled112 on Monday November 06, 2023 @03:11PM (#38168251)
I've done this enough times I use `ls` first, then `rm`
Re:Show HN: Inshellisense – IDE style shell autocomplete by tombert on Monday November 06, 2023 @03:33PM (#38168571)
Yeah, I generally will use `find . -name "<my pattern"` nowadays, just so I can see all the potentially recursive files as well, and then when I'm 100% sure that what I'm doing is good, I will pipe that into xargs or parallel.

My point was that I don't feel like Unix really stops you from doing destructive scary stuff. It seems like it's perfectly happy to let you break your machine.

Re:Show HN: Inshellisense – IDE style shell autocomplete by doubled112 on Monday November 06, 2023 @03:46PM (#38168739)
Exactly, which is why we check for ourselves instead of expecting it to hold our hand.

Unixy tools tend do what you tell them, nothing more and nothing less. No confirmations, no output if successful, no progress bars, etc.

That's a feature in my mind, but I can see how it is easy to have your day ruined if you're expecting it to ask you again.

Re:Show HN: Inshellisense – IDE style shell autocomplete by tombert on Monday November 06, 2023 @03:50PM (#38168802)
I mostly agree, but sometimes I wish that `rm` would have default to "confirm before destroying", and add a flag like `-y` to not prompt, more or less like how `apt` works on Ubuntu.
Re:Show HN: Inshellisense – IDE style shell autocomplete by doubled112 on Monday November 06, 2023 @03:58PM (#38168904)
That's actually a way better experience than no confirmation and confirming each item individually.
Re:Show HN: Inshellisense – IDE style shell autocomplete by LtWorf on Monday November 06, 2023 @04:26PM (#38169255)
rm can do that... set an alias to ask to confirm every time.
Re:Show HN: Inshellisense – IDE style shell autocomplete by tombert on Monday November 06, 2023 @04:33PM (#38169330)
That's fine on my computer, but if I'm logging into a server I'm not going to do that every time.
Re:Show HN: Inshellisense – IDE style shell autocomplete by neuromanser on Tuesday November 07, 2023 @01:41PM (#38180961)
As much as we all wish it wouldn't be so, TANSTAAFL. What is your suggestion and how does it maintain compatibility with the existing body of code?
Re:Show HN: Inshellisense – IDE style shell autocomplete by doubled112 on Monday November 06, 2023 @05:03PM (#38169693)
rm doesn’t provide an action summary, does it?

Last time I used the interactive option, it needed me to press Y once for every file.

If you have a list of 200 files you’re probably not even reading by the end.

Re:Show HN: Inshellisense – IDE style shell autocomplete by neuromanser on Tuesday November 07, 2023 @01:20PM (#38180673)
I wholeheartedly agree that rm -i is a terrible UI. However: what presentation of 200 paths would you not glaze over?

Microsoft gets lots of praise for maintaining Backwards Compatibility, even if it's Bug Compatibility, yet POSIX gets shit for the same.

Re:Show HN: Inshellisense – IDE style shell autocomplete by doubled112 on Wednesday November 08, 2023 @11:58PM (#38201341)
The presentation suggested in this very thread would work better for me. I generally pay pretty close attention to package apt/pacman/dnf output because it is all right there in front of me.

Perhaps ironically, if those programs asked me for each change I would just hold Y until it went away. Needing confirmation of each item is why I glaze over.

Re:Show HN: Inshellisense – IDE style shell autocomplete by mksybr on Monday November 06, 2023 @05:07PM (#38169749)
This seems worse then remembering, because you still have to remember that your safe-by-default command is unsafe-by-default everywhere you're not usually.
Re:Show HN: Inshellisense – IDE style shell autocomplete by Gabrys1 on Monday November 06, 2023 @05:09PM (#38169779)
alias rm="rm -i" alias mv="mv -i"

This was in the default when running in interactive shell for Mandrake Linux (way too many) years ago.

Re:Show HN: Inshellisense – IDE style shell autocomplete by mananaysiempre on Monday November 06, 2023 @04:42PM (#38169432)
Or just add ‘echo’ in front: echo rm ... . Especially when the command is in a loop of some sort.
Re:Show HN: Inshellisense – IDE style shell autocomplete by reddit_clone on Monday November 06, 2023 @04:56PM (#38169590)
As much as I can, I do a 'mv ... /tmp' instead of 'rm -rf'. It gets the files out of the way, and provides a way out if that's not what I wanted.

'/tmp' will eventually be cleaned by the OS so no (prolonged) space worries.

Re:Show HN: Inshellisense – IDE style shell autocomplete by floppydisc on Monday November 06, 2023 @06:34PM (#38170837)
To add to this, I've been a happy user of the trash-cli for forever. Can recommend.
Re:Show HN: Inshellisense – IDE style shell autocomplete by KMnO4 on Monday November 06, 2023 @08:39PM (#38172037)
/tmp is a RAM disk on many systems so be careful with very large files
Re:Show HN: Inshellisense – IDE style shell autocomplete by insanejudge on Monday November 06, 2023 @05:23PM (#38169954)
kind of the same deal with spooky SQL queries and verifying your where clause with a select first
Re:Show HN: Inshellisense – IDE style shell autocomplete by tombert on Monday November 06, 2023 @10:40PM (#38172953)
At least with SQL you can just consistently wrap stuff in transactions, so if you break something you can always revert.
Re:Show HN: Inshellisense – IDE style shell autocomplete by rixed on Monday November 06, 2023 @06:26PM (#38170729)
alias rm='rm -i'
Re:Show HN: Inshellisense – IDE style shell autocomplete by AnyTimeTraveler on Tuesday November 07, 2023 @03:32AM (#38174525)
I set up hourly borg backups instead. That resulted in me aliasing rm='rm -rf' without a worry in the world. So far, I made about ten recoveries and have never lost important data.
Re:Show HN: Inshellisense – IDE style shell autocomplete by oefrha on Tuesday November 07, 2023 @07:23AM (#38175988)
If you never rm’ed work you just did not captured by hourly backups, well, lucky you.
Re:Show HN: Inshellisense – IDE style shell autocomplete by mksybr on Monday November 06, 2023 @03:07PM (#38168183)
Generally? Do you have examples in mind? The ones I think of are destroy first and ask questions only if told to do so: mv cp rm redirection tee
Re:Show HN: Inshellisense – IDE style shell autocomplete by owlstuffing on Monday November 06, 2023 @04:21PM (#38169182)
Yeah, you’re right. I was thinking of overly destructive commands eg. reformat etc.