Live data from Hacker News

Level Up Your Shell Game

viget.com

41–50 of 50 posts

Re: Level Up Your Shell Game

#41
I prefer to use inputrc instead of aliases. Put the following into your .inputrc

    "\C-gs": "git status -sb "
Then, for example, after pressing Ctrl-g, s "git status -sb " will appear in your prompt. Much more readable than lots of two or three letter aliases. You can see the complete list of my shortcuts on my GitHub - https://github.com/grn/dotfiles/blob/master/inputrc

Re: Level Up Your Shell Game

#42
post #36

When you execute a command that takes a long time to run and you want to send it to the background you can do: ctrl + z then, to send it to the background: bg and, to get it back from the background: fg Also, I really like to use "for", like: // get the size of each file or directory in the current directory for i in `ls -1`; do du -hs $i; done;

I don't understand your last line. How is it different to "for i in *; blah"? Or even just "du -hs ."?

Re: Level Up Your Shell Game

#43
post #2

I didn't see Ctrl-r, but I've found that to be the most insanely useful shortcut. Ctrl-r = reverse history search. Type a partial command after Ctrl-r and it'll find the most recent executed command with that substring in it. Press Ctrl-r again, jump to the next oldest command containing your substring. Did you accidentally press too many Ctrl-r? Press backspace to move forward in history.

C-s moves forward in history, but you have to type it twice to begin with, once to toggle the mode, and once to actually move forward.

Backspace normally just deletes the last character in your incremental search string.

And be sure that C-s / C-q aren't set up for terminal flow control with something like:

    stty start undef stop undef

Re: Level Up Your Shell Game

#44

IMO the aliases for git should be in ~/.gitconfig instead. I have a bunch of these, like: [alias] br = branch co = checkout ci = commit -v sci = svn dcommit --interactive cp = cherry-pick l = log --pretty=oneline --abbrev-commit l3 = log --pretty=oneline --abbrev-commit -n3 lm = log --pretty=oneline --abbrev-commit master.. rc = rebase --continue st = status -sb squash = !git rebase -i --autosquash $(git merge-base m…

Did you know you can make your own git commands, and I don't mean just aliases?

Write a script called git-mycommand, and you can invoke it with 'git mycommand'. Tab completion works too, at least for bash + bash_completion.

Re: Level Up Your Shell Game

#45
post #41

I prefer to use inputrc instead of aliases. Put the following into your .inputrc "\C-gs": "git status -sb " Then, for example, after pressing Ctrl-g, s "git status -sb " will appear in your prompt. Much more readable than lots of two or three letter aliases. You can see the complete list of my shortcuts on my GitHub - https://github.com/grn/dotfiles/blob/master/inputrc

I don't like rebinding C-g, as that's the 'cancel' key for things like incremental search (in emacs bindings).

Re: Level Up Your Shell Game

#46
post #45
post #41

I prefer to use inputrc instead of aliases. Put the following into your .inputrc "\C-gs": "git status -sb " Then, for example, after pressing Ctrl-g, s "git status -sb " will appear in your prompt. Much more readable than lots of two or three letter aliases. You can see the complete list of my shortcuts on my GitHub - https://github.com/grn/dotfiles/blob/master/inputrc

I don't like rebinding C-g, as that's the 'cancel' key for things like incremental search (in emacs bindings).

Good point! Interestingly I managed to work without it somehow. I just checked that C-g C-g works as cancel when those binding are present.

Re: Level Up Your Shell Game

#47
post #44

IMO the aliases for git should be in ~/.gitconfig instead. I have a bunch of these, like: [alias] br = branch co = checkout ci = commit -v sci = svn dcommit --interactive cp = cherry-pick l = log --pretty=oneline --abbrev-commit l3 = log --pretty=oneline --abbrev-commit -n3 lm = log --pretty=oneline --abbrev-commit master.. rc = rebase --continue st = status -sb squash = !git rebase -i --autosquash $(git merge-base m…

Did you know you can make your own git commands, and I don't mean just aliases? Write a script called git-mycommand, and you can invoke it with 'git mycommand'. Tab completion works too, at least for bash + bash_completion.

Yes, I have written some of those too. Just make sure the script is in your PATH. I drop them in ~/bin/ -- which reminds me of another thing you should have in your ~/.bash_profile, if it isn't already in the template provided by your system:

    if [ -d $HOME/bin ]
    then
        PATH=$PATH:$HOME/bin
    fi

Re: Level Up Your Shell Game

#48
post #21
post #2

I didn't see Ctrl-r, but I've found that to be the most insanely useful shortcut. Ctrl-r = reverse history search. Type a partial command after Ctrl-r and it'll find the most recent executed command with that substring in it. Press Ctrl-r again, jump to the next oldest command containing your substring. Did you accidentally press too many Ctrl-r? Press backspace to move forward in history.

A complementary tip for Ctr+R is to tag long reusable commands with a comment in the end, e.g., find . -name "*.png" -print0 | xargs -0 -P8 pngquant --ext .png --force 256 #optimizepng (if you’re using zsh, you have to enable INTERACTIVE_COMMENTS option first; just run set -k)

Thanks! I didn't know about INTERACTIVE_COMMENTS.

Adding a comment there is a neat trick. It also works with bang searches (!?), almost like creating a temporary ad-hoc alias:

    find . -name "*.png" -print0 | xargs -0 -P8 pngquant --ext .png --force 256 #optimizepng
    ... many other commands, time passes ...
    !?optimizepng

Re: Level Up Your Shell Game

#49
post #36

When you execute a command that takes a long time to run and you want to send it to the background you can do: ctrl + z then, to send it to the background: bg and, to get it back from the background: fg Also, I really like to use "for", like: // get the size of each file or directory in the current directory for i in `ls -1`; do du -hs $i; done;

I don't understand your last line. How is it different to "for i in *; blah"? Or even just "du -hs ."?

It was just an example...

instead of "ls -1" you could use any other command that returns a list

The "du -hs ." will only return the size of the current directory, but that was also an example. You could use any other command that you wanted to perform over each item in the list returned by the first command.

Not sure if this is clear enough, please let me know.

Re: Level Up Your Shell Game

#50

Here is a rule for how to level up your shell/editing game. If you ever touch your arrow keys, you are doing something wrong. > ctrl + left arrow Moves the cursor to the left by one word > ctrl + right arrow Moves the cursor to the right by one word Alt + b and Alt + f are also aliases for the same action.

uhh.... So what's wrong with doing the exact same thing with arrow keys? isn't that more natural and convenient?

Your hand has to move a few inches. It wastes time. You can optimize it out of your workflow.
Post reply on HN