Post

0 Configuration Files

Put them to $HOME directory.

.bash_profile

1
2
3
4
# make .bash_profile same as .bashrc
if [ -f "${HOME}/.bashrc" ]; then
    source "${HOME}/.bashrc"
fi

.bashrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# A basic .bashrc file that sets the command prompt to show the current directory,
# protects the novice bash user from some common pitfalls, and adds color to a few
# commands.
#
# This file has been tested on OS X, Windows (Git Bash), and Linux.
# It is used at Princeton University (COS 126 and COS 226) and Coursera
# (Algorithms, Part I and II; Computer Science: Programming with a Purpose).
#
# It is distributed via the IntelliJ/Java installer:
#   https://lift.cs.princeton.edu/java/mac
#   https://lift.cs.princeton.edu/java/windows
#   https://lift.cs.princeton.edu/java/linux

# Written by Kevin Wayne

MAX_PROMPT_LEN=35

getPrompt() {
    currentWorkingDir=${PWD/#$HOME/\~}
    if (( ${#currentWorkingDir} > $MAX_PROMPT_LEN )); then
        currentWorkingDir=.../${PWD##*/}   
    fi
}

PROMPT_COMMAND=getPrompt

if [ "$TERM" = "xterm-color" ] || [ "$TERM" = "xterm-256color" ]; then

    # Use color if terminal supports it.
    BLACK="\[$(tput setaf 0)\]"
    RED="\[$(tput setaf 1)\]"
    GREEN="\[$(tput setaf 2)\]"
    YELLOW="\[$(tput setaf 3)\]"
    BLUE="\[$(tput setaf 4)\]"
    MAGENTA="\[$(tput setaf 5)\]"
    CYAN="\[$(tput setaf 6)\]"
    WHITE="\[$(tput setaf 7)\]"
    DEFAULT="\[$(tput sgr0)\]"
 
    export PS1="${BLUE}\${currentWorkingDir}> ${DEFAULT}"
else
    export PS1="\${currentWorkingDir}> "
fi

# Establish a safe environment.
set -o ignoreeof         # Do not log out with <Ctrl-D>.
set -o noclobber         # Do not overwrite files via '>'.
alias rm='rm -i'         # Prompt before removing files via 'rm'.
alias cp='cp -i'         # Prompt before overwriting files via 'cp'.
alias mv='mv -i'         # Prompt before overwriting files via 'mv'.
alias ln='ln -i'         # Prompt before overwriting files via 'ln'.

# Use 'less' instead of 'more'.
# Windows Git Bash provides 'less', but not 'more'.
alias less='less --quit-at-eof --no-init --tabs=4 --RAW-CONTROL-CHARS'
alias more='less'

# Add colors to 'ls'.
alias ls='ls -GF'

# Add color to 'grep' and relatives (when not piped or redirected).
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

# When the shell exits, append to the history file instead of overwriting it.
shopt -s histappend

# Make the command-line history ignore duplicate command lines.
export HISTCONTROL=erasedups:ignoredups

# Make the command-line history show dates and times.
export HISTTIMEFORMAT="%F %T "

# Support non-ASCII characters in terminal.
# Note: use LC_ALL='C' if you want sort to behave in expected way.
export LC_ALL='en_US.UTF-8'
export LANG='en_US.UTF-8'
export LANGUAGE='en_US.UTF-8'

# Suppress OS X warning to change default shell to zsh.
export BASH_SILENCE_DEPRECATION_WARNING=1

# Set Windows codepage to 65001 (UTF-8).
if [[ "$OSTYPE" == "msys" ]]; then
    chcp.com 65001
fi

.inputrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# A basic .inputrc file that customizes tab completions and disables the alert bell.
#
# This file has been tested on OS X, Windows (Git Bash), and Linux.
# It is used at Princeton University (COS 126 and COS 226) and Coursera
# (Algorithms, Part I and II; Computer Science: Programming with a Purpose).
#
# It is distributed via the IntelliJ/Java installer:
#   https://lift.cs.princeton.edu/java/mac
#   https://lift.cs.princeton.edu/java/windows
#   https://lift.cs.princeton.edu/java/linux

# Written by Kevin Wayne


# tab completions
set show-all-if-ambiguous on
set completion-ignore-case on

# disable "display all possibilities prompt when too many items"
set completion-query-items 9999
set page-completions off

# disable alert bell
set bell-style none
This post is licensed under CC BY 4.0 by the author.