Skip to content

Commit e9f4118

Browse files
committed
Add the completion capabilities for git
1 parent e08f20e commit e9f4118

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ RUN apt-get update && apt-get install -y \
8888

8989
COPY src/inputrc /home/silveruser/.inputrc
9090
COPY src/settings.xml /home/silveruser/.m2/
91+
COPY src/git_completion_profile /home/silveruser/.git_completion_profile
9192

9293
RUN chown silveruser:silveruser /home/silveruser/.inputrc \
93-
&& chown silveruser:silveruser /home/silveruser/.m2/settings.xml
94+
&& chown silveruser:silveruser /home/silveruser/.m2/settings.xml \
95+
&& chown silveruser:silveruser /home/silveruser/.git_completion_profile \
96+
&& echo "if [ -f .git_completion_profile ]; then\n . ~/.git_completion_profile\nfi" >> /home/silveruser/.bashrc
9497

9598
ENV LANG ${DEFAULT_LOCALE}
9699
ENV LANGUAGE ${DEFAULT_LOCALE}

src/git_completion_profile

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Scavenged from Git 1.6.5.x contrib/completion/git_completion.bash
2+
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
3+
# returns text to add to bash PS1 prompt (includes branch name)
4+
5+
_git_get ()
6+
{
7+
# you can return anything here for the autocompletion for example all the branches
8+
__gitcomp_nl "$(__git_refs)"
9+
}
10+
11+
__gitdir ()
12+
{
13+
if [ -z "${1-}" ]; then
14+
if [ -n "${__git_dir-}" ]; then
15+
echo "$__git_dir"
16+
elif [ -d .git ]; then
17+
echo .git
18+
else
19+
git rev-parse --git-dir 2>/dev/null
20+
fi
21+
elif [ -d "$1/.git" ]; then
22+
echo "$1/.git"
23+
else
24+
echo "$1"
25+
fi
26+
}
27+
__git_ps1 ()
28+
{
29+
local g="$(__gitdir)"
30+
if [ -n "$g" ]; then
31+
local r
32+
local b
33+
if [ -f "$g/rebase-merge/interactive" ]; then
34+
r="|REBASE-i"
35+
b="$(cat "$g/rebase-merge/head-name")"
36+
elif [ -d "$g/rebase-merge" ]; then
37+
r="|REBASE-m"
38+
b="$(cat "$g/rebase-merge/head-name")"
39+
else
40+
if [ -d "$g/rebase-apply" ]; then
41+
if [ -f "$g/rebase-apply/rebasing" ]; then
42+
r="|REBASE"
43+
elif [ -f "$g/rebase-apply/applying" ]; then
44+
r="|AM"
45+
else
46+
r="|AM/REBASE"
47+
fi
48+
elif [ -f "$g/MERGE_HEAD" ]; then
49+
r="|MERGING"
50+
elif [ -f "$g/BISECT_LOG" ]; then
51+
r="|BISECTING"
52+
fi
53+
54+
b="$(git symbolic-ref HEAD 2>/dev/null)" || {
55+
56+
b="$(
57+
case "${GIT_PS1_DESCRIBE_STYLE-}" in
58+
(contains)
59+
git describe --contains HEAD ;;
60+
(branch)
61+
git describe --contains --all HEAD ;;
62+
(describe)
63+
git describe HEAD ;;
64+
(* | default)
65+
git describe --exact-match HEAD ;;
66+
esac 2>/dev/null)" ||
67+
68+
b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
69+
b="unknown"
70+
b="($b)"
71+
}
72+
fi
73+
74+
local w
75+
local i
76+
local s
77+
local u
78+
local c
79+
80+
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
81+
if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
82+
c="BARE:"
83+
else
84+
b="GIT_DIR!"
85+
fi
86+
elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
87+
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
88+
if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
89+
git diff --no-ext-diff --ignore-submodules \
90+
--quiet --exit-code || w="*"
91+
if git rev-parse --quiet --verify HEAD >/dev/null; then
92+
git diff-index --cached --quiet \
93+
--ignore-submodules HEAD -- || i="+"
94+
else
95+
i="#"
96+
fi
97+
fi
98+
fi
99+
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
100+
git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
101+
fi
102+
103+
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
104+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
105+
u="%"
106+
fi
107+
fi
108+
fi
109+
110+
if [ -n "${1-}" ]; then
111+
printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
112+
else
113+
printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
114+
fi
115+
fi
116+
}
117+
118+
export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWSTASHSTATE=1
119+
120+
# En fait l'important ici c'est le "\033[1;32m\]$(__git_ps1)\[\033[0m\]", le reste c'est mon prompt usuel…
121+
export PS1='\[\033[0;37m\]\u@\h:\[\033[0;33m\]\W\[\033[0m\]\[\033[1;32m\]$(__git_ps1)\[\033[0m\] \$ '

0 commit comments

Comments
 (0)