-
Notifications
You must be signed in to change notification settings - Fork 3
/
.bashrc
97 lines (87 loc) · 2.7 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
# .bashrc is sourced in Ubuntu
# Some of bash colors
export RED='\033[0;31m'
export YELLOW='\033[0;33m'
export BBLUE='\033[1;34m'
export NC='\033[0m'
# Command line
_parse_error_code() {
local code=$?
[[ $code -gt 0 ]] || return
echo "[$code] "
}
# \[..color..\] should be used to preserve correct shell line width
export PS1="\[$RED\]\$(_parse_error_code)\[$YELLOW\]\h\[$NC\]:\[$BBLUE\]\w\[$NC\]\$ "
# Bash history
export HISTTIMEFORMAT="%d/%m/%y %T "
export HISTSIZE=10000
export HISTFILESIZE=10000
export HISTIGNORE="ls:ll:cd:cd -"
export HISTCONTROL="ignorespace:erasedups"
shopt -s histappend
# BUG: history is not loaded by default
export HISTFILE=$HOME/.bash_history
history -r
# Bash completion
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# Colorize less output
export LESSOPEN="| $(which source-highlight) -i %s -f esc256 --style-file esc256.style"
export LESS=" -R"
# Find files in the OpenFOAM distribution and among the local source code
_find_openfoam_files() {
local res1 res2
res1="$(locate "/$1" | grep "$WM_PROJECT_DIR" | grep -v lnInclude)"
res2="$(find ~/{src,libraries,applications} -wholename "*/$1*" | grep -vE 'lnInclude|Make')"
if [[ -z "$res1$res2" ]]; then
echo -e "${RED}Missing filename"\!"${NC}" >&2
else
echo -e "$res1\n$res2"
fi
}
# Open an OpenFOAM file
s() {
local files
files="$(_find_openfoam_files "$1")"
[[ -z "$files" ]] && return 1
if [[ "$(wc -w <<< "$files")" -gt 1 ]]; then
echo -e "${RED}There are several files with the same name." >&2
echo -e "Specify the unique path using the parent directory.${NC}" >&2
echo "$files" | tr ' ' '\n' >&2
return 2
fi
local file=${files/$'\n'}
if [[ -w "$file" ]]; then
vim "$file"
else
less -R "$file"
fi
}
# List files in an OpenFOAM directory
d() {
local files
declare -A dirs
files="$(_find_openfoam_files "$1")"
for file in $files; do
if [[ -f "$file" && "$file" =~ "$1"$ ]]; then
dirs["$(dirname "$file")"]=1
elif [[ -d "$file" && "$file" =~ "$1"$ ]]; then
dirs["$file"]=1
fi
done
for dir in "${!dirs[@]}"; do
echo -e "Directory: ${BBLUE}$dir${NC}"
ls "$dir"
done
}
# Aliases
alias grep='grep --color=auto'
alias ls='ls --color=auto -G'
alias ll='ls -lFh'
alias diff='colordiff'
alias g='git'
alias m='FOAM_EXTRA_CXXFLAGS=-fdiagnostics-color=always wmake -j 2>&1 | less -R'
alias ma='FOAM_EXTRA_CXXFLAGS=-fdiagnostics-color=always wmake -a -j 2>&1 | less -R'
alias md='FOAM_EXTRA_CXXFLAGS=-fdiagnostics-color=always wmake -debug -j 2>&1 | less -R'
alias c='find . \( -name "linux*" -o -name "lnInclude" \) -exec rm -r {} \;'