-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
138 lines (115 loc) · 3.82 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
# navigate
alias ls='ls -G'
alias ll='ls -l'
alias la='ls -la'
# git
alias gs='git status'
alias gb='git branch'
alias gl='git log'
alias gd='git diff'
alias ga='git add'
alias gc='git checkout'
alias gmm='git commit -m'
alias gam='git commit --amend'
alias gcm='git checkout main'
alias gcd='git checkout develop'
alias gsm='git switch main'
alias gsd='git switch develop'
alias gcb='git checkout -b'
alias gpom='git pull origin main'
alias gpod='git pull origin develop'
alias gpum='git pull upstream main'
alias gpud='git pull upstream develop'
function gpo() {
local B=$(git branch | grep '^* ' | perl -pe 's/^\* //gc')
git push origin $B
}
function gsddb() {
local B=$(git branch | grep '^* ' | perl -pe 's/^\* //gc')
git switch develop && git pull origin develop && git branch -d $B
}
function gsmdb() {
local B=$(git branch | grep '^* ' | perl -pe 's/^\* //gc')
git switch main && git pull origin main && git branch -d $B
}
function gfpr() {
git fetch origin pull/$@/head:pr-$@
}
# history
HISTSIZE=30000
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
HISTCONTROL=ignoredups
# functions
function _find_cmd() {
which $1 2>/dev/null
}
# pbcopy,pbpaste (osx)
if [ -n "$(_find_cmd pbcopy)" ]; then
alias pb='perl -pe "chomp" | pbcopy && pbpaste'
fi
# brew
if [ -n "$(_find_cmd brew)" ]; then
BREW_PREFIX=`brew --prefix`
[[ -r "${BREW_PREFIX}/etc/profile.d/bash_completion.sh" ]] && . "${BREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
# fzf
if [ -n "$(_find_cmd fzf)" ]; then
export FZF_DEFAULT_OPTS='--reverse'
function fbd() {
local PRE_IFS=$IFS
IFS=$'\n'
local parent=$(for d in $(pwd | perl -pe 's|/|\n|gc' | tail -r); do
local p=$p../; echo $p$d;
done | fzf)
IFS=$PRE_IFS
[ -n "$parent" ] && cd "$parent"
}
function frepo() {
local DIR=$(find ~/repos \( -type d -o -type l \) -mindepth 3 -maxdepth 3 | perl -pe "s|${HOME}/repos/||" | fzf)
[ ! -z $DIR ] && cd -P ~/repos/${DIR}
}
function fhistory() {
local CMD=$(HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S - " history | tail -r | fzf)
CMD=`echo ${CMD} | perl -pe 's/.+? - (.+)/$1/gc'`
history -s ${CMD}
eval ${CMD}
}
fi
# peco
if [ -n "$(_find_cmd peco)" ]; then
alias peco="peco --rcfile ~/dotfiles/.peco/config.json"
function pessh() {
local OPT=$@
local HOST=$(cat ~/.ssh/known_hosts | awk "{print \$1}" | perl -pe "s/,.+//" | peco)
history -s pessh ${OPT}
history -s ssh "${OPT} ${HOST}"
ssh ${OPT} ${HOST}
}
pehistory() {
local CMD=$(HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S - " history | tail -r | peco)
CMD=`echo ${CMD} | perl -pe 's/.+? - (.+)/$1/gc'`
history -s ${CMD}
eval ${CMD}
}
perepo() {
local REPODIR=repos
REPODIR=$(echo ${REPODIR} | perl -pe 's|(^/).+(/$)||')
local DIR=$(find ~/${REPODIR} -type d -o -type l -mindepth 3 -maxdepth 3 | perl -pe "s|`echo $(cd ~ && pwd)/${REPODIR}/`||" | peco)
[ ! -z $DIR ] && cd -P ~/${REPODIR}/${DIR}
}
fi
# tmux
if [ -f ~/dotfiles/.tmux.conf ]; then
alias tmux="tmux -f ~/dotfiles/.tmux.conf"
fi
# bashrc
alias bashrc='vim ~/dotfiles/.bashrc'
# git diff-highlight
[ -z "${GIT_DIFF_HIGHLIGHT_PATH}" ] && GIT_DIFF_HIGHLIGHT_PATH=/usr/local/share/git-core/contrib/diff-highlight
[ -d ${GIT_DIFF_HIGHLIGHT_PATH} ] && export PATH=${GIT_DIFF_HIGHLIGHT_PATH}:${PATH}
# tabtab source for serverless package
# uninstall by removing these lines or running `tabtab uninstall serverless`
[ -f /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.bash ] && . /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.bash
# tabtab source for sls package
# uninstall by removing these lines or running `tabtab uninstall sls`
[ -f /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.bash ] && . /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.bash