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

Great tips. !! is a nice timesaver when you've forgotten to prepend sudo to a command:

  $ /etc/init.d/rabbitmq-server restart
  Failed, need root access
  $ sudo !!
  Success
cd - is also quite cool, it takes you to the previous working directory.

  $ pwd
  /some/really/long/path/goes/here
  $ cd /var/log/app
  Work in this directory for a while, then go to previous dir
  $ cd -
  $ pwd
  /some/really/long/path/goes/here


I have the following in my zshrc for sudo. It adds sudo at the beginning of the current line or writes sudo !! if the current line is empty. I've aliased it to alt+s

    run-with-sudo() {
      if [[ -z $LBUFFER ]]; then
        LBUFFER="sudo !!";
      else
        LBUFFER="sudo $LBUFFER";
      fi
    };
    zle -N run-with-sudo;
    bindkey '\es' run-with-sudo


Nice little timesaver for such a common task, I'd just been doing the following (with vi editing on) but yours is much easier:

  esc-0-i-sudo


It may not be less keystrokes, but for what it's worth, I find using shift+i is easier than 0-i


Didn't know about that one, thanks!


Don't forget pushd and popd.


For Zsh, setopt autopushd




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

Search: