Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

Mac OS X Finder and Terminal Shortcuts

These are some of simple tricks that came across when I was working with Mac OS X - Yosemite. Most of them will work with older versions such as Mavericks and Mountain Lion.


How do you navigate to the '/usr/local' from the `Finder` program?

When you open the Finder you can only navigate into limited places(figure 1).

Figure 1: `Goto` places in Finder


But for a scenario such as navigate into '/usr/local'. How do you do that? It is simple. Just type following on the terminal;

open '/usr/local'

To get to know more about `open` command goto this link or type `man open`. Then `Q` to exit from the manual.

Open current path of the terminal in Finder?

Surprisingly YES from me. You can open your current terminal path on the terminal by typing(Note the dot);

open .

Open '/usr' on the File Open Dialog?

Yes, you can use 'GoTo' feature. Just press [⌘Command]+[⇧Shift]+[G] on the file open dialog. Then type '/usr'. Voila !!!

Get current address of a file into terminal?

Just drag and drop the file/directory you want into the terminal.

Open a file in a user-specified texteditor using terminal?

You can create an alias for saving your time! Here how to do it. 

First we need to create/edit the ~/bash_profile file. You can use any simple texteditor such as nano or vim. I am using nano. In the terminal type;

nano ~/.bash_profile

If there are any existing data, don't do any changes for those and start from a new line and type;

alias te='open -a /Applications/Sublime\ Text\ 2.app'

Notice that I am defining a alias called `te` that executes the `open -a` command. Next part is the path for your text editor. Most of the time your already installed text-editor will appeared on the /Applications folder.

In nano editor once you done with adding the text, type [⌃control]+[O] to write-out and press [Enter] to confirm. Then [⌃control]+[X] to exit.  

Then type;

source ~/.bash_profile

This will reload your settings in the ~/.bash_profile into current terminal emulator.

Now you can use `te ~/Downloads/sample.txt` to open the `sample.txt` using the texteditor you chose. In my case, It is Sublime 2.

Show/Hide Hidden Files in Finder?

To show all hidden files, paste this in the terminal;

defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app

To hide all hidden files again, paste this in the terminal;

defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app

Syntax Highlighting bash terminal and vim in Mac OS X

So far I was not a huge Apple fan. However, recently I received a MacBook Pro(Amazing Huh!). In Mac OS X; your default terminal shell is bash. But the Terminal itself put a burden on me; Unlike it is in Ubuntu or Cent OS; the folders and files names...etc are not color coded ending up frustrating. 

Here is how I made it colorful :P

STEP 1: 
Open up your terminal. You can simply press [⌘Command]+[SpaceBar] to appear 'Spotlight Search' and type 'terminal' and hit enter.

 
STEP 2:

type "cd ~" and hit enter.

This will change the current directory into your home directory.

STEP 3:

type "vim .bash_profile".

This command will open ".bash_profile" in vim editor. vim is a CLI based text editor.

STEP 4:

Hit [i] to enter into --INSERT-- mode. This will enable you to insert new characters into the document. If there '.bash_profile' is not existed before; 'vim' will create a new one for you and it will appear empty. Otherwise; make sure you are not changing other settings in the file.

After entering --INSERT-- mode; type the following;


export CLICOLOR=1

STEP 5:
Enter [Esc] to exit from --INSERT-- mode. Then type ":wq" and hit enter.

":wq" -> will write and quite from the vim
":q!" -> will exit without saving your changes(If you did something wrong!)

STEP 6:
In the terminal; enter "source .bash_profile".

This will apply configurations into the current bash shell. Or you can skip this step and re-open the terminals.

STEP 7:
Now type "ls -l" you will experience it ! Enjoy !!!



BONUS:
If you need to highlight syntaxes in the vim editor as well; follow the same steps to edit the file. Simplest way is to create a file in '~/.vimrc'. 

So your command would be "vim ~/.vimrc" and enter the following;

filetype plugin indent on
syntax on