Live data from Hacker News

The Fuck – Correct your previous console command

github.com

151–160 of 173 posts

Re: The Fuck – Correct your previous console command

#151

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 For example: $ apt-get install foo # Crap $ sudo !!

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…

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.

Re: The Fuck – Correct your previous console command

#152
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.

  $ 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.

Re: The Fuck – Correct your previous console command

#153

99 times out of 100, my issue is forgetting to sudo a command, so I just have 'alias fuck="sudo !!"' in my ~/.bash_profile

Check it out: https://github.com/seletskiy/dotfiles/blob/master/.zsh/alias... Far more easier to press CTRL-T than type `fuck` every time.

maybe easier, but much less fun...

Re: The Fuck – Correct your previous console command

#155

Earlier quoted context omitted.

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.

> Women are more likely to be/feel excluded from in-groups in technology workplaces ... because people want to treat them differently, perhaps?

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.

Re: The Fuck – Correct your previous console command

#156
post #109

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 pr…

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.

Re: The Fuck – Correct your previous console command

#157
post #116
post #51

Earlier quoted context omitted.

You must not really be a programmer ;) Late night, vision is starting to blur and you've typed `git push origin master` incorrectly dozens of times already... $ FUCK!!!111ksjdkjsd

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 :)

I do that too, I think twice before typing 'touch penis' to create dummy files in my bash scripts though.

Re: The Fuck – Correct your previous console command

#158
post #45

Earlier quoted context omitted.

If it was called the fix it never would have made it to page 1

Also if anyone really cares, they could just fork it and make the change.

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.

Re: The Fuck – Correct your previous console command

#159

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 For example: $ apt-get install foo # Crap $ sudo !!

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.

Command example:

$ git rem[TAB] ---> $ git remote

$ git remote a[TAB] ---> $ git remote add

File example:

$ git add i[TAB] --> $ git add index.js

Multiple options example (TAB twice):

$ git r[TAB,TAB]

(will give you the options:)

rebase relink replace revert reflog remote request-pull rm release repack reset

The result is NO TYPOS! ;)

--------------------------

It would also be worth remembering the unix convention of using $ for regular user prompt and # for super user prompt.

In other words:

$ # Again, that is just a convention, your OS/distro could be different.

Post reply on HN