remix logo

Hacker Remix

Ask HN: What are the best things in your shell config? Functions, aliases, etc.

6 points by afefers 14 hours ago | 3 comments

What are the most useful/essential things in your shell configuration file. Be it custom function, wrappers, aliases, etc. Please provide an explanation since it isn't always obvious to others.

wruza 3 hours ago

I always alias rm, mv, cp, ln to -i.

Also, gt, gtt, gl, ga, gc, gu, gp, gd, gd2 for git status -s, status, log, add, commit, pull, push, diff, diff to rev. All with useful (to me) flags.

My prompt looks like this:

  \n
  [<status>] user@site [<cwd>]\n
  $ 
So that I see where I am, all commands line up, the last status is obvious and also there’s never this:

  $ cat nonewline.txt
  Oops no newline$ _
My .inputrc always contains https://stackoverflow.com/a/1030206

ndegruchy 13 hours ago

I have a couple of favorites (bash):

  # Only provide CDPATH when interactive...
  if [[ $- = *i* ]];
  then
      export CDPATH=:"$HOME"/Projects/
  fi
`CDPATH` is great. It's like having z, j or zoxide installed for configurable paths. While it doesn't fully replace the former, it provides a lot of the useful functionality for me.

  _cleanup_files() {    
      # Cleanup files
      local OFFENDERS=(
   "$HOME"/.java
   "$HOME"/.oracle_jre_usage
   "$HOME"/.pki
   "$HOME"/.wget-hsts
   "$HOME"/.xsession-errors
          ...
      )

      for FILE in "${OFFENDERS[@]}";
      do
   if [[ -e "$FILE" ]];
   then
       trash-put "$FILE"
   fi
      done
  }

  # Prompt
  export PROMPT_COMMAND=_cleanup_files

There are certain files that get created from various apps that I run that aren't really useful (font caches, etc). Try as I might, I can't get them into appropriate XDG-style locations. I could wrap them in boxxy, but this seems simpler. I put them in the trash in case something blew up and I need to recover it.

withinboredom 10 hours ago

I have `git fsync` which pulls and deletes all the local branches when the remote branch is deleted.

    fsync = !git pull --rebase && git fetch -p && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
This is probably my most-used alias on my machine, by far.

14 hours ago