Hacker News new | past | comments | ask | show | jobs | submit login

Probably too late to get some visibility, but I love this:

    function my-accept-line() {
      # check if the buffer does not contain any words
      if [ ${#${(z)BUFFER}} -eq 0 ]; then
        # put newline so that the output does not start next
        # to the prompt
        echo
        # check if inside git repository
        if git rev-parse --git-dir > /dev/null 2>&1 ; then
          # if so, execute `git status'
          git status
        else
          # else run `ls'
          ls -l
        fi
      fi
      # in any case run the `accept-line' widget
      zle .accept-line
    }
    # create a widget from `my-accept-line' with the same name
    zle -N accept-line my-accept-line
    # rebind Enter, usually this is `^M'
    bindkey '^M' accept-line
This replaces `enter` (empty command line), with either `ls` or `git status` if in a git repository.

This beautifully works as expected, I never got any bug because of this (as this could be expected for low level aliasing), and it does exactly what I'd expect: get current status of the current folder.

Now typing `git status` elsewhere is such a pain!




Late on this as well but in case it's useful to you, I use this for quick "git add":

  ga () {
          if test "$#" -eq 0
          then
                  echo "No arguments (0_0)?"
          elif test "$#" -eq 1
          then
                  git add -u && git commit -m "$(echo $1 | sed 's/^./\U&\E/')"
          else
                  git add ${@:1:$(( $# - 1 ))} && git commit -m "$(echo ${@:$#} | sed 's/^./\U&\E/')"
          fi
  }
Usage:

  # Add all modified files and capitalize the commit message
  ga "fix typo in README"
  # Add some files and treat last arg as commit message
  ga main.rs point.rs "speedup by 10e9"




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: