-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
161 lines (135 loc) · 3.5 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
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Disable the annoying terminal output stop function
# This leaves Ctrl + S and Ctrl + Q free for binding in Vim for example
stty stop ''
stty start ''
################### Aliases #####################
alias ls='ls --color=auto'
alias vi=vim
alias ll="ls -la --color=auto"
################## Useful functions ###################
function sshf {
if [ $# -lt 1 ];
then
echo "Specify port to forward!"
return
elif [ $# -eq 2 ];
then
ssh -N -L${1}:localhost:${1} $2
elif [ $# -eq 1 ];
then
ssh -N -L${1}:localhost:${1} blackbird
fi
}
function duh {
if [[ ! $# = 1 ]] || [[ ! -d $1 ]];
then
echo "Enter a directory!"
return
fi
du -sk ${1}/* ${1}/.[!.]* | sort -n | awk '
function bytes_to_readable(bytes) {
tb = bytes / (1024*1024*1024*1024)
if(tb >= 1){
printf "%.3fTB", tb
return
}
gb = bytes / (1024*1024*1024)
if(gb >= 1){
printf "%.3fGB", gb
return
}
mb = bytes / (1024*1024)
if(mb >= 1){
printf "%.3fMB", mb
return
}
kb = bytes / (1024)
if(kb >= 1){
printf "%.3fKB", kb
return
}
printf "%dB", bytes
}
{
bytes=bytes_to_readable($1*1024);
$1="";
print bytes,$0
}'
}
function dockerbash() {
case $# in
0)
echo "Enter at least the name of a container"
return 1
;;
1)
docker exec -t -i $1 /bin/bash
;;
3)
if [ ! "$2" = "-u" ]
then
echo "Use: dockerbash [containername] -u [user]"
return 1
fi
container=$1
user=$3
docker exec -ti -u $user $container /bin/bash
;;
esac
}
function docker-pid() {
docker inspect --format '{{ .State.Pid }}' "$@"
}
function docker-entry() {
docker inspect --format 'Entry: {{.Config.Entrypoint}} CMD: {{.Config.Cmd}}' "$@"
}
alias dockerclean='docker images -qf dangling=true | xargs docker rmi'
function ignoredir() {
local DIR=${1:-$(pwd)}
if [ ! -d "$DIR" ];
then
echo $DIR is not a directory
return 1
fi
echo '*' >> $DIR/.gitignore
echo '!.gitignore' >> $DIR/.gitignore
}
function ssh-script() {
if [ $# -lt 2 ]
then
echo "Usage: ssh-script user@host [local_script.sh] arg1 arg2 ..."
return 1
fi
local host=$1
local localscript=$2
shift
shift
ssh $host "bash -s -- $@" < $localscript
}
function cast() {
castnow --myip 192.168.1.174 $@
}
################## History options ###################
# Append to the history file, don't overwrite it
shopt -s histappend
# Huge history. Doesn't appear to slow things down, so why not?
HISTSIZE=500000
HISTFILESIZE=100000
HISTTIMEFORMAT="%Y-%m-%d %T "
################### ENV variables #####################
export GOPATH=~/code/go/gopath
export PATH=$GOPATH/bin:$PATH
export PATH=~/bin:$PATH
export PATH=~/.cargo/bin:$PATH
export EDITOR=vim
export TERM=xterm-256color
# This breaks highlighting searches in less
#export TERM=screen-256color
PS1='[\u@\h \W]\$ '
export ANDROID_HOME=/opt/android-sdk/
export PATH=/opt/dart/flutter/bin:$PATH