-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_git
More file actions
73 lines (60 loc) · 1.69 KB
/
Copy path_git
File metadata and controls
73 lines (60 loc) · 1.69 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
#!/bin/bash
function gs {
local tmp_submodule="$(mktemp -t XXXXXX)"
local tmp_status="$(mktemp -t XXXXXX)"
(
(
cd ./$($(type -P git) rev-parse --show-cdup) > /dev/null
$(type -P git) submodule summary > "$tmp_submodule"
) &
# TODO add -b back with autodetect of git version
$(type -P git) status -s --ignore-submodules=dirty > "$tmp_status" &
wait
)
cat "$tmp_submodule"
cat "$tmp_status"
rm -f "$tmp_submodule" "$tmp_status"
}
alias gl="$(type -P git) lg"
alias gd="$(type -P git) difftool"
alias gm="$(type -P git) mergetool"
function gdiff {
local len="$(git diff --no-ext-diff -w -b "$@" | wc -l | awk '{print $1}')"
if [[ "$len" != 0 ]]; then
$(type -P git) diff --no-ext-diff -w -b "$@" | vim -R -
fi
}
# http://jeetworks.org/node/52
function cdd {
if [[ $(which git 2> /dev/null) ]]; then
STATUS=$(git status --ignore-submodules=dirty 2>/dev/null)
if [[ -z $STATUS ]]; then
return
fi
TARGET="./$(git rev-parse --show-cdup)$1"
cd $TARGET
fi
}
function _cdd {
if [[ $(which git 2> /dev/null) ]]; then
STATUS=$(git status --ignore-submodules=dirty 2>/dev/null)
if [[ -z $STATUS ]]; then
return
fi
TARGET="./$(git rev-parse --show-cdup)"
if [[ -d $TARGET ]]; then
TARGET="$TARGET/"
fi
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}$2"
dirnames=$(cd $TARGET; compgen -o dirnames $2)
opts=$(for i in $dirnames; do if [[ $i != ".git" ]]; then echo $i/; fi; done)
if [[ ${cur} == * ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
fi
}
complete -o nospace -F _cdd cdd
PATH="$PATH:/usr/local/git/bin"