Zobrazujú sa príspevky s označením Shell. Zobraziť všetky príspevky
Zobrazujú sa príspevky s označením Shell. Zobraziť všetky príspevky

š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.

 
 







Post install settings 1

Regarding previous post about minimal base install, the next handy steps are to adjust environment we will working through.
1.Change shell:
The default shell in FBSD is "sh". SH is shell with basic functions but nothing more. If you work in CLI often, it's better to use sophisticated shell. 
I use "tcsh" shell for CLI and "bash" for scripting. 
TCSH exists in base install but BASH not. If you want bash, you have install this via ports. (More about installing software in further time).

Changing shell is very simple:
For current user: chsh -s [shell]
Change shell for another user: chsh -s [shell] [username]
Etc. To change my current shell: chsh -s tcsh


Now you can log out and log in back to see the difference.
Before you have made a change, the sign of the shell was "#" what means you are in "sh" shell. Now you should see "%" in prompt line what means "tcsh" shell. 

Some ways to verify the current shell:
echo $SHELL
cat /etc/passwd (see end of line for particular user)
cat /etc/master.passwd (see end of line for particular user)


More about shells you can find in handbook

2.Customize shell prompt
As you can see, "%" at the beginning of the prompt doesn't seem nice and you can't list of possible commands by pressing TAB key.  Next handy trick is using aliases. Alias is CLI shortcut for whatever command.


Change your current directory to "home" (press cd).
By "ls - la" you should see file ".cshrc". Dot means something like hidden file. 
".cshrc" is configuration file for "csh" shell which is similar to "tcsh" shell.
Copy ".cshrc" to ".tcshrc" because we use "tcsh" shell.
Now you can edit ".tcshrc" for example with "vi" editor.
(Adjustment of vi editor in further time)
So what we are going to do:


1.Aliases etc.:
alias [shortcut] [command]
alias df /bin/df -h
alias cl /usr/bin/clear
alias re rehash
alias etc cd /etc
alias shut /sbin/shutdown -p now
and so.....what you want


2.Autolist:
In "if" section of the file (it should work placed anywhere) add:
set filec
set autolist


For apply the change, log out and log in back. Now press TAB key, and you should see suggestions. It works for commands suggestions and list of files suggestions. It's very helpful.


See the continue of this article.