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?
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?
You can shorten commands by creating an alias. Aliases should be put in ~/.bash_aliases
(not in ~/.bashrc
or ~/.profile
).
.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
.
.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
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 . &
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.
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.
~/.zshrc
file. Make sure you use the rc file for your shell, which should be explained in that shell's manpage.
– Thomas Ward
Oct 08 '12 at 18:49