-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_bindings_config
50 lines (43 loc) · 1.17 KB
/
bash_bindings_config
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
RED='\033[0;31m'
BLUE='\033[0;34m'
NO_COLOR='\033[0m'
view_history() {
CURRENT_LINE=$READLINE_LINE
RESULTS=""
LINE_NO_LEAD_SPACE="$(echo -e "${CURRENT_LINE}" | sed -e 's/^[[:space:]]*//')"
if [ ! -z "$LINE_NO_LEAD_SPACE" ]; then
echo -e "${BLUE}Searching history for $LINE_NO_LEAD_SPACE${NO_COLOR}"
RESULTS=`history | grep "$LINE_NO_LEAD_SPACE"`
fi
if [ ! -z "$RESULTS" ]; then
echo "$RESULTS"
else
echo -e "${RED}No results found${NO_COLOR}"
fi
}
git_add() {
READLINE_LINE="git add "
READLINE_POINT=8
}
line_replacer() {
LINE="$1"
LEN=${#LINE}
READLINE_LINE="$LINE"
READLINE_POINT=$LEN
}
tester() {
echo works
}
## Binds CTRL + H to show all occurences in history for entered line
bind -x '"\C-h": view_history'
## Git Shortcuts
### CTRL + G + A to `git add `
bind -x '"\C-g\C-a": line_replacer "git add "'
### CTRL + G + C to `git commit `
bind -x '"\C-g\C-c": line_replacer "git commit "'
### CTRL + G + O to `git checkout `
bind -x '"\C-g\C-o": line_replacer "git checkout "'
### CTRL + G + B to `git branch `
bind -x '"\C-g\C-b": line_replacer "git branch "'
### CTRL + G + P + O to `git push origin `
bind -x '"\C-g\C-p\C-o": line_replacer "git push origin "'