Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Every time I need to use sublime to open a project from terminal, I have to do this:

nohup sublime . &

Is there a way to short it?

share|improve this question
6  
Create an Alias. Check this out: askubuntu.com/questions/1414/how-to-create-a-permanent-alias –  Geppettvs D'Constanzo Oct 8 '12 at 16:44
add comment

4 Answers 4

up vote 3 down vote accepted

You can make command short by editing .bashrc file and add the following line at the end of the file.

alias new_command='long old_command'

For here you can use

alias newcommand = nohup sublime . &

share|improve this answer
add comment

You can shorten commands by creating an alias. Aliases should be put in ~/.bash_aliases (not in ~/.bashrc or ~/.profile).

Alias in .bash_aliases

You can create ~/.bash_aliases with the following command:

touch ~/.bash_aliases

You can now edit the file and put your alias in there in the format:

alias cmd='command'

For example:

alias subl='nohup sublime . &'

Be warned that if your define an alias that has the same name as a command, the alias takes precedence. This can be useful:

alias ls='ls -alF --color=auto'

Will always give you coloured, classified, complete lists when using ls.

Why not in .bashrc or .profile?

.bashrc and .profile are usually filled with all kind of nifty things by default. While this is certainly useful, it's not convenient when adding aliases yourself. Someone has apparently thought of this and added the following to the default .bashrc:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

If .bash_aliases exists, it's loaded by .bashrc and you have an entire file for all your aliases. If you install the bash-doc package there are some examples that can be found in:

 /usr/share/doc/bash-doc/examples/startup-files/Bash_aliases
share|improve this answer
add comment

Add following to your .bashrc:

 alias sblm='nohup sublime . &'

This will create an alias for the command. You can always execute then sblm, which will be evaluated as nohup sublime . & by your shell.

share|improve this answer
    
Make a note that if you are not using bash, but something, say ZSH, then you would use the ~/.zshrc file. Make sure you use the rc file for your shell, which should be explained in that shell's manpage. –  Thomas W. Oct 8 '12 at 18:49
add comment

You could make a wrapper script something like this -

mkdir -p ~/bin
echo "nohup sublime . &" > ~/bin/sbl
chmod 700 ~/bin/sbl

Now typing sbl will have the effect you want (though if you didn't already have a ~/bin folder, you may have to log out & log back in once first so your PATH is correct).

It's traditional to use aliases for this, but I have always preferred using wrappers because they are more flexible if you decide to edit them to do more complex tasks later.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.