Ok, so maybe I'm a little lazy. But is there a way to assign an alias to an application so that if I run a command in the terminal, I could use the alias instead of having to type the actual application's name...
example:
killall TextWrangler
would become...
killall tw
I don't think there is a way to alias textwrangler into tw for use with killall, but you can alias the full killall command this way :
alias killalltw="killall TextWrangler"
Something even shorter : alias killtw="killall TextWrangler"
You can't have any spaces in the alias' name.
For this to be persistent between Terminal sessions you will need to put this line into ~/bash_profile file.
Related
I intend to set up mac terminal shortcut per instructions but it does not work. This is what I did:
open terminal
nano .bash-profile
#add a few aliases
alias dtt = 'do this thing'
alias gc='git commit -m'
#save the bash profile
source ~/.bash_profile
Afterwards the new alias are present in the bash file. However no autocomplete is present in terminal, if I type dtt, it won't change to 'do this thing'. The shortcut doesn't seem to work.
Anything amiss? Thanks
Alias is used to do something (in your ex. 'do this thing'), typing the command you chose ('dtt'). The terminal won't autocomplete anything.
In fact alias instructs the shell to replace one string with another when executing commands.
You could use it to abbreviate commands. e.g. alias pg="ping". If you type pg google.com it will exec "ping google.com"
Currently, to get to the directory I need to type this:
cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser
Is there a way to make it so that I can just type something like:
cd FolderBelongingToUser ?
I'm familiar with z (uses ranking) and cdargs (uses shortcuts) but there are many other tools designed to make navigation in your shell easier and built-in solutions like CDPATH or the ** wildcard…
CDPATH
Adding something like this in your *rc file:
export CDPATH='.:~:/cygdrive/c/Users/NameOfUser/'
allows you to do exactly what you are after:
$ cd FolderBelongingToUser
or, better:
$ cd Fold<Tab>
**
If your bash is recent enough, you can do something like this:
$ cd **/foo
If you're using OSX you can open the hidden file named .bash_profile in your root user directory and add an entry like this:
alias define_your_shortcut='define your path'
You can do this for anything. For example here is an alias for your example:
alias FolderBelongingToUser='cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
Here's another example using a command to toggle hidden files
alias showfiles='defaults write com.apple.finder ShowAllFiles TRUE'
alias hidefiles='defaults write com.apple.finder ShowAllFiles FALSE'
After you make any changes to your bash_profile you'll need to either logout and login or you can open terminal and tell it to reload your bash_profile with this command
source ~/.bash_profile
I'm not personally familiar with Windows but if your using Windows a quick search result explained that this is how you would create a command prompt alias in Windows
AddConsoleAlias( TEXT("test"),
TEXT("cd \\<a_very_long_path>\\test"),
TEXT("cmd.exe"));
Alternatively it looks like someone provided a good answer to doing this in Windows here: https://superuser.com/questions/560519/how-to-set-an-alias-in-windows-command-line
Vim normally supports tab completion, so you can probably type something like
cd ~NamTabFolTab
which will expand to
cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser
Of course, if NameOfUser is you, then you can probably just type
cd ~/FolTab
You can add the following line to your .vimrc
cabbr FolderBelongingToUser /cygdrive/c/Users/NameOfUser/FolderBelongingToUser
Then you can can
cd FolderBelongingToUser
If you want to add more to the path (eg to specify a filename with :w) you can press / after FolderBelongingToUser and it will replace it with the full path and allow you to continue typing.
:ca[bbrev] is a Command line only abbreviation. See: :help :cabbr
If this is a permanent alias, then in your ~/.bashrc, create an alias:
alias FTBU='/cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
You will then be able to access it in your shell by:
$ cd FTBU
As another trick, if you are only going to use the alias to change to the directory then simply add cd to the alias
alias FTBU='cd /cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
You then need only type:
$ FTBU
to change to the /cygdrive/c/Users/NameOfUser/FolderBelongingToUser directory. However, if you plan to use the alias for any other purpose, leave the cd out of the alias definition.
If this is a temporary alias, you can simply create an alias from the command line with:
$ alias FTBU='/cygdrive/c/Users/NameOfUser/FolderBelongingToUser'
with the same results. (substitute anything you like for FTBU) Note: you remove an alias with the unalias command. Also Note: you should to check whether an existing system command exists with the name of your alias before assigning it. Simply type the proposed alias at the command line. If you receive something line bash: your_alias: Command Not Found, then you are good to go. There is no minimum number of characters required in an alias. So it you want to use a single-character, that's fine.
Often I find my self navigating the filesystem from a Conque shell in Vim and want to open a specific file inside my existing MacVim session. Is this possible ? - I was hoping for something like:
shell> open some/file.txt
and then have file.txt pop up inside my existing Vim window (preferably in a new tab).
Note: I am using #wycats vim dot files (not sure this matters).
Type from ConqueShell
mvim --remote-tab-silent filename
This will open the file in a new tab in MacVim
You could also write a Bash alias to shorten the command (assuming you are using bash).
Put in your ~/.profile
alias vim='mvim --remote-tab-silent'
this would enable you to type
vim filename
from ConqueShell or bash, and have it open in a new MacVim tab, rather than terminal vim. It of course does disable your ability to run standard vim (although you could still use the vi command), so maybe you would want to name the alias differently.
Just to add, this will work only if you placed the mvim executable on your path E.G. /usr/bin/mvim. It comes with the MacVim.app
Often I find my self navigating the filesystem from a Conque shell
The beauty of running a shell from inside vim is you have all of vim and the shell at your disposal.
gf is your friend. Once you get the file you want displayed on the screen in some way, you can enter normal mode, move the cursor to the file you want to edit, then use the gf command to navigate to the file. There are many ways to use this. Any program or command that outputs file names is great for this (ll, git status, etc). You could also type the filename into the shell, just to make it visible on the screen without actually running any terminal commands (tab completion is handy here).
It is possible, you can start vim as server and then add as many files as you want, but I'm not very familiar with this, so I can't give you just a direction.
I added an alias in my .bash_profile file in my home directory on Mac Leopard. For example,
alias preview = "open -a preview"
alias lsall = "ls -l"
When I try to run these commands from the command line, I get the message that command not found
Any idea what I might be doing wrong? Thanks!
You just need to lose the spaces around =, i.e.
alias preview="open -a preview"
alias lsall="ls -l"
You also need to name the file .bash_profile if you want it to be executed automatically when you start a new shell.
I created a script that starts all the apps I need for my day and assign them to the workspaces I want.
I'd like to know is there was a way to pass an argument to the terminal I open. The argument would be an alias that runs a massive source update of all the projects I'm working on.
I'd like to do something like this:
gnome-terminal start_rolls
Unfortunately, this only opens the terminal and the command is simply not run.
Any ideas ?
Thanks in advance !
Rolf
P.S.: the -e option does not work with aliases, it seems...
gnome-terminal --help-terminal-options says:
-e, --command Execute the argument to this option inside the terminal
some combination of "-e", "bash -c", "bash -i" and your alias might help
-e is going to be deprecated in future releases you should use something like this:
gnome-terminal -- bash -c "vim Main.java"
you can replace "vim Main.java" for whatever you want