-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_profile
188 lines (162 loc) · 7.23 KB
/
.bash_profile
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# neau's .bash_profile
# Last change on Sat Feb 24 22:52:52 EET 2018
# Enable visibility of invisible files for Finder in OS X.
# More information on http://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app'
# Common aliases
alias ll='ls -lah'
alias l='ls'
alias grep='grep --color=auto'
# Networking Aliases
alias myip='curl ip.appspot.com' # myip: Public facing IP Address
alias netCons='lsof -i' # netCons: Show all open TCP/IP sockets
alias flushDNS='dscacheutil -flushcache' # flushDNS: Flush out the DNS Cache
alias lsock='sudo /usr/sbin/lsof -i -P' # lsock: Display open sockets
alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP' # lsockU: Display only open UDP sockets
alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP' # lsockT: Display only open TCP sockets
alias ipInfo0='ipconfig getpacket en0' # ipInfo0: Get info on connections for en0
alias ipInfo1='ipconfig getpacket en1' # ipInfo1: Get info on connections for en1
alias openPorts='sudo lsof -i | grep LISTEN' # openPorts: All listening connections
alias showBlocked='sudo ipfw list' # showBlocked: All ipfw rules inc/ blocked IPs
# Searching
alias qfind="find . -name " # qfind: Quickly search for file
ff () { /usr/bin/find . -name "$@" ; } # ff: Find file under the current directory
ffs () { /usr/bin/find . -name "$@"'*' ; } # ffs: Find file whose name starts with a given string
ffe () { /usr/bin/find . -name '*'"$@" ; } # ffe: Find file whose name ends with a given string
# extract: Extract most know archives with one command
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# my_ps: List processes owned by my user:
my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }
# rm -rf is such a legendarily dangerous command that any shell user should already know to avoid it,
# regardless of what aliases they have set up. Meanwhile, alias rm = rm -i has always seemed to me an
# obvious and necessary safeguard, given that rm is irreversible, unlike sending a file to the trash.
alias rmi="rm -i"
# only show dot files
alias lsh="ls -ld .??*"
# LESS man page colors
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
# Create directory and enter it.
mkcd () {
mkdir -p "$*"
cd "$*"
}
# Display useful host related informaton.
ii() {
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Current network location :$NC " ; scselect
echo -e "\n${RED}Public facing IP Address :$NC " ;myip
#echo -e "\n${RED}DNS Configuration:$NC " ; scutil --dns
echo
}
# memHogsTop, memHogsPs: Find memory hogs.
alias memHogsTop='top -l 1 -o rsize | head -20'
alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'
# cpuHogs: Find CPU hogs
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
# findPid: find out the pid of a specified process
# -----------------------------------------------------
# Note that the command name can be specified via a regex
# E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
# Without the 'sudo' it will only find processes of the current user
# -----------------------------------------------------
findPid () { lsof -t -c "$@" ; }
function sshKeyGen(){
echo "What is the name of the Key (nospaced please)?";
read name;
echo "What is the email associated with it?";
read email;
`ssh-keygen -t rsa -f ~/.ssh/id_rsa_$name -C "$email"`;
ssh-add ~/.ssh/id_rsa_$name
pbcopy < ~/.ssh/id_rsa_$name.pub;
echo "SSH Key copied in your clipboard";
}
# grabs the latest .bash_profile file and reloads the prompt
alias updatebashprofile="curl https://raw.githubusercontent.com/neau/dotfiles/master/.bash_profile > ~/.bash_profile && reload"
# hhhhhhnnnnnngggg
alias ..="cd ../"
alias ...="cd ../../"
alias ....="cd ../../../"
# rename all the files which contain uppercase letters to lowercase in the current folder
function filestolower(){
read -p "This will rename all the files and directories to lowercase in the current folder, continue? [y/n]: " letsdothis
if [ "$letsdothis" = "y" ] || [ "$letsdothis" = "Y" ]; then
for x in `ls`
do
skip=false
if [ -d $x ]; then
read -p "'$x' is a folder, rename it? [y/n]: " renamedir
if [ "$renamedir" = "n" ] || [ "$renameDir" = "N" ]; then
skip=true
fi
fi
if [ "$skip" == "false" ]; then
lc=`echo $x | tr '[A-Z]' '[a-z]'`
if [ $lc != $x ]; then
echo "renaming $x -> $lc"
mv $x $lc
fi
fi
done
fi
}
# Generates a tree view from the current directory
function tree(){
pwd
ls -R | grep ":$" | \
sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
}
# remove_disk: spin down unneeded disk
# ---------------------------------------
# diskutil eject /dev/disk1s3
# to change the password on an encrypted disk image:
# ---------------------------------------
# hdiutil chpass /path/to/the/diskimage
# to mount a read-only disk image as read-write:
# ---------------------------------------
# hdiutil attach example.dmg -shadow /tmp/example.shadow -noverify
# mounting a removable drive (of type msdos or hfs)
# ---------------------------------------
# mkdir /Volumes/Foo
# ls /dev/disk* to find out the device to use in the mount command)
# mount -t msdos /dev/disk1s1 /Volumes/Foo
# mount -t hfs /dev/disk1s1 /Volumes/Foo
# to create a file of a given size: /usr/sbin/mkfile or /usr/bin/hdiutil
# ---------------------------------------
# e.g.: mkfile 10m 10MB.dat
# e.g.: hdiutil create -size 10m 10MB.dmg
# the above create files that are almost all zeros - if random bytes are desired
# then use: ~/Dev/Perl/randBytes 1048576 > 10MB.dat
# Install helm-cli
# via https://helm.sh/docs/intro/install/
alias helm-install='curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash'
echo "neau's .bash_profile succesfully loaded."