Mac OS X
Raiting:
3

Terminal.app


imageIt is not secret that productivity of work directly dependents on the used instruments. Let us try to disable the syntax’s highlight in the favorite text editor and we immediately will notice the difference.

This article will highlight some things that will do the work in the terminal more enjoyable and productive for users of MacOS X, and may be useful for users of other operating systems.

Visor


Visor is SIMBL- plugin for Terminal.app from BinaryAge, which allows opening a terminal using the hot key and it makes of it something like a console in Quake.

Installation. First of all we need SIMBL: www.culater.net / software / SIMBL / SIMBL.php
Then we download Visor from: visor.binaryage.com and unpack the archive, and put Visor.bundle in a folder ~ / Library / Application Support / SIMBL / Plugins.

Restart the terminal

Now, our terminal is opened by a hot key Ctrl + `(or double-clicking on the icon of terminal, etc.). Tab (Cmd + T) also will work.

image

In the settings of a terminal appeared a new tab - Visor. On this tab can be set the hot key the position of the terminal window and the effect of appearance, etc.

image

Among other things, Visor gave us the opportunity to change the default colors in the terminal: in the terminal’s settings appeared a new button «More ...», but the colors do not work so far.

More colors!


As the shell is used GNU Bash by default in MacOS X, therefore all settings will be written to the file ~ /.profile.

First, we need to know what we want to use ANSI-colors in the terminal:

export TERM=xterm-color
export CLICOLOR=1

Now, the ls command will highlight the various types of files. These colors are set by variable of the environment LSCOLORS, which has a default value exfxcxdxbxegedabagacad - the collection of type pairs fb, where f is the text color, and b is background. The values for f and b parameters as follows:

a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background


The order of the pairs fb:

1. directory
2. symbolic link
3. socket
4. pipe
5. executable
6. block special
7. character special
8. executable with setuid bit set
9. executable with setgid bit set
10. directory writable to others, with sticky bit
11. directory writable to others, without sticky bit


We write:

export LSCOLORS = fxfxcxdxbxegedabagacad
More details about the parameters of ls can be found in man (man ls) and explore it .

Now, the colors work in the terminal, and its own values for these colors can set Visor in the parameters of terminal (the same button «More ...»).

Aliases


Very often the simple things have the complicated names. Bash allows creating aliases for different groups.

The syntax is very simple: alias is a command name = "command-with-parameters-and-so-on", then goes only the imagination:

alias ..= "cd .."
alias gohome = "cd ~/"
alias rmsvn = 'find. -name ". svn"-type d-exec rm-rf {} \; '

Prompt


Now let us talk about the command line prompt. Here is an example of the prompt, which displays the name of the branch and status, if the directory is under control git + highlights the status of the command to complete.

# Constants of colors
COLOR_YELLOW = "\ [\ e [33; 10m \]"
COLOR_RED = "\ [\ e [31; 10m \]"
COLOR_GREEN = "\ [\ e [32; 10m \]"
COLOR_BLUE = "\ [\ e [34; 10m \]"
COLOR_NONE = "\ [\ e [0m \]"
COLOR_NONEP = "\ [\ e [38; 0m \]"

# Status of repository
git_dirty_flag () {
git status 2> / dev / null | grep-c: | awk '{if ($ 1> 0) print ", ö °"}'
}

# Branch
parse_git_branch () {
git branch - no-color 2> / dev / null | sed-e'/^[^*]/ d '-e' s / * \ (.* \) / \ 1 / '
}

prompt_func () {

prompt="${COLOR_BLUE}\w${COLOR_GREEN}$(parse_git_branch)${COLOR_YELLOW}$(git_dirty_flag)${COLOR_NONEP}"

# If the previous command was unsuccessful
if test $? -Eq 0
then
PS1 = "$ {prompt} $ {COLOR_NONEP} $ {COLOR_NONE}" # highlight its output in red
else
PS1 = "$ {prompt} $ {COLOR_RED} $ {COLOR_NONE}"
fi
}

PROMPT_COMMAND = prompt_func

What happened:

image

Here is a related link: volnitsky.com / project / git-prompt

P. S.
It is important that after each change ~ /.profile it is necessary to restart bash.
KlauS 14 november 2011, 19:28
Vote for this post
Bring it to the Main Page
 

Comments

Leave a Reply

B
I
U
S
Help
Avaible tags
  • <b>...</b>highlighting important text on the page in bold
  • <i>..</i>highlighting important text on the page in italic
  • <u>...</u>allocated with tag <u> text shownas underlined
  • <s>...</s>allocated with tag <s> text shown as strikethrough
  • <sup>...</sup>, <sub>...</sub>text in the tag <sup> appears as a superscript, <sub> - subscript
  • <blockquote>...</blockquote>For  highlight citation, use the tag <blockquote>
  • <code lang="lang">...</code>highlighting the program code (supported by bash, cpp, cs, css, xml, html, java, javascript, lisp, lua, php, perl, python, ruby, sql, scala, text)
  • <a href="http://...">...</a>link, specify the desired Internet address in the href attribute
  • <img src="http://..." alt="text" />specify the full path of image in the src attribute