Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Make aliases for most Linux commands

I agree in principle, but what you should really be writing are shell functions. Aliases are defined once and cast in stone - if there is a variable in an alias body, it will be evaluated once, on alias creation, and never again. Functions have no such problem. They also let you select process arguments, while aliases delegate this to invoked commands. Aliases are for very simple things, anything more complicated and you should write a function.

Also, you should set up a decent autocompletion. Zsh needs a bit of configuring and fish has it by default - the need for most aliases is eliminated by autocompletion and history functionalities of a shell. There is standard CTRL+R combo which lets you search your history and there is a "up-line-and-search" action in zsh which searches the history for lines starting with what you have on your current line. Set your HISTSIZE to some huge number and never worry about forgetting how to do something or having to repeat (as in re-type) a command.

Use fasd (https://github.com/clvv/fasd). A simple little script that records all paths, files and directories, you visit and sorts them by "frecency" (both frequency and recency). It let's you just `z pr 5` to `/usr/home/you/project/something/test5`. Give it a day and you'll never want to get back.



Yeah, that's true. My bullet point wasn't a very good one-liner.

Aliases are nice because they're the most entry-level customization yet they solve the #1 thing I spent my time doing at the very beginning: hunting down magical incantations on google. When I found one that helped me immediately, I'd collect it in my .bashrc like a pokeball. I had a lot of teeth to cut before I started looking for solutions that were solved with functions.

However, autocompletion based off history is a volatile convenience to me, not something that I feel obviates the need for aliases. Depending on ctrl-r to find `tar -xzvf` isn't much different than autocompleting your own `untar` alias. Except that when `tar -xzvf` isn't in your history anymore as a noob (fresh VPS/fresh shell/different computer), then you're back on Google/manpages to find the incantation so that it's in your history once again.

Besides, here's a simple example of the sort of abstractions I'm talking about:

    transmission-edit -> sudo vim /etc/transmission-daemon/settings.json
    transmission-start -> sudo start transmission-daemon
    transmission-stop -> sudo stop transmission-daemon
    ...
I type "trans" and then hit tab. All my Transmission-Daemon related stuff is right there ready for autocompletion. I don't have to think about files or locations or paths. I don't have to remember that transmission-daemon is set up as a service. And I especially don't have to remember that its config is a .json file named 'settings' in `/etc/transmission-daemon/`.

This is me just talking aloud.

fasd looks great. Thanks.


While aliases may be great for saving time typing, you can use them to steal from yourself the opportunity to learn how unix commands like 'tar' work. Frankly, tar should never seem like an "incantation", because most of the flags are there as shortcuts. From your example, -f and -z are shortcuts for certain pipes and redirects. 'tar -xzvf file.gz' is equivalent to 'zcat file.gz | tar -xv'; and of course the -v is unnecessary so you have 'zcat file.gz | tar x', which is a lot clearer than 'untar', which won't work for tar.bz2 files, or even plain old .tar files (but, just switch zcat to bzcat and you're golden).


I feel like everyone who has responded to me so far plugged that coax cable from The Matrix into the back of their brain stem one day and just downloaded Everything Unix. I don't really relate to a single comment.

I call it an incantation because you're on your couch eating a frozen meal at 7:30pm on a Tuesday night with your laptop in front of you. The TV is on, but it's muted so it sits in the limbo between a social coping device and a distraction for the few hours you have between the commute from work and bedtime.

Yeah, one day you want to learn more about Unix and tar and how electrons flow on a circuit board and maybe what gravity is -- like, what it really is --, but tonight you just want to get nginx set up for the first time on your linode so it can serve your hand-rolled blog and move the needle just enough so you feel like you're making some progress in life.

You've managed to use `wget` to download nginx-1.2.9.tar.gz onto your VPS. And all you want to do next is get the files out of tar.gz. You'd love to right click it and select "Uncompress" from a context menu, but it's in a terminal window.

For now you just google "ubuntu uncompress tar", click the first result, and copy the incantation into .bashrc aliased to `untar` for future reference before pressing forward into the abyss.


> if there is a variable in an alias body, it will be evaluated once, on alias creation, and never again.

Really? That's not true in bash:

    $ alias x='echo foo$A'
    $ x
    foo
    $ A=zball
    $ x
    foozball




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: