-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_profile
183 lines (159 loc) · 5.12 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
# Standard profile
# ----------------
# With Mac's default interactive shell now zsh, we'll want to silence the obnoxious message
export BASH_SILENCE_DEPRECATION_WARNING=1
# M1 Mac
# eval "$(/opt/homebrew/bin/brew shellenv)"
# DOCKER_DEFAULT_PLATFORM="linux/amd64"
# Shell Personality
source /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
export PS1='🪂 \u(\[\e[0;36m\]\W\[\e[m\])\[\e[1;32m\]$(__git_ps1 " (%s)")\[\e[m\]→ '
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
# Replaces fzf grep with ripgrep when STDIN pipe isn't provided - makes fzf faster
export FZF_DEFAULT_COMMAND='rg --files --hidden --no-require-git --follow --glob "!.git/*"'
# Python
eval "$(pyenv init --path)"
# Go
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
# JavaScript
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Meta
alias ebash="code ~/.bash_profile"
alias rbash="source ~/.bash_profile"
# Dev
alias push="git push"
alias pushF="git push --force"
alias pull="git pull"
alias stash="git stash --include-untracked"
alias pop="git stash pop"
alias gs="clear; git status"
alias gl="git log"
alias ga="git add . ; git status"
alias gc="git commit -m "
alias gchB="git checkout -B"
gh () { # open github branch specfic directory in web browser
local branch origin repoURL repoName repoDirectory url
branch=$(git rev-parse --abbrev-ref HEAD)
origin=$(git config --get remote.origin.url)
repoURL=$(echo $origin | sed -e's/git@/http:\/\//' -e's/\.git$//' | sed -E 's/(\/\/[^:]*):/\1\//')
repoURL+="/tree/$branch"
repoName=$(echo $origin | sed -e'0,/\//d' -e's/.*\///' -e's/\.git$//')
repoDirectory=$(pwd | sed "s/.*$repoName//")
url="$repoURL$repoDirectory"
open $url
}
gbD () { # git branch delete with fuzzy matching
local branches branchInfo branchName
branches=$(git --no-pager branch -vv) &&
branchInfo=$(echo "$branches" | fzf +m) &&
branchName=$(echo "$branchInfo" | awk '{print $1}' | sed "s/.* //")
echo Type \'yes\' if you want to delete "$branchName"
read ans
if [ "$ans" = 'yes' ] ; then
git branch -D $(echo "$branchName")
else
echo Aborting.
fi
}
gch () { # checkout git branch with fuzzy matching
local branches branch
branches=$(git --no-pager branch -vv) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
greset1 () {
echo Type \'yes\' if you want to reset your git history by one commit:
read ans
if [ "$ans" = 'yes' ] ; then
git log -2 | grep commit | tail -1 | awk '{print $NF}' | xargs git reset
else
echo Aborting.
fi
}
ys () { # select and run a package.json script THROUGH YARN with fuzzy matching
local script
if [ ! -e package.json ]; then
echo No package.json in this directory
else
script=$(jq '.scripts | keys[]' package.json | sed 's/"//g' | fzf)
yarn run $script
fi
}
ns () { # select and run a package.json script THROUGH NPM with fuzzy matching
local script
if [ ! -e package.json ]; then
echo No package.json in this directory
else
script=$(jq '.scripts | keys[]' package.json | sed 's/"//g' | fzf)
npm run $script
fi
}
# Preferred options
alias mv="mv -v"
alias rm="rm -i -v"
alias cp="cp -v"
alias ls="ls -Aplhtr"
alias grep="grep --ignore-case --color --line-number"
alias mkdir="mkdir -pv "
# Navigation
alias x="exit"
alias o="open ."
alias ..="cd ..; clear; ls"
alias ...="cd ../..; clear; ls"
alias ~="cd ~; clear; ls"
alias Downloads="cd ~/Downloads; clear; ls"
alias Documents="cd ~/Documents; clear; ls"
alias Dev="cd ~/Dev; clear; ls"
fd() { # Fuzzy match directory navigation
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m)
cd "$dir"
}
fhistory() { # Fuzzy match shell history search and evaluation
local cmd
cmd=$(history | cut -c 8- | fzf)
echo "$cmd"
eval "$cmd"
}
# Miscellaneous
alias c.="code ."
alias c="clear"
alias l="clear; ls"
alias ninja="chmod 700 "
alias sneak="chmod 600 "
alias epg="printenv | grep "
alias path='echo -e ${PATH//:/\\n}'
alias ip="ipconfig getifaddr en0"
alias mac="networksetup -getmacaddress en0"
alias m="make"
alias big10="du -a -h ./ | sort -h -r | head -n 10"
wifipwd () { # Retrieve wifi password - fuzzy match SSIDs if none is provided
local network
network=$1
if [ "$network" = "" ] ; then
network=$(networksetup -listpreferredwirelessnetworks en0 | awk '{$1=$1};1' | fzf)
fi
if [ "$network" != "" ] ; then # network could still be empty if fzf was exited
echo Network: $network
security find-generic-password -ga "$network" | grep "password:"
fi
}
fkill () { # Fuzzy matching process murder
local process pid
process=$(ps -ef | sed 1d | fzf -m)
if [ "$process" != "" ] ; then
pid=$(echo "$process" | awk '{print $2}')
echo $pid | xargs kill -${1:-9}
echo $process
fi
}
emoji () { # Fuzzy match emoji printing
local emojis selected_emoji
emojis=$(curl -sSL 'https://git.io/JXXO7')
selected_emoji=$(echo "$emojis" | fzf)
echo $selected_emoji
}