-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_fishin
More file actions
170 lines (135 loc) · 3.52 KB
/
Copy pathbash_fishin
File metadata and controls
170 lines (135 loc) · 3.52 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
#!/bin/bash
alias vim="nvim"
# don't duplicate commands in history
export HISTCONTROL=ignoreboth:erasedups
# Delete only "bar/" from "foo/bar/" with ctrl-w
if [[ $- == *i* ]]; then
stty werase undef
bind '"\C-w": backward-kill-word'
fi
# COMMAND ALIASES -----------------------------------------------------
function rg() {
if command -v bat > /dev/null 2>&1; then
PAGER="bat -p"
else
PAGER="less -R"
fi
if [ -t 1 ]; then
command rg --smart-case --heading --path-separator // --pretty -g "!*.min.js" -g "!*.map" "$@" | tr -d "\017" | eval "$PAGER"
else
command rg --smart-case --path-separator // "$@"
fi
}
# GIT UTILITIES -------------------------------------------------------
# git status
function g() {
local has_staged_files=$(git status --porcelain 2>/dev/null | egrep '^(M|A|D|R)' | wc -l)
local has_files=$(git status --porcelain 2>/dev/null | egrep '^ M' | wc -l)
if [[ -n "$1" ]]; then
local file="$1"
if [[ -f "$file" || -d "$file" || -n "$(git ls-files "$file" 2>/dev/null)" ]]; then
git add -A -- "$@"
else
git "$@"
fi
return
fi
if [[ $has_staged_files -gt 0 ]]; then
git diff --staged --ignore-cr-at-eol
git status
return
fi
if [[ $has_files -gt 0 ]]; then
if [[ -n "$1" ]]; then
git diff --ignore-cr-at-eol "$@"
else
git diff --ignore-cr-at-eol
git status
fi
return
fi
git status
}
# git add -A
# git commit --amend
function ga() {
local has_staged_files=$(git status --porcelain 2>/dev/null | egrep '^(M|A|D|R)' | wc -l)
if [[ $has_staged_files -eq 0 ]]; then
git add -A
fi
git commit --amend
}
# git commit -m 'blabla'
function gc() {
local has_staged_files=$(git status --porcelain 2>/dev/null | egrep '^(M|A|D|R)' | wc -l)
local has_files=$(git status --porcelain 2>/dev/null | egrep '^( M|\?\?)' | wc -l)
if [[ $has_staged_files -gt 0 ]]; then
if [[ -n "$*" ]]; then
git commit -m "$*"
else
git commit
fi
return
fi
if [[ $has_files -gt 0 ]]; then
git add -A
if [[ -n "$*" ]]; then
git commit -m "$*"
else
git commit
fi
return
fi
git commit -m 'show git error message'
}
# git checkout blabla
function gco() {
git checkout "$@"
}
# git show (evitiamo gs per non mascherare ghostscript)
function gg() {
git show "$@"
}
# git log -u FILENAME
# git log
function gl() {
local FILENAME="$1"
if [[ "$FILENAME" == "--" ]]; then
FILENAME="$2"
fi
if [[ -n "$FILENAME" ]]; then
git log --full-history --follow -u -- "$FILENAME"
else
git log
fi
}
# git tree
function gt() {
git log --graph --oneline --exclude=refs/stash --all --date-order
}
# PROMPT --------------------------------------------------------------
shorten_path() {
pwd | sed -E -e "s:^${HOME}:~:" -e "s:([^/\.])[^/]+/:\1/:g"
}
parse_git_branch() {
if git rev-parse --is-inside-work-tree &>/dev/null; then
local BRANCH=$(git branch --show-current 2>/dev/null)
local DIRTY=$(git status --porcelain 2>/dev/null)
local COLOR=""
# uncommitted changes or untracked files
if [ -n "$DIRTY" ]; then
COLOR="\e[31m" # red
else
AHEAD=$(git status --porcelain --branch 2>/dev/null | grep -c '\[ahead ')
# we are ahead of the remote branch (unpushed commits)
if [ $AHEAD -ne 0 ]; then
COLOR="\e[34m" # blue
else
COLOR="\e[33m" # yellow
fi
fi
echo -e "(\001${COLOR}\002${BRANCH}\001\e[0m\002)"
fi
echo ""
}
PS1="\$(parse_git_branch) \[\033[32m\]\$(shorten_path)\[\033[00m\] "