10
十一/08
0

贴我的.bashrc文件上来

鉴于好多朋友需要bashrc文件的配置,这个文件是长期设置累积的。有shell颜色的配置,自动补全,以及一些常用alias设置。

# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can’t tolerate any output.  So make sure this doesn’t display
# anything or bad things will happen !

# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it’s important to refrain from
# outputting anything in those cases.

if [[ $- != *i* ]] ; then
    # Shell is non-interactive.  Be done now!
    return
fi

# Bash won’t get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.  #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

# Enable history appending instead of overwriting.  #139609
shopt -s histappend

# Change the window title of X terminals
case ${TERM} in
    xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)
        PROMPT_COMMAND=’echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"’
        ;;
    screen)
        PROMPT_COMMAND=’echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"’
        ;;
esac

use_color=false

# Set colorful PS1 only on colorful terminals.
# dircolors –print-database uses its own built-in database
# instead of using /etc/DIR_COLORS.  Try to use the external file
# first to take advantage of user additions.  Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs}    ]] \
    && type -P dircolors >/dev/null \
    && match_lhs=$(dircolors –print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true

if ${use_color} ; then
    # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
    if type -P dircolors >/dev/null ; then
        if [[ -f ~/.dir_colors ]] ; then
            eval $(dircolors -b ~/.dir_colors)
        elif [[ -f /etc/DIR_COLORS ]] ; then
            eval $(dircolors -b /etc/DIR_COLORS)
        fi
    fi

    if [[ ${EUID} == 0 ]] ; then
        PS1=’\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] ‘
    else
        PS1=’\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] ‘
    fi

    alias ls=’ls –color=auto’
    alias grep=’grep –colour=auto’
else
    if [[ ${EUID} == 0 ]] ; then
        # show root@ when we don’t have colors
        PS1=’\u@\h \W \$ ‘
    else
        PS1=’\u@\h \w \$ ‘
    fi
fi

# Try to keep environment pollution down, EPA loves us.
unset use_color safe_term match_lhs
alias ll=’ls -l –color=tty’
# Java develop
export JAVA_HOME=/opt/java
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export OOO_FORCE_DESKTOP=gnome
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
 

关键字: ,
15
十/08
1

关于~/.bashrc的郁闷问题

机器上的archlinux安装了这么久,最近发现一个棘手的问题。~/.bashrc里面的一些设置,比如alias命令的设置“不起作用”,新开一个终端都要source一下才起作用。因为这个文件里面设置了大量的使用习惯问题,所以每次要souce很麻烦。我们都知道每个用户都可使用~/.bash_profile输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次,并且默认情况下,他设置一些环境变量,执行用户的.bashrc文件。而这个
~/.bashrc文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该文件被读取。

大体原理就是这个,那为什么我这个文件不起作用呢?这时候想到一个可笑的问题:难道我用的不是bash?echo了下SHELL环境变量,发现是sh,当时汗颜。原来我刚装好arch的时候创建这个用户没有指定shell为bash。

知道问题所在了,解决办法就是更改当前用户的shell。最好不要编辑/etc/passwd文件,而是使用chsh命令,应该是(change shell)的意思吧。

chsh -s /bin/bash terrysco

问题解决。。。。

关键字: , ,