Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

281–288 of 288 posts

Re: Ask HN: Best things in your bash_profile/aliases?

#281
# z for quickly switching between commonly used dirs eg. `z ex` -> cd /mnt/c/dev/api.extensions

  # https://github.com/rupa/z
  source ~/z.sh
git helpers

  # update all git repos in subdirs
  alias gitp="ls -d */ | xargs -P10 -I{} git -C {} pull"
  # fetch updates for git repos in subdirs
  alias gitf="ls -d */ | xargs -P10 -I{} git -C {} fetch --all"
selection of most commonly used git aliases

  ci = commit -m
  cf = clean -fxd
  cl = clone
  co = checkout
  cm = commit --amend --no-edit
  lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue%Creset' --abbrev-commit --date=relative --all -n 25
  pf = push -f --follow-tags
  rb = rebase master
  st = status -sb

Re: Ask HN: Best things in your bash_profile/aliases?

#285

My favorite new one that I have been using a lot: function cheat() { curl cht.sh/$1 } It queries the cht.sh cheatsheet of various Unix commands. 'cheat tar' prints: # To extract an uncompressed archive: tar -xvf /path/to/foo.tar # To create an uncompressed archive: tar -cvf /path/to/foo.tar /path/to/foo/ # To extract a .gz archive: tar -xzvf /path/to/foo.tgz # To create a .gz archive: tar -czvf /path/to/foo.tgz /path…

This is awesome, I ALWAYS have to google for how to untar an archive (I don't do it often enough to commit to memory) thank you!

I have:

    function extract () {
      if [ -f $1 ] ; then
        case $1 in
          *.tar.bz2)   tar xjf $1     ;;
          *.tar.gz)    tar xzf $1     ;;
          *.bz2)       bunzip2 $1     ;;
          *.rar)       unrar e $1     ;;
          *.gz)        gunzip $1      ;;
          *.tar)       tar xf $1      ;;
          *.tbz2)      tar xjf $1     ;;
          *.tgz)       tar xzf $1     ;;
          *.zip)       unzip $1       ;;
          *.Z)         uncompress $1  ;;
          *.7z)        7z x $1        ;;
          *)     echo "'$1' cannot be extracted via extract()" ;;
           esac
       else
           echo "'$1' is not a valid file"
       fi
     }
instead

Re: Ask HN: Best things in your bash_profile/aliases?

#286
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!

Re: Ask HN: Best things in your bash_profile/aliases?

#287
post #80

Can I add something from .vimrc? If you put the commands: set undofile set undodir=~/.vim/undodir You get infinite undo in your files. Now when you go into a file, delete or add some text and close your terminal down, the next time you enter vim you can (re|un)do previous operations. Has saved my ass more times than I care to mention over my career!

This is awesome! Be sure to mkdir ~/.vim/undodir first as vim won't do it for you (or didn't for me)

Late on this but in case it's useful:

  if !isdirectory($HOME . "/.vim/undodir")
      call mkdir($HOME . "/.vim/undodir", "p")
  endif
  set undofile
  set undodir=~/.vim/undodir

Re: Ask HN: Best things in your bash_profile/aliases?

#288

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 ru…

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"
Post reply on HN