-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
131 lines (110 loc) · 3.19 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
## Bash completion
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
## History
HISTTIMEFORMAT="%F %T " # format with time
HISTCONTROL=ignoreboth # no duplicate lines or lines starting with space
shopt -s histappend # append instead of overwriting
# Limit to 100 lines
HISTSIZE=100
HISTFILESIZE=200
## Misc
shopt -s checkwinsize # update LINES and COLUMNS on window resize if necessary
## Aliases
# Add color support for common commands
alias ls="ls --color"
alias grep="grep --color"
alias egrep="egrep --color"
alias fgrep="fgrep --color"
# Run aliases file if present
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
## Colors
########################################
# Color string.
#
# Some ANSI color escape codesAttribute codes:
# 0=none 1=bold 4=underscore 5=blink 7=reverse 8=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#
# Globals:
# Arguments:
# 1: [OPTIONAL] ANSI color escape code. Defaults to unset color modifications.
# 2: [OPTIONAL] String to be colored.
# Outputs:
# Returns:
# The color code or, if supplied, the string colored by said color code.
########################################
function _color() {
case $# in
2)
# Color $2 with $1
printf "\e[%sm%s\e[0m" "$1" "$2"
;;
1)
# Echo specified color
printf "\e[%sm" "$1"
;;
*)
# Reset to default color
printf "\e[0m"
;;
esac
}
## Prompt
# https://github.com/starship/starship
eval "$(starship init bash)"
## Custom functions
# Print network information
function netinfo() {
local output=''
output+="$(_color '0;36' 'DATE'): $(date)"
output+="\n$(_color '0;36' 'USER@HOSTNAME'): $(whoami)@$(hostname)"
local local_ip_addr=''
local router_local_ip_addr=''
case "$OSTYPE" in
"linux-gnu")
local local_ip_info
local_ip_info="$(ip route get 1.1.1.1)"
local_ip_addr="$(echo "$local_ip_info" | head -1 | cut -f7 -d' ')"
router_local_ip_addr="$(echo "$local_ip_info" | head -1 | cut -f3 -d' ')"
;;
"msys")
# Bash for Windows (MinGW)
local local_ip_info
local_ip_info="$(ipconfig)"
local_ip_addr="$(echo "$local_ip_info" | grep 'IPv4 Address' | awk '{print $NF}')"
router_local_ip_addr="$(echo "$local_ip_info" | grep -A 1 'Default Gateway' | tail -n 1 | awk '{print $1}')"
;;
*)
# Unknown OS
echo "Could not match $OSTYPE"
exit 1
;;
esac
output+="\n$(_color '0;36' 'LOCAL IP ADDR'): $local_ip_addr"
output+="\n$(_color '0;36' 'ROUTER LOCAL IP ADDR'): $router_local_ip_addr"
output+="\n$(_color '0;36' 'PUBLIC IP ADDR'): $(curl -s ipinfo.io/ip)"
echo -e "$output"
}
# System specific setups/scripts.
#
# WILL NEED TO MOVE SETUPS THERE MANUALLY AS PROGRAMS TYPICALLY WRITE HERE OR TO .bash_profile
if [ -f ~/.bash_system ]; then
. ~/.bash_system
fi