Помогни ни да направим Uroci.net по - богат! Добави урок

Трикове за Bash

Black Pearl   трудност:    видян: 8939




Ето и един примерен скрипт

___________________________________________________

function elite
{

local GRAY="[�33[1;30m]"
local LIGHT_GRAY="[�33[0;37m]"
local CYAN="[�33[0;36m]"
local LIGHT_CYAN="[�33[1;36m]"

case $TERM in
xterm*)
local TITLEBAR='[�33]0;u@h:w�07]'
;;
*)
local TITLEBAR=""
;;
esac

local GRAD1=$(tty|cut -d/ -f3)
PS1="$TITLEBAR
$GRAY-$CYAN-$LIGHT_CYAN(
$CYANu$GRAY@$CYANh
$LIGHT_CYAN)$CYAN-$LIGHT_CYAN(
$CYAN#$GRAY/$CYAN$GRAD1
$LIGHT_CYAN)$CYAN-$LIGHT_CYAN(
$CYAN$(date +%H%M)$GRAY/$CYAN$(date +%d-%b-%y)
$LIGHT_CYAN)$CYAN-$GRAY-
$LIGHT_GRAYn
$GRAY-$CYAN-$LIGHT_CYAN(
$CYAN$$GRAY:$CYANw
$LIGHT_CYAN)$CYAN-$GRAY-$LIGHT_GRAY "
PS2="$LIGHT_CYAN-$CYAN-$GRAY-$LIGHT_GRAY "
}
___________________________________________________
Не е много лесно да се помнят кодовете на отделните цветове затова може да си помогнете със следния скрипт:

___________________________________________________
#!/bin/bash
#
# This file echoes a bunch of colour codes to the terminal to demonstrate
# what's available. Each line is one colour on black and gray
# backgrounds, with the code in the middle. Verified to work on white,
# black, and green BGs (2 Dec 98).
#
echo " On Light Gray: On Black:"
echo -e "�33[47m�33[1;37m White �33[0m
1;37m
�33[40m�33[1;37m White �33[0m"
echo -e "�33[47m�33[37m Light Gray �33[0m
37m
�33[40m�33[37m Light Gray �33[0m"
echo -e "�33[47m�33[1;30m Gray �33[0m
1;30m
�33[40m�33[1;30m Gray �33[0m"
echo -e "�33[47m�33[30m Black �33[0m
30m
�33[40m�33[30m Black �33[0m"
echo -e "�33[47m�33[31m Red �33[0m
31m
�33[40m�33[31m Red �33[0m"
echo -e "�33[47m�33[1;31m Light Red �33[0m
1;31m
�33[40m�33[1;31m Light Red �33[0m"
echo -e "�33[47m�33[32m Green �33[0m
32m
�33[40m�33[32m Green �33[0m"
echo -e "�33[47m�33[1;32m Light Green �33[0m
1;32m
�33[40m�33[1;32m Light Green �33[0m"
echo -e "�33[47m�33[33m Brown �33[0m
33m
�33[40m�33[33m Brown �33[0m"
echo -e "�33[47m�33[1;33m Yellow �33[0m
1;33m
�33[40m�33[1;33m Yellow �33[0m"
echo -e "�33[47m�33[34m Blue �33[0m
34m
�33[40m�33[34m Blue �33[0m"
echo -e "�33[47m�33[1;34m Light Blue �33[0m
1;34m
�33[40m�33[1;34m Light Blue �33[0m"
echo -e "�33[47m�33[35m Purple �33[0m
35m
�33[40m�33[35m Purple �33[0m"
echo -e "�33[47m�33[1;35m Pink �33[0m
1;35m
�33[40m�33[1;35m Pink �33[0m"
echo -e "�33[47m�33[36m Cyan �33[0m
36m
�33[40m�33[36m Cyan �33[0m"
echo -e "�33[47m�33[1;36m Light Cyan �33[0m
1;36m
�33[40m�33[1;36m Light Cyan �33[0m"
___________________________________________________

Примери

По надолу е посочен доста интересен промпт, който си сменя цветовете в зависимост от натоварването на системата.


___________________________________________________
#!/bin/bash
# "hostloadcolour" - 17 October 98, by Giles
#
# The idea here is to change the colour of the host name in the промпт,
# depending on a threshold load value.

# THRESHOLD_LOAD is the value of the one minute load (multiplied
# by one hundred) at which you want
# the промпт to change from COLOUR_LOW to COLOUR_HIGH
THRESHOLD_LOAD=200
COLOUR_LOW='1;34'
# light blue
COLOUR_HIGH='1;31'
# light red

function промпт_command {
ONE=$(uptime | sed -e "s/.*load average: (.*...), (.*...), (.*...)/1/" -e "s/ //g")
# Apparently, "scale" in bc doesn't apply to multiplication, but does
# apply to division.
ONEHUNDRED=$(echo -e "scale=0 n $ONE/0.01 nquit n" | bc)
if [ $ONEHUNDRED -gt $THRESHOLD_LOAD ]
then
HOST_COLOUR=$COLOUR_HIGH
# Light Red
else
HOST_COLOUR=$COLOUR_LOW
# Light Blue
fi
}

function hostloadcolour {

PROMPT_COMMAND=промпт_command
PS1="[$(date +%H%M)][u@[�33[$(echo -n $HOST_COLOUR)m]h[�33[0m]:w]$ "
}


автор: Мария Кръстева
за: www.uroci.com


Страници: «1 2 3

Регистрирайте се, за да добавите коментар


Калдейта ЕООД - © 2003-2010. Всички права запазени.
Препоръчваме: Национален Бизнес | Bomba.bg | IT Новини | Диплома.бг | TRAVEL туризъм | Реферати | AmAm.bg | Иде.ли | Курсови работи | Фото Форум | Spodeli.net | Фото-Култ | Atol.bg | Elmaz.com | MobileBulgaria.com | Казанлък.Com