bash设置

bash(1)

要使bash 符合个人的口味,有几个文档需要修改:


/etc/bashrc 存有整个系统的别名和功能;
/etc/profile 存有整个系统的环境参数和启动程式;
$HOME/.bashrc 存有用户的的别名和功能;
$HOME/.bash_profile 存有用户的环境参数和启动程式;
$HOME/.bash_logout 存有退出系统时的结束方式;
$HOME/.inputrc 存有主要绑定数值和其他位元数值;
下文将例举对这些文档的修改。首先,最重要的文档是:/etc/profile。如以下几节中可以看到,一向以修改这个文档的方式来设定Linux的各种功能。

--------------------------------------------------------------------------------

# /etc/profile

# System wide environment and startup programs
# --整个系统环境和启动程式
#
# Functions and aliases go in /etc/bashrc
# --/etc/bashhrc中的功能和别名
#
# This file sets the following features:
# --这个文档设定下列功能:
#
# o path --路径
# o prompts --提示符
# o a few environment variables --几个环境变数
# o colour ls --ls 的颜色
# o less behaviour --设定less的功能
# o keyboard settings --键盘设置
#
# Users can override these settings and/or add others in their
# $HOME/.bash_profile
# 用户可在$HOME/.bash_profile中取消这些设定和(或)增加其他设定

# set a decent path
# 设定可行的路径

echo $PATH | grep X11R6 > /dev/null
if [ $? = 1 ] ; then # add entries to the path
PATH="$PATH:/usr/X11R6/bin:$HOME/bin:."
fi

# notify the user: login or non-login shell. If login, the prompt is
# coloured in blue; otherwise in magenta. Root's prompt is red.
# 通知用户:登录(login)或不登录(non-login)的外围程序(shell)。
# 如果登录,则提示符为蓝色,否则为紫红色。Root的提示符为红色。

USER=`whoami`
if [ $LOGNAME = $USER ] ; then
COLOUR=44
else
COLOUR=45
fi

if [ $USER = 'root' ] ; then
COLOUR=41
fi

# put a real escape character instead of ^[
# 用真正的换码字符代替^[

PS1='^[[$COLOUR;37;1m$HOSTNAME:^[[37;40;1mw$ '
PS2="Continue> "

# no core dumps, please
# 请勿转储内存信息

ulimit -c 0

# set umask
# 设定umask

if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
umask 002
else
umask 022
fi

# a few variables
# 几项变数

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
EDITOR=jed
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 PS2 USER LOGNAME MAIL EDITOR HOSTNAME HISTSIZE HISTFILESIZE

# enable colour ls
# 设定ls的颜色

eval `dircolors /etc/DIR_COLORS -b`
export LS_OPTIONS='-F -s -T 0 --color=tty'

# customize less
# 设定less

LESS='-M-Q'
LESSEDIT="%E ?lt+%lt. %f"
LESSOPEN="| lesspipe.sh %s"
VISUAL=jed
LESSCHARSET=latin1
export LESS LESSEDIT LESSOPEN VISUAL LESSCHARSET

# customise the keyboard
# 设定键盘

/sbin/kbdrate -s -r 16 -d 500

for i in /etc/profile.d/*.sh ; do
if [ -x $i ]; then
. $i
fi
done

--------------------------------------------------------------------------------

此处为 /etc/bashrc:

 

--------------------------------------------------------------------------------

# /etc/bashrc

# System wide functions and aliases
# 整个系统的功能和别名
#
# Environment stuff goes in /etc/profile
# /etc/profile中的环境参数
#

alias which="type -path"
alias d="ls"
alias dir="d"

--------------------------------------------------------------------------------

此处为 .bashrc:

 

--------------------------------------------------------------------------------

# $HOME/.bashrc
# Source global definitions

if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# this is needed to notify the user that they are in non-login shell
# 需要以下设定,以便通知处於不登录(non-login)外围程序(shell)中的用户

COLOUR=45
# put a real escape character instead of ^[
# 用真正的换码字符代替^[


PS1='^[[$COLOUR;37m$USER:^[[37;40mw$ '

# aliases
# 别名

alias cp='cp -i'
alias l=less
alias lyx='lyx -width 900 -height 700'
alias mv='mv -i'
alias rm='rm -i'
alias x=startx

# A few useful functions
# 几个有用的功能

inst() # Install a .tar.gz archive in the current directory.
{ gzip -dc $1 | tar xvf - }

cz() # List the contents of a .zip archive.
{ unzip -l $* }

ctgz() # List the contents of a .tar.gz archive.
{
for file in $* ; do
gzip -dc ${file} | tar tf -
done
}

tgz() # Create a .tgz archive a la zip.
{
name=$1 ; tar -cvf $1 ; shift
tar -rf ${name} $*
gzip -S .tgz ${name}
}

--------------------------------------------------------------------------------

此处为.bash_profile:

 

--------------------------------------------------------------------------------

# $HOME/.bash_profile

# User specific environment and startup programs
# 用户特定的环境参数和启动程式
#
# This file contains user-defined settings that override
# those in /etc/profile
# 这个文档中存有用户自订的设置,可取代/etc/profile 中的数值
#
# Get aliases and functions
# 设定别名和功能
#
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# re-get PS1 settings
# 重新设定PS1数值

if [ $USER = 'root' ] ; then
COLOUR=41
else
COLOUR=44
fi

# put a real escape character instead of ^[
# 用真正的换码字符代替^[

PS1='^[[$COLOUR;37;1m$HOSTNAME:^[[37;40;1mw$ '

export PS1

--------------------------------------------------------------------------------

此处为 .bash_logout:

 

--------------------------------------------------------------------------------

# $HOME/.bash_logout

clear

--------------------------------------------------------------------------------

此处为 .inputrc:

 

--------------------------------------------------------------------------------

# $HOME/.inputrc

# key bindings
# 主要绑定

"e[1~": beginning-of-line
"e[3~": delete-char
"e[4~": end-of-line

# (F1 .. F5) are "e[[A" ... "e[[E"
# (F1 .. F5) 分别为 "e[[A" ... "e[[E"

"e[[A": "info C-m"

set bell-style visible # please don't beep
# --喇叭不发声
set meta-flag On # allow 8-bit input (i.e, accented letters)
# --允许8-位元输入(例如重音字符)译注:用于欧洲
# 文字或GB码及Big5码)
set convert-meta Off # don't strip 8-bit characters
# 不取消8-位元字符
set output-meta On # display 8-bit characters correctly
# 正确显示8-位元字符

set horizontal-scroll-mode On
set show-all-if-ambiguous On

--------------------------------------------------------------------------------

设定下列参数使 backspace 和 delete 两键在xterm 和其他X11应用中运作正常:


在.xinitrc中添加:
usermodmap=$HOME/.Xmodmap
xmodmap $usermodmap
在.Xmodmap中添加:
keycode 22 = BackSpace
keycode 107 = Delete
以上就设定了主控台的参数。 要修改xterm,则更改如下:
在.Xdefaults中增添:
xterm*VT100.Translations: #override BackSpace: string(0x7F)
Delete: string(0x1b) string("[3~")
Home: string(0x1b) string("[1~")
End: string(0x1b) string("[4~")
CtrlPrior: string(0x1b) string("[40~")
CtrlNext: string(0x1b) string("[41~")

nxterm*VT100.Translations: #override BackSpace: string(0x7F)
Delete: string(0x1b) string("[3~")
Home: string(0x1b) string("[1~")
End: string(0x1b) string("[4~")
CtrlPrior: string(0x1b) string("[40~")
CtrlNext: string(0x1b) string("[41~")
在bash(1) 和 readline(3) 的man说明中有更多这方面的资料。

不要以为这些设定在每种应用中都可正常运作。例如,在xterm中运行joe,有些键位就不起作用;运行rxvt也有相同的问题。有人说,这是termcap的问题。

 


300*300
  • 没有相关文章
  • 没有评论
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00340 秒