Useful tips for profile

1 minute read

If you are familiar with unix or linux, you know how important profile settings are. If I were to build a new server environment, I would check the profile first. The following settings are the ones I set up mainly in ksh or bash environments.

.bash_profile

stty erase "^H" kill "^U" intr "^C" eof "^D"
stty hupcl ixon ixoff
stty cs8 -istrip

##########################################################
# export
##########################################################
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/vac/bin:/usr/ccs/bin/
export PATH=$PATH:.

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

set -o vi
export EDITOR=vi

# prompt
export PS1='^[[1;32m[`hostname`:`whoami`][`pwd`] # ^[[0m'

##########################################################
# enable color support of ls and also add handy aliases
##########################################################
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

##########################################################
# alias
##########################################################
alias ll='ls -alF'
alias la='ls -A'

Prompt

##########################################################
# Case #1 : Recommended
##########################################################
### PS1 Configuration ###
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
LIME_YELLOW=$(tput setaf 190)
YELLOW=$(tput setaf 3)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)

if [ "${HN:0:2}" = "ts" ]; then
    export PS1='\[${CYAN}\][\t][TEST${HN:7}-\u\[${CYAN}\]@\h:$PWD]\[${NORMAL}\]'
elif [ "${HN:0:2}" = "pr" ]; then
    export PS1='\[${RED}\][\t][PROD${HN:7}-\u\[${RED}\]@\h:$PWD]\[${NORMAL}\]'
elif [ "${HN:0:2}" = "dr" ]; then
    export PS1='\[${GREEN}\][\t][DR${HN:7}-\u\[${GREEN}\]@\h:$PWD]\[${NORMAL}\]'
elif [ "${HN:0:2}" = "dv" ]; then
    export PS1='\[${WHITE}\][\t][UAT${HN:7}-\u\[${WHITE}\]@\h:$PWD]\[${NORMAL}\]'
fi

##########################################################
# Case #2 : NOT recommended (editing can be broken)
##########################################################
if [ "${HN:0:2}" = "ts" ]; then 
    export PS1='\e[0;36m[UAT${HN:7}_\u@\h:$PWD]\e[m'
elif [ "${HN:0:2}" = "pr" ]; then 
    export PS1='\033[0;31m[PRD${HN:7}_\u@\h:$PWD]\033[m'
elif [ "${HN:0:2}" = "dr" ]; then 
    export PS1='\033[1;31m[DR${HN:7}_\u@\h:$PWD]\033[m'
elif [ "${HN:0:2}" = "dv" ]; then
    export PS1='[개발${HN:7}_\u@\h:$PWD]'
fi

Tags:

Categories:

Updated:

Leave a comment