Hacker News new | ask | show | jobs
by jetpm 3991 days ago
I made a bash function for easier alias binding. It makes aliases immediately available and permanent. Also you don't need quotes so you can use tab completion etc. It goes like this:

ali <name of alias> <command>

to get it put this in your .bashrc

  function ali() {  
   echo "alias $1='${@:2}'" >> ~/.bashrc   #in ubuntu use   ~/.bash_aliases  
   echo "made alias:";  
   echo "alias $1='${@:2}'";  
   source ~/.bashrc;  #reload bashrc  
  }

When I realize I type a command often, I just push the up arrow to get the command again, append "ali" infront of it and turn it to an alias. Works direclty.

And of course the alias to show the list of all aliases:

  alias alis='cat ~/.bash_aliases'
1 comments

> alias alis='cat ~/.bash_aliases'

That only lists what's in .bash_aliases, along with any comments.

Why not just run alias without arguments? It lists all active aliases, however and whenever they were defined.

  $ man bash
  /^SHELL BUILTIN COMMANDS
  ...
  alias [-p] [name[=value] ...]
"Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output."