-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
231 lines (198 loc) · 6.06 KB
/
.bashrc
File metadata and controls
231 lines (198 loc) · 6.06 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export OTHER_REPOS=("my-project" "my-other-project")
# Values to make outputs color coded.
RED='\033[0;31m'
NC='\033[0m'
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
alias clearBranches='git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D'
# Typically, I like to create aliases for my projects so I can easily switch between
# multiple projects relatively quickly. For example, this is how I would switch to a project
# folder named "janet".
# alias j='cd ~/Desktop/Projects/janet'
# A collection of aliases used to quickly switch between git branches,
# assist in adding files and checking git status.
alias bm='git checkout main'
alias bd='git checkout dev'
alias s='git status'
alias a='git add .'
source ~/.profile
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
# Function to switch quickly to an already existing branch. If certain repos require a prefix for the branch,
# or different prefixs you can specify them in the OTHER_REPOS variable.
#
# EXAMPLE USAGE:
# In repo named my-project
# `b new-feature` => `git checkout PROJECTPREFIX-new-feature`
# In repo named something-else-project
# `b new-feature` => `git checkout new-feature`
function b() {
repo=$(basename `git rev-parse --show-toplevel`)
if [[ " ${OTHER_REPOS[@]} " =~ " ${repo} " ]]; then
git checkout PROJECTPREFIX-$1
else
git checkout $1
fi
}
# Function to quickly create a branch. If certain repos require a prefix for the branch,
# or different prefixs you can specify them in the OTHER_REPOS variable.
#
# EXAMPLE USAGE:
# In repo named my-project
# `nb new-feature` => `git checkout -b PROJECTPREFIX-new-feature`
# In repo named something-else-project
# `nb new-feature` => `git checkout -b new-feature`
function nb() {
repo=$(basename `git rev-parse --show-toplevel`)
if [[ " ${OTHER_REPOS[@]} " =~ " ${repo} " ]]; then
git checkout -b PROJECTPREFIX-$1
else
git checkout -b $1
fi
}
# Deletes the specified branch after confirmation.
#
# EXAMPLE USAGE:
# `db 123`
function db() {
branch=$1
read -p "Are you sure? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
return
fi
repo=$(basename `git rev-parse --show-toplevel`)
if [[ " ${OTHER_REPOS[@]} " =~ " ${repo} " ]]; then
git branch -D ${PROJECTPREFIX}-$branch
else
git branch -D $branch
fi
}
# Function to quickly push changes out to the remote repository. Function will prevent
# a push onto the main branch
#
# EXAMPLE USAGE:
# `p` => `git push`
function p() {
current=$(git rev-parse --abbrev-ref HEAD)
if [ "$current" == "main" ]
then
echo -e "${RED}YOU CANNOT DIRECTLY PUSH TO MAIN.${NC}"
else
git push
fi
}
# Function to quickly push a new branch up out to the remote repository. Function will prevent
# a push onto the main branch
#
# EXAMPLE USAGE:
# `pb` => `git push -u origin new-branch`
function pb() {
current=$(git rev-parse --abbrev-ref HEAD)
if [ "$current" == "main" ]
then
echo -e "${RED}YOU CANNOT DIRECTLY PUSH TO MAIN.${NC}"
else
git push -u origin $current
fi
}
# Function to quickly commit to the current branch, prefixed with the current branch name.
# Function will prevent a commit on the main branch.
#
# EXAMPLE USAGE:
# `c "Initial Commit"` => `git commit -m "branch_name: Initial Commit"`
function c() {
current=$(git rev-parse --abbrev-ref HEAD)
if [ "$current" == "main" ]
then
echo -e "${RED}YOU CANNOT DIRECTLY COMMIT TO MAIN.${NC}"
else
git commit -m "$current: $1"
fi
}
# Function will cherry-pick the given SHA. Function prevents main branch from being used.
#
# EXAMPLE USAGE:
# `cp shaid` => `git cherry-pick shaid`
function cp() {
current=$(git rev-parse --abbrev-ref HEAD)
if [ "$current" == "main" ]
then
echo -e "${RED}YOU CANNOT DIRECTLY COMMIT TO MAIN.${NC}"
else
git cherry-pick $1
fi
}
# Function will pull the main branch switcing back to the currently viewed branch.
# If there are existing changes, it will stash them.
#
# EXAMPLE USAGE:
# `pm`
function pm() {
current=$(git rev-parse --abbrev-ref HEAD)
git stash
git checkout main
git pull
git checkout $current
}
# Function will open the URL to create a new PR for the current repo on the current branch.
#
# EXAMPLE USAGE:
# `npr`
function npr() {
repo_url=$(git config --get remote.origin.url)
branch=$(git rev-parse --abbrev-ref HEAD)
${var1%.out}
open "${repo_url%.git}/pull/new/$branch"
}
# Function will copy the current commit URL path to the clipboard.
#
# EXAMPLE USAGE:
# `cgc`
function cgc() {
commit_link | pbcopy
}
# Function will "go to" the current commit URL path.
#
# EXAMPLE USAGE:
# `gc`
function gc() {
repo_url=$(git config --get remote.origin.url)
commit_sha=$(git rev-parse HEAD)
open "${repo_url%.git}/commit/$commit_sha"
}
# Function will copy the current commit SHA to the clipboard.
#
# EXAMPLE USAGE:
# `csha`
function csha() {
commit_sha=$(git rev-parse HEAD)
echo $commit_sha | pbcopy
}
# Opens the current repository in the browser.
#
# # EXAMPLE USAGE:
# `or`
function or() {
repo_url=$(git config --get remote.origin.url)
open ${repo_url%.git}
}
# Helper function that returns the current commit link.
function commit_link() {
repo_url=$(git config --get remote.origin.url)
commit_sha=$(git rev-parse HEAD)
echo "${repo_url%.git}/commit/$commit_sha"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm