Live data from Hacker News

Level Up Your Shell Game

viget.com

11–20 of 50 posts

Re: Level Up Your Shell Game

#11
post #5

My favorite shell trick (not in the link) is this: ~- Tilde-hyphen expands to the previous directory you were in, and of course "cd -" returns you to your previous directory, so I put them together all the time. Here's an example workflow (with a fake PS1): mac:/Users/me/Projects/my_new_app$ cd ~/.pow mac:/Users/me/.pow$ ln -s ~- . mac:/Users/me/.pow$ cd - mac:/Users/me/Projects/my_new_app$ Now I can continue working…

Save the earth, fork less:

    ln -s $PWD ~/.pow
(Interesting tip about ~-, didn't know that one)

Re: Level Up Your Shell Game

#12
It's probably worth mentioning that all the delete functions he points out(all of them for that matter, ctrl-k, etc) are actually cut's, so you can paste them back as well. I find Ctrl-u especially useful when I'm halfway through with a command, then I realize I wanted to do something else before executing said command, so I cut it- then paste it back when I need it. * Ctrl + y to paste anything back

Re: Level Up Your Shell Game

#15

It's probably worth mentioning that all the delete functions he points out(all of them for that matter, ctrl-k, etc) are actually cut's, so you can paste them back as well. I find Ctrl-u especially useful when I'm halfway through with a command, then I realize I wanted to do something else before executing said command, so I cut it- then paste it back when I need it. * Ctrl + y to paste anything back

readline also seems to have a "kill ring":

    $ aaa ^U
    # now "aaa" is the only thing in the kill ring
    $ bbb ^U
    # now kill ring is ["aaa", "bbb"]
    $ ccc ^U
    # now kill ring is ["aaa", "bbb", "ccc"]
    $ ^Y
    $ ccc
    # alt+y cycles through the kill ring
    $ bbb Alt+Y
    $ aaa Alt+Y
    $ ccc Alt+Y
    $ bbb
etc. This likely feels completely natural if you're an emacs user. I don't know what the equivalent vi thing is.

Re: Level Up Your Shell Game

#16
post #9

The command line navigation commands are just what any Emacs user would expect. vi users can set their $EDITOR to 'vi' to get those commands. What do you mean you've never used Emacs? mumble whippersnappers mumble

Use `set -o vi` to get vi navigation commands on the command line. EDIT: In bash, that is. It's `bindkey -v` in zsh.

set -o vi works in zsh as well.

Re: Level Up Your Shell Game

#17
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 master HEAD)
Also, I prefer to set aliases in my ~/.functions instead of in ~/.bash_profile or ~/.bashrc. I find that this makes it easier to move the .functions file from one machine to another, especially on a lab/test machine with a shared account where I shouldn't be modifying things in the shared ~/.bashrc. To make this work, you can add this to your ~/.bashrc or ~/.bash_profile:

    if [ -f ~/.functions ]; then . ~/.functions; fi
This will source your .functions file if it exists when your .bashrc is run.

A tweak to the "editbash" suggested alias will make it so that you don't have to reopen your terminal. My equivalent alias is "vif", for "vi .functions":

    alias vif='vi ~/.functions; . ~/.functions'
Note that the second command (after the semicolon) sources the modified .functions file.

Lastly: brevity is king. I love 'alias psgrep="ps aux | grep"', since I use it several times a day, but to "level up your shell game", keep it short. My alias for this command is "psg". The other alias that I use all the time is "d" -- "alias d='ls -lFh --color --group-directories -v'".

Re: Level Up Your Shell Game

#18

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…

Why exactly do you love 'alias psgrep="ps aux | grep"' ? What does it get you that pgrep doesn't (or, if you need more information, 'ps u `pgrep `')?

Re: Level Up Your Shell Game

#20

Interestingly, relatedly, a lot of the emacs style keybindings (ctrl-a, ctrl-e, ctrl-k, etc) are system-wide in OSX. I prefer vim as my daily editor, but it is often useful. You can also make the bindings even more emacsy if you want. http://irreal.org/blog/?p=2063

There’s a link to one of the related files from your link, but folks might also find the rest of my article about this from 2006 interesting:

http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html

Also cf.:

http://www.hcs.harvard.edu/~jrus/site/system-bindings.html

http://www.hcs.harvard.edu/~jrus/site/selectors.html

https://github.com/jrus/cocoa-text-system/tree/master/KeyBin...

Post reply on HN