-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
170 lines (133 loc) · 4.42 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Initialization file for interactive bash shells
# Bash also reads .bashrc for non-interactive shells if they're remote shells.
# Exit if this is not an interactive shell.
if [[ $- != *i* ]]; then return; fi
# Aliases
# =======
alias ..='cd ..'
alias ...='cd ../..'
if [[ `uname` == 'Darwin' ]] ; then
alias ls='ls -G'
else
alias ls='ls --color=auto'
fi
alias l='ls'
alias la='ls -A'
alias ll='ls -lA'
alias vi='vim'
alias grep='grep --color=auto'
alias dstore-cleanup='find . -type f -name .DS_Store -delete'
alias mvnd='MAVEN_OPTS="$MAVEN_OPTS -agentlib:jdwp=transport=dt_socket,server=y,address=9186" mvn'
alias javad='java -agentlib:jdwp=transport=dt_socket,server=y,address=9186'
alias timestamp='TZ=UTC0 date +"%Y-%m-%dT%H:%M:%SZ"'
alias serve='python -m SimpleHTTPServer'
alias json='python -m json.tool'
alias xml='tidy -xml -quiet -indent'
alias urlencode='python -c "import sys, urllib as ul; print ul.quote(sys.argv[1]);"'
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote(sys.argv[1]);"'
alias hgrep='history|grep'
alias aws-login='export AWS_PROFILE=$(aws configure list-profiles | fzf --prompt "Choose active AWS profile:") && aws sso login'
# Bash configuration
# ==================
# Shell history
HISTCONTROL=ignorespace:ignoredups
HISTFILESIZE=1000
HISTSIZE=1000
HISTIGNORE='exit:logout'
HISTTIMEFORMAT='%Y-%m-%dT%H:%M:%S '
# Append to the history file, don't overwrite it
shopt -s histappend
# Don't check for new mail
unset MAILCHECK
# Check the window size after each command
shopt -s checkwinsize
# Autocompletion
# ==============
# Ignore backup files in autocompletion
export FIGNORE='~'
# Initialze Bash completion
if [[ -f "/usr/local/etc/bash_completion" ]]; then
. /usr/local/etc/bash_completion
elif [[ -f /etc/bash_completion ]]; then
. /etc/bash_completion
fi
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
[[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/etc/profile.d/bash_completion.sh"
if [[ -f "/usr/local/bin/aws_completer" ]]; then
complete -C "/usr/local/bin/aws_completer" aws
fi
# CDPATH
CDPATH=.:$HOME/Development/projects
# Shell functions
# ===============
# Create a directory and change into it
mkcd() {
[ -n "$1" ] && mkdir -p "$1" && cd "$1"
}
# Run a command with a different JAVA_HOME
jv() {
if [ "$#" -eq "0" ]; then
/usr/libexec/java_home -V
return 0
elif [ "$#" -lt "2" ]; then
echo "Usage: jv <version> <command>" >&2
return 1
fi
local -x JAVA_HOME
JAVA_HOME=$(/usr/libexec/java_home -v "$1")
if [ "$?" -ne "0" ]; then
return 1
fi
shift
"$@"
}
# Colorized man pages
# from Lemont Washington https://gist.github.com/cocoalabs/2fb7dc2199b0d4bf160364b8e557eb66
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# Interactive jq
fjq() {
echo '' | fzf --print-query --preview "cat \"$1\" | jq {q}"
}
# Shell prompt
# ============
# Colors used in the prompt
COL_RED='\[\e[0;31m\]'
COL_BLUE='\[\e[0;34m\]'
COL_OFF='\[\e[0m\]'
# If this is a remote shell, display the hostname as part of the prompt
if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
PROMPT_HOSTNAME="\u@\h:"
fi
# Show git info in the prompt if __git_ps1 is available (it should be part of
# the bash completions loaded above)
if declare -f __git_ps1 >/dev/null; then
PROMPT_GIT='$(__git_ps1)'
export GIT_PS1_SHOWSTASHSTATE=yes
export GIT_PS1_SHOWDIRTYSTATE=yes
fi
# Color the prompt red if the last command exited with a non-zero status
PROMPT_ERR_COLOR='$(if [[ "$?" != "0" ]];then echo "'${COL_RED}'";fi)'
# Update the window title to show the current directory
WINDOW_TITLE='\[\e]0;'${PROMPT_HOSTNAME}'\w\007\]'
# Set the prompt
PS1="${WINDOW_TITLE}${COL_BLUE}${PROMPT_ERR_COLOR}${PROMPT_HOSTNAME}\w${PROMPT_GIT}\$${COL_OFF} "
unset COL_RED COL_BLUE COL_OFF PROMPT_HOSTNAME PROMPT_GIT PROMPT_ERR_COLOR WINDOW_TITLE
# Misc
# ====
# https://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html
export GPG_TTY=$(tty)
# Local configuration
# ===================
if [[ -r ~/.bashrc_local ]]; then
. ~/.bashrc_local
fi