-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
130 lines (105 loc) · 2.91 KB
/
bashrc
File metadata and controls
130 lines (105 loc) · 2.91 KB
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
# Aliases
alias ls='ls -F'
alias ll='ls -lF'
alias la='ls -alF'
alias py='python'
# Create a base64 encoded data URL from a file
dataurl() {
local MIMETYPE=$(file --mime-type "$1" | cut -d ' ' -f2)
if [[ $MIMETYPE == "text/*" ]]; then
MIMETYPE="${MIMETYPE};charset=utf-8"
fi
echo "data:${MIMETYPE};base64,$(openssl base64 -in "$1" | tr -d '\n')"
}
unshorten() {
curl -sIL $1 | sed -n 's/Location: *//p'
}
# https://meyerweb.com/eric/thoughts/2020/09/29/polite-bash-commands/
please() {
if [ "$1" ]; then
sudo $@
else
sudo "$BASH" -c "$(history -p !!)"
fi
}
# Functions
function cd
{
if [ $# -eq 0 ]; then
pushd ~ > /dev/null
elif [ " $1" = " -" ]; then
pushd "$OLDPWD" > /dev/null
else
pushd "$@" > /dev/null
fi
}
function mcd() {
mkdir -p $1
cd $1
}
function g() {
./gradlew "$@"
}
# The worktime and slacktime functions originate here
# http://samuelmullen.com/2013/10/the-two-most-productivity-enhancing-scripts-ever-written-in-the-history-of-unix/
# --
function worktime() {
echo "# WORKTIME" | sudo tee -a /etc/hosts > /dev/null
while read -r line; do
echo "127.0.0.1 ${line}"
done < $HOME/.blocked_sites | sudo tee -a /etc/hosts > /dev/null
}
function slacktime() {
local flag=0
while read -r line; do
[[ $line =~ "# WORKTIME" ]] && flag=1
[[ $flag -eq 1 ]] && continue
echo $line
done < /etc/hosts > /tmp/hosts
sudo cp /tmp/hosts /etc/hosts
}
function _git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1] /'
}
function _virtualenv_info(){
local venv=''
if [[ -n "$VIRTUAL_ENV" ]]; then
# Strip out the path and just leave the env name
venv="${VIRTUAL_ENV##*/}"
venv="${venv%-*}"
fi
[[ -n "$venv" ]] && echo "(venv: $venv) "
}
function _aws_profile(){
local aws_prof=''
if [[ -n "$AWS_PROFILE" ]]; then
aws_prof="${AWS_PROFILE}"
fi
[[ -n "$aws_prof" ]] && echo "<aws: $aws_prof> "
}
function _prompt_command() {
local BRANCH=`_git_branch`
local LOAD=`uptime|awk '{min=NF-2;print $min}'`
local VENV=`_virtualenv_info`
local TIME='\t'
local NEWLINE='\n'
local PROFILE=`_aws_profile`
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local BCYAN="\[\033[1;36m\]"
local BLUE="\[\033[0;34m\]"
local GRAY="\[\033[0;37m\]"
local DKGRAY="\[\033[1;30m\]"
local WHITE="\[\033[0;37m\]"
local RED="\[\033[0;31m\]"
# return color to Terminal setting for text color
local DEFAULT="\[\033[0;39m\]"
export PS1="\n[\!] \t ${RED}(${LOAD}) ${GREEN}\w\n${BLUE}${PROFILE}${DEFAULT}${CYAN}${BRANCH}${RED}$VENV${DEFAULT}\$ "
}
PROMPT_COMMAND=_prompt_command
# OS specific bash extensions
if [ -f ~/.bash_ext ]; then
source ~/.bash_ext
fi
# Created by `userpath` on 2020-10-24 12:51:29
export PATH="$PATH:/Users/bpack/.local/bin"