štvrtok 9. februára 2012

Post install settings 2

We will continue in "tcsh" shell customization.

3. Customize shell prompt.:
You can achieve nice and pragmatic prompt really fast but what's perfect, you can use colors in your prompt. It's a little bit hard to understand, because of color syntax but you will be rewarded with fancy prompt. First take a look at b/w prompt and colored afterwards.

In "if" section of ".tcshrc" check the "set prompt" line.
The prompt is bordered with quotes.
You can put your "own words and symbols" to your prompt with combination of system variables like hostname, username, date, time and so. The list of variables can be found in "man tcsh".
The b/w prompt which I use:

set prompt = "[%n@%m|%~]>"
- [: my own character
- %n: prints username
- @: my own character to separate username and hostname
- %m: prints hostname
- |: (pipe character) my own character do separate directory from others
- %~: prints current directory (~will show instead home dir.)
- ]: my own character
- >: my own character
My prompt then looks like: 
[root@MCBSD|/etc]>

I use above prompt, but with colors. I use red for username letters, blue for [@|] and white for the rest. To understand color syntax, practice with it. Below example is for color of letters, you can set color even for background and so.

Color codes:
30m - black
31m - red
32m - green
36m - cyan
and so...for more check google: bash prompt color codes

Syntax:[starting string][your string][ending/reset string]

[starting string]: %{\033[36m%}
-just change "36m" to color you want. 36 is for cyan
[your string]: your symbol "etc. @" or variable "%n" for username"
[ending/reset string]: %{\033[0m%}
- leave this as it is, it resets color back to default


You have to use this syntax for every symbol in prompt in order to have colored this symbol.


Small example: word TEST with half cyan and half  red


%{\033[36m%}TE%{\033[0m%}{\033[31m%}ST{\033[0m%}
- %{\033[36m%} will make  "TE" to have cyan color 
- {\033[0m%} will reset color after "TE" back to default
- {\033[31m%} will make "ST" to have red color
- {\033[0m%} will reset color after "ST" back to default 


My prompt:
set prompt = "%{\033[36m%}[%{\033[0m%}%{\033[31m%}%n%{\033[0m%}%{\033[36m%}@%{\033[0m%}%m%{\033[36m%}|%{\033[0m%}%~%{\033[36m%}]%{\033[0m%}>"


If you compare letters marked with red, it's the same as in b/w prompt. Rest contains starting and ending strings.

That's it. Your life in CLI is more comfortable now. 
You have nice overview where and "who" you are by nice prompt.
You can use TAB key for better orientation in usable commands and for overview of listed files/folders in actual position.
You have shortcuts for faster executing your frequent commands.

 
 







Žiadne komentáre:

Zverejnenie komentára