/
.bashrc
103 lines (85 loc) · 2.56 KB
/
.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Code that needs to run before the main bash setup
[[ -r "$HOME/.bashrc.pre" ]] && source "$HOME/.bashrc.pre"
# Set up the environment
export VISUAL="vim"
export EDITOR="vim"
# Remote connection-specific settings
if [ -n "$SSH_TTY" ] || [ -n "$SSH_CONNECTION"] || [ -n "$SSH_CLIENT" ]; then
# Set the GPG input to the terminal, rather than open the GUI program
export GPG_TTY=$(tty)
export TERM=xterm-256color
fi
# Prefer GB English and use UTF-8.
export LC_ALL=en_GB.UTF-8
export LANG=en_GB.UTF-8
export LANGUAGE=en_GB.UTF-8
# History settings
[[ -z "$HISTFILE" ]] && HISTFILE=$HOME/.bash_history
HISTTIMEFORMAT="%F %T "
# Save 10000 history lines in memory
HISTSIZE=10000
# SAve 200M lines on disk
HISTFILESIZE=200000000
# Append to the history, instead of overwriting
shopt -s histappend
# Ignore duplicates or space-preceding commands
HISTCONTROL=ignoreboth
# Ignore useless commands
HISTIGNORE='ls:ll:ls -alh:pwd:clear:history'
# Multiple commands on one line show up as a single line
shopt -s cmdhist
# Aliases
alias ..="cd ..;"
alias g="git"
alias mkdir="mkdir -p"
alias rsh="source $HOME/.bashrc"
# Functions
function mcd() {
mkdir -p -- "$@" && cd -- "$_";
}
function env() {
command env $@ | sort;
}
# SSH auto-completion based on entries in known_hosts.
if [[ -e $HOME/.ssh/known_hosts ]]; then
complete -o default -W "$(cat $HOME/.ssh/known_hosts | sed 's/[, ].*//' | sort | uniq | grep -v '[0-9]')" ssh scp stfp
fi
# Prompt
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function write_prompt() {
local EXIT=$?
PS1=""
# Start printing prompt on newline if cursor not in first column
shopt -s promptvars
PS1='$(printf "%$((COLUMNS-1))s\r")'$PS1
# Write the return code and timestamp out after the first command
if [[ -z "${PS1_NEWLINE_LOGIN}" ]]; then
PS1_NEWLINE_LOGIN=true
else
if [ $EXIT == 0 ]; then
PS1+="\e[32m✔\e[90m \A\e[00m\n"
else
PS1+="\e[31m✘\e[90m \A\e[00m\n"
fi
fi
# Current user, host, path
PS1+="\u@\h \[\033[36m\]\w\[\033[00m\]\n"
# Append the current git branch if in a repo, on a new line
if $(git status -s &> /dev/null)
then
if [[ $(git status --porcelain) == "" ]]
then
PS1+="\e[32m⊻ $(parse_git_branch)\e[00m\n"
else
PS1+="\e[31m⊻ $(parse_git_branch)*\e[00m\n"
fi
fi
PS1+="\$ "
}
# Set the prompt via this command (runes once before each prompt is set)
PROMPT_COMMAND=write_prompt
# Load local (per computer) bashrc settings if available
[[ -r "$HOME/.bashrc.local" ]] && source "$HOME/.bashrc.local"
# vi:ft=sh