2

Possible Duplicate:
How to add an alias to a command in terminal?

I use the sublime text 2 text editor for developing in Ubuntu. When I want to open a file form the command line, I need to type sublime-text-2 <file-name>.

I would like to be able to tab after sub to get that, but there is sublime-text and subl or something that which also auto-complete.

Is there a way to change or create an alias for the name sublime-text-2 and call it 'sub' or just 'sublime' or even something completely different like 'texta'?

  • @FlorianDiesch Not necessarily a duplicate -- non-alias solutions (as with @LnxSlck's) are perfectly valid. – belacqua Aug 08 '12 at 23:48

3 Answers3

3

Just do this:

sudo ln -s /pathforsublimetext2install/sublime_text /usr/bin/sublime

Also, I recommend that you install sublime text 2 through a PPA, because it will integrate better with Unity/Gnome.

To install this PPA:

sudo add-apt-repository ppa:webupd8team/sublime-text-2 
sudo apt-get update
sudo apt-get install sublime-text
belacqua
  • 23,120
LnxSlck
  • 12,256
  • That is how i installed it, cheers. – Fantastic Mr Fox Aug 08 '12 at 23:50
  • Manually creating symlinks in /usr is not cool. If you must, create them in ~/bin instead. – Sergey Aug 15 '12 at 23:00
  • Care to explain why is not cool? As defined /usr/bin contains applications for the system's users. Even more /usr/bin is one of the major subdirectories of the /usr directory. It is the directory in which most standard programs are kept, along with on-line manuals and most libraries (i.e., collections of code that are commonly used by programs). – LnxSlck Aug 15 '12 at 23:48
1

By default, you can get command completion for aliases in bash on Desktop Ubuntu.

For example, here's my scanh alias (which will tab complete) from .bash_aliases:

alias scanh='egrep -v "^ \*|^\/\*|^$" '

You can create an alias for yourself in the same way. E.g.,

alias text2='/pathtofile/sublime-text-2'

You can also, if you prefer, move the blocking commands out of the way.

For instance, if a command called sublet is confounding your tab-completion, the process might look like this:

$ which sublet 
/usr/bin/sublet
$ ls -la sublet
/usr/bin/sublet
$ sudo mv /usr/bin/sublet /usr/bin/xsublet

Linking the sublime-text-2 command to something shorter works the same way. Just make sure that the link you create is in your path:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$ ln -s  sublime-text-2 /usr/local/bin/sub

Any of the above directories, /usr/bin/, /usr/sbin, etc., will work. If you have a stand-alone script or binary, you can also move it into the path directly:

$ sudo mv sublime-text-2 /usr/bin/sub
belacqua
  • 23,120
1

I would use the alias command. I put such things in my ~/.bash_alises file, which is called by my ~/.bashrc. You can also put the following in .bashrc, either way it's up to you.

I have lines like this:

alias del='gvfs-trash'                          #I habitually avoid rm
alias def='surfraw google define:'
alias st2='sublime-text-2'

After changing ~/.bash_aliases the first time, type source ~/.bash_aliases. In the future that will be done when you start your computer.

HTH.