I've made this little function for quickly writing a new-alias to .bashrc
##------------------------------------ ##
 #           -- new-alias --           #
 # creates new alias & writes to file  #
 #          $1 = alias new             #
 #          $2 = alias definition      #
##------------------------------------ ##
new-alias () { 
  if [ -z "$1" ]; then
    echo "alias name:"
    read NAME
  else
    NAME=$1
  fi

  if [ -z "$2" ]; then
    echo "alias definition:"
    read DEFINTION
  else
    if [ "$2" = "-cd" ]; then
      DEFINTION='cd '
    else
      DEFINTION=$2
    fi
  fi

  echo "alias $NAME='$DEFINTION'" >> ~/.bashrc
  . ~/.bashrc
}
share|improve this answer
  • Good idea, but careless using of this function may lead to trashing .bashrc with multiple instances of alias command. Your function definitely needs to implement some checkups to avoid such cluttering. – Troublemaker-DV Mar 31 '16 at 1:04