Cool idea. For those systems where you don't have the option of adding a 3rd party tool, it's probably worth knowing some of the standard bash shortcuts. The easy to remember ones are:
!^ - the first argument from the previous command
!$ - the last argument from the previous command
!* - all of the arguments from the previous command
!! - the entire previous command
Nice. Now that we're getting all stackoverflowy in here, it would be worth mentioning two other handy tips.
Preventing typo mistakes with bash autocomplete is even better than correcting mistakes afterwards, it also makes typing so much faster.
It works with commands AND it also works for files inside the current working directory.
Hint: start typing your command and then hit TAB, voilà!
Note: if there are more than 1 command/file option that starts with the same chars you wrote, hit TAB twice and you will have all the options displayed in front of you, it comes in handy to remember fast instead of browsing documentation.
When I was typing the '#' I was thinking 'comment', not 'root shell'; in retrospect I can see how it might have been confusing, especially when my example used 'sudo'.
I was not criticizing your use of # at all. Using # to comment is perfectly fine I guess. Now that you mentioned it, it might be a bit confusing for newbies, but don't worry I don't think anyone would try to send the command 'Crap' over a super user session, although why the hell not? haha
*Works if properly implemented. Had to manually disable this behavior in eshell as it prevented you from running regex with two carets, e.g. '$ grep -E '^sometext[^ ]+moretext'.
You can also just run a sed style substitution in most shells, e.g. '$ !!:s/before/after/' or '$ !!:gs/x/y/', which is safer IMO.
You know... I've seen this notation on discussion forums (and probably IRC etc.) for years, and had no idea until now that it was a reference to this shell capability lol
alt-. (Alt-period) is a good shortcut to keep in mind. On first press, it inputs the last arg from the previous command. If you press alt-. again, it inputs the last arg from the previous-to-previous command. And so on.
I've been using "sudo !!" (which I pronounce as sudo bangbang in my head) for a while now, mostly with vim for editing stuff in /etc. It's very nifty.
Another nifty tool is vi editing mode. You run "set -o vi", and now your shell takes vi modal editing commands. That along with Ctrl-r for reverse history search has made life in the shell so much easier. Bash has a ton of little stuff like that built in. Zsh has a few more.
Yes, that vi editing mode of bash is very useful. IIRC it was there in ksh too. Some people might not know that you can use both the insert/append mode and the command mode of vi(m) in that vi editing mode of bash, to edit previously entered commands. You just switch between the two modes the same way as you do in the real vi(m), with ESC to go from insert/append mode to command mode, and i or a to go from command mode to insert/append mode.
Also, after you have entered a previous command, to edit it, or any previous command in the history, the first thing you have to do is press ESC (to go to command mode) and then k, thereby bring the last entered command into view for editing.
When editing a command, but in command mode (not insert/append mode), you can also press v to open the command in vi(m) in a temporary file, then have the full screen editor at your disposal to edit the command (useful for long scripts including for/while loops or long pipelines), and then when you save and exit (:wq or :x followed by Enter), the newly edited command gets executed by bash.
Also, this editing technique is useful not only for correcting typos in commands, but for modifying a previous correct command, to change some words in it and then re-issue it.
who@where:~$ fuck
No fuck given
who@where:~$ fuck
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
/dev/sda6 is mounted.
WARNING!!! The filesystem is mounted. If you continue
you ***WILL*** cause ***SEVERE*** filesystem damage.
Do you really want to continue<n>? no
check aborted.
help.autocorrect
Automatically correct and execute mistyped commands after waiting for the given number of deciseconds (0.1 sec).
If more than one command can be deduced from the entered text, nothing will be executed. If the value of this option is negative, the corrected command will be executed immediately.
If the value is 0 - the command will be just shown but not executed. This is the default.
Created a pull request for a `fuck -dry` option.
Did not test nor store the command so when it is ran again it is recalled, but the base is there for it to be fully implemented.
I think a good solution to this would be to have it display the command it's going to run with a y/n prompt. It would only add one extra keystroke and make the utility a lot safer. I think I'll make a pull request or fork or something that does this this weekend if somebody hasn't already by then.
Or syntax highlighting as found in fish, red if your command will not run, blue otherwise, params in blue. Duno I wish more shells had basic syntax highlighting for input commands.
Yeah I agree...the appeal of CLI is to tersely do a variety of powerful commands...and the tradeoff is that you have to be exact in your syntax. The seconds saved in not having to retype something is a relatively irrelevant optimization, which isn't bad in itself except that it also introduces a significant amount of ambiguity, which can be deadly in CLI work.
It can actually be integrated into history expansion, used at will, configured with a custom prompt, told to ignore certain words and files that annoy you, etc. But if you try to search for "zsh correction", most posts are related to disabling it entirely.
I think it's a funny little app. I could see it being kind of useful for the author but I think I would personally have trouble using an app that I don't actually know what it's going to do 100%. I think that you could mitigate this a bit by putting the list of commands it corrects right at the top of the readme.
I think most of us have probably been at the point where we were typing something like "I hate you, you god damn computer!" into the terminal or text editor. I see this as a moderately elegant helper in those situations
'I could see it being kind of useful for the author...'
That was my impression. It reminded me of little custom scripts or functions I've created that help with my day to day work, things I wouldn't necessarily give to someone because they were built with myself in mind. I know how they work and exactly what they do.
"In one notorious incident, Warren added a DWIM feature to the command interpreter used at Xerox PARC. One day another hacker there typed delete $ to free up some disk space. (The editor there named backup files by appending $ to the original file name, so he was trying to delete any backup files left over from old editing sessions.) It happened that there weren't any editor backup files, so DWIM helpfully reported $ not found, assuming you meant 'delete *'."
See http://www.catb.org/jargon/html/D/DWIM.html and also https://en.wikipedia.org/wiki/DWIM
What I really want is a wrapper for sudo.
Whenever I use sudo, if type the password correctly it works instantly; if I mistype the password, it delays for 2 seconds before asking again. Often it's faster to Ctrl+C UP ENTER than to wait for that annoying 2 seconds. So it would be nice if a wrapper existed to see if sudo gives access within 0.1 seconds, and if it doesn't, assume the password was wrong, kill the sudo process and launch the command again. Automate the Ctrl+C UP ENTER.
I suspect the delay in sudo is configurable: it's not there because sudo is actually doing any work checking your password, it's there to prevent attackers from trying many many combinations of passwords quickly.
If you care about that protection, then you don't want to circumvent it, but in the equally reasonable case where you don't care, then you can probably just make sudo faster.
How is it offering protection? An attacker could use this scheme as well. If the server doesn't let the user through in 0.1 s, abort and retry the connection, circumventing the delay.
I've started to wonder why we've never seen a more IDE-like autocomplete in consoles. I mean, why do I have to use man pages and all sorts of reference guides to remember the parameters for find or grep or whatever, or the order of commands for whatever?
There really needs to be better communication between software and the environment it's running in.
I feel like fish gets part of the way there by grabbing stuff from the man pages and displaying descriptions in tab-complete options. But we're still a ways from the anti-Mac user interface[1]. Unless maybe you count Google's search bar.
Projects like this always make me think the developer's imagination has drastically failed them with respect to the scope of negative consequences that may result from using their tool.
Projects like this always make me think the developer's imagination is great and they must at least be intelligent enough to criticise their work (with humour).
I think i will continue using the Fish shell feature instead. It has this awesome feature of autocompleting your command with the bash history of yours.
It is safe because it will autocomplete a command that you wrote before.
Another cool thing with it is that, it will list the commands that you can run after entering a word. It does this by reading the man page of the command you write.
brew <Tab> will list the brew commands for you to use with its explanations.
I'm not sure what difference you think gender makes, unless you think women are delicate flowers that must be sheltered from bad language, but I do agree that it would be better named something more office friendly. I'd suggest 'argh', 'grr' or 'gah'.
Profanity is (deliberately) uncomfortable to people who are not part of your in-group. Women are more likely to be/feel excluded from in-groups in technology workplaces.
If I specifically don't swear around a woman colleague, while I would usually swear around all my male colleagues, isn't that exclusionary? Wouldn't treating her the same as I treat everyone else be more inclusive?
I get your point, but I think the problem is with in-group behaviour. You are comfortable with swearing if you're very comfortable with the group dynamic.
But there are plenty of out-groups in technology along plenty of lines, who may privately be uncomfortable in this situation; and gender is only one of those lines.
If we pretend there is no problem with gender that needs addressing in this respect, it's not that we are excluding women: it's that we are excluding every aspect of diversity in technology.
I've created perl scripts for fuck, shit, and goddamnit. they merely echo an array slice to the terminal, from a list of about 30 phrases. had 'em for about 15 years now.
<root@ButtPirate>$ fuck
I hope this computer dies of ass cancer.
always makes me feel a little better about life. this app might be more effective, though.
yea, lots of us use shells with suggestive text...that doesn't make this less amusing. Now if only someone would make rules for my osx terminal, thatd be great
While I agree with what I take to be your overall point, what would have been lost had you replaced your comment with the following, which does not assume anything about the poster's motivation?
The utility is actually called "The Fuck", with no asterisk. Please respect creators by not bowdlerizing the names they have chosen.
I'm not sure if this is too much of a de-rail, and I will delete it if it is inappropriate, but I am constantly surprised by and grateful for the civility of HN, where, despite strong opinions, constructive criticism is often accepted and acted upon. Thank you for being part of that!
And then update it whenever the upstream changes. And keep track of all any new references which need to be modified. And publish a package if you still want it to be installed easily. And so on.
Swear words don't break the HN guidelines. When we ask for civility we have in mind how people treat one another online. Swear words can be used to treat others badly, but they have plenty of other uses.
It's not a trivial question, though, and people aren't wrong to disagree. Cultural differences make for very different views here. In some (sub-)cultures swear words are uncivil and in others they are innocuous. There's no model that satisfies all these norms, so inevitably we have to disappoint some.
As a consequence of the above, we don't bowdlerize titles either.
I know a guy that does all his "printf debugging" using variations of printf("penis\n"). As a bonus, its a good incentive to remember to get rid of the printfs when you are done :)
There's already a "wtf" program, available in Macports and probably some other package managers. It has a database of internet acronyms, and otherwise it seems similar to commands like "apropos" and "whatis".
~> wtf is imnsho
IMNSHO: in my not so humble opinion
~> wtf is cat
SVK::Command::Cat(3pm) - Output the file from depot
cat(1) - concatenate and print files
fc-cat(1) - read font information cache files
git-cat-file(1) - Provide content or type and size information for repository objects
~> wtf is fuck
fuck: nothing appropriate
> WTF means the same thing. That is no less vulgar.
Vulgarity of expressions is not a function only of what the expression means, but of the acceptability of the expression itself in various social contexts. WTF is, generally, acceptable as not excessively vulgar in social contexts where expanding the last letter of the initialism into its referent would not be, but the reverse isn't true; WTF is pretty close, therefore, to strictly less vulgar.
This may not seem rational, but then the entire concept of vulgarity is irrational.
"The f-word" is used exclusively by people being descriptive. Nobody says "So I was f-wording my spouse..." or stubs their toe and exclaims "oh f-word!". It is used when people are reporting what other people said. That is why it is considered less offensive; it is never properly used.
It signals to the easily offended, "I want to convey this information to you, but I am deliberately mangling words so that you know I too disapprove of the terrible word that was unfortunately used by somebody else."
"WTF" isn't used that way. When people say it, they are using it, not describing somebody's usage. There is zero implication of an apology or empathy with the audience's word-phobia.
It's basically a negative, aggressive emotional response, exactly a thing I'd rather not experience while working.
A failure due to not enough privileges might be a signal to rethink what you are doing; a mindless prepending of `sudo` is dangerous. Why not `su root` then?
Also, there was that screnshot of `sudo wget` as a response to a 403 error. This is exactly why you should re-examine a failed command instead of swearing around.
I would, because a lot of commands could be improved by a "do what I mean" option.
GNU find is smart enough to tell me that I've placed one of the flags or the find string in the wrong place, but not smart enough to correct the fucking error and do what I meant in the first place. (It knows, it just won't do it.)
"apt-get/yum install" is unusable by anyone but root. Why do I need to waste time re-keying the command? This is annoying enough that I've aliased it[1] on every machine I have access to.
I'd be willing to bet the collective man hours wasted on these worthless "you did it wrong, here's how you did it wrong, now go do it right" type messages, expands well into the decades.
"Do what I mean" is great as long is what you mean is what the computer infers. As everyone who wrote Perl or used MS Word knows, this is not always the case. And when it is not, it's often super annoying.
How often do you run apt-get install? I bet it's not even a daily routine. (If it is, you should have already automated it.) OTOH if you run chmod or chown and it suddenly requires root privileges, it's a good idea to think a bit; a disaster may be around the corner.
There are different mentalities; some crave for unconstrained aerobatics while others keep reminding to wear a parachute. I wish you all the luck, but I won't wish you be my SRE.