-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
37 lines (31 loc) · 1.06 KB
/
.functions
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
# Copy w/ progress
function cp_p () {
rsync -WavP --human-readable --progress $1 $2
}
function strip_diff_leading_symbols(){
color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)[m|K])?"
# simplify the unified patch diff header
sed -E "s/^($color_code_regex)diff --git .*$//g" | \
sed -E "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \
sed -E "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\
# actually strips the leading symbols
sed -r "s/^($color_code_regex)[\+\-]/\1 /g"
}
## Print a horizontal rule
rule () {
printf "%$(tput cols)s\n"|tr " " "="
}
function git_default_branch() {
if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
echo $default_branch
fi
}
git_rebase_main_func() {
stash_output=$(git stash)
git checkout $(git_default_branch)
git pull -p
git checkout -
git rebase $(git_default_branch)
[[ $stash_output != 'No local changes to save' ]] && git stash pop || true
}