41:14d2a23ab38f
Anton Shestakov <engored@ya.ru>, 2014-08-28
Lose .Xdefaults (only stjerm settings).

next change 42:34ee83bd5ad2
previous change 40:48d26a4c35ba

.bash_prompt

Permissions: -rw-r--r--

Other formats: Feeds:
0
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
#!/bin/bash
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
RETURN_CODE="$?"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
RESET="\[\e[0m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
BOLD="\[\e[1m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
R="\[\e[1;31m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
G="\[\e[1;32m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
Y="\[\e[1;33m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
B="\[\e[1;34m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
P="\[\e[1;35m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
C="\[\e[1;36m\]"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
TIME="${G}\t${RESET}"
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
0
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
function prompt_command {
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
if [[ $EUID == 0 ]] ; then
3
3:cb307dcaf2ef More quotes.
Anton Shestakov <engored@ya.ru>
previous changes: 2:9c916e36d032
line | diff
local PROMPT_COLOR="$R"
2
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
# getting hg and git info is disabled for root
5
5:7b2ad8123a53 virtualenv support.
Anton Shestakov <engored@ya.ru>
previous changes: 3:cb307dcaf2ef
line | diff
local HG_INFO=" ${P}-${RESET}"
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
local GIT_INFO=" ${G}-${RESET}"
2
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
else
3
3:cb307dcaf2ef More quotes.
Anton Shestakov <engored@ya.ru>
previous changes: 2:9c916e36d032
line | diff
local PROMPT_COLOR="$G"
2
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
# testing if current dir is a part of hg/git repo
3
3:cb307dcaf2ef More quotes.
Anton Shestakov <engored@ya.ru>
previous changes: 2:9c916e36d032
line | diff
local TEST_DIR="$PWD"
2
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
while true ; do
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
[[ -d "$TEST_DIR/.hg" ]] && local HG_TRACKED=1 && break
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
[[ -d "$TEST_DIR/.git" ]] && local GIT_TRACKED=1 && break
3
3:cb307dcaf2ef More quotes.
Anton Shestakov <engored@ya.ru>
previous changes: 2:9c916e36d032
line | diff
[[ "$TEST_DIR" == '/' ]] && break
2
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
TEST_DIR=$(dirname "$TEST_DIR")
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
done
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
if [[ $HG_TRACKED ]] ; then
33
33:b0de9677e28d .bash_prompt cleanup, unification.
Anton Shestakov <engored@ya.ru>
previous changes: 32:ec26c70bf440
line | diff
local SUM=$(LC_ALL=C hg sum 2>/dev/null)
32
32:ec26c70bf440 Save on echo.
Anton Shestakov <engored@ya.ru>
previous changes: 30:3327ef700923
line | diff
local PARENTS=($(grep -Po '(?<=parent: ).*(?=:)' <<< "$SUM"))
32:ec26c70bf440 Save on echo.
Anton Shestakov <engored@ya.ru>
previous changes: 30:3327ef700923
line | diff
local BRANCH=$(grep -Po '(?<=branch: ).*$' <<< "$SUM")
32:ec26c70bf440 Save on echo.
Anton Shestakov <engored@ya.ru>
previous changes: 30:3327ef700923
line | diff
local COMMIT=$(grep -Po '(?<=commit: ).*$' <<< "$SUM")
32:ec26c70bf440 Save on echo.
Anton Shestakov <engored@ya.ru>
previous changes: 30:3327ef700923
line | diff
local UPDATE=$(grep -Po '(?<=update: ).*$' <<< "$SUM")
30
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
local REV=${PARENTS[0]}
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
local MERGEREV=${PARENTS[1]}
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
BRANCH=${BRANCH/default/}
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
[ -z "$MERGEREV" ] || MERGEREV="+$MERGEREV"
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
case "$COMMIT" in
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
*'(clean)'*)
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
COMMIT=''
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
;;
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
*added*|*modified*|*deleted*)
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
COMMIT='!'
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
;;
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
esac
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
case "$UPDATE" in
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
*'(update)'*)
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
UPDATE='^'
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
;;
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
*'(merge)'*)
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
UPDATE=''
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
;;
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
*'(current)'*)
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
UPDATE=''
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
;;
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
esac
30:3327ef700923 Replace hg-prompt-dependent mercurial prompt with hg sum, bash and grep.
Anton Shestakov <engored@ya.ru>
previous changes: 28:dda34692ae7d
line | diff
local HG_INFO=" ${P}${BRANCH}${REV}${R}${UPDATE}${G}${MERGEREV}${R}${COMMIT}${RESET}"
2
2:9c916e36d032 Renamed .bashrc to .bash_prompt. Disabled any hg interaction for root.
Anton Shestakov <engored@ya.ru>
previous changes: 1:ef4ec926e9a4
line | diff
fi
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
if [[ $GIT_TRACKED ]] ; then
33
33:b0de9677e28d .bash_prompt cleanup, unification.
Anton Shestakov <engored@ya.ru>
previous changes: 32:ec26c70bf440
line | diff
local GIT_STATUS=$(LC_ALL=C git status 2>/dev/null)
33:b0de9677e28d .bash_prompt cleanup, unification.
Anton Shestakov <engored@ya.ru>
previous changes: 32:ec26c70bf440
line | diff
local GIT_BRANCH=$(grep -Po '(?<=On branch ).*$' <<< "$GIT_STATUS")
38
38:aeaac3ebe25e Show current git hash.
Anton Shestakov <engored@ya.ru>
previous changes: 35:44a6ddc7f222
line | diff
local GIT_REV=$(LC_ALL=C git rev-parse --short HEAD 2>/dev/null)
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
34
34:6d42e8d89e7e .bash_prompt: replace grep with "string contains" bashism.
Anton Shestakov <engored@ya.ru>
previous changes: 33:b0de9677e28d
line | diff
if [[ $GIT_STATUS == *'Your branch is behind'* ]]; then
39
39:06ada8ea9a31 Behind and ahead of branches in git.
Anton Shestakov <engored@ya.ru>
previous changes: 38:aeaac3ebe25e
line | diff
local GIT_BEHIND="$R^"
40
40:48d26a4c35ba Ahead/behind commit count.
Anton Shestakov <engored@ya.ru>
previous changes: 39:06ada8ea9a31
line | diff
[[ $GIT_STATUS =~ behind[^$'\n']+([0-9]+)' 'commit ]] && GIT_BEHIND+=${BASH_REMATCH[1]}
39
39:06ada8ea9a31 Behind and ahead of branches in git.
Anton Shestakov <engored@ya.ru>
previous changes: 38:aeaac3ebe25e
line | diff
fi
39:06ada8ea9a31 Behind and ahead of branches in git.
Anton Shestakov <engored@ya.ru>
previous changes: 38:aeaac3ebe25e
line | diff
if [[ $GIT_STATUS == *'Your branch is ahead'* ]]; then
39:06ada8ea9a31 Behind and ahead of branches in git.
Anton Shestakov <engored@ya.ru>
previous changes: 38:aeaac3ebe25e
line | diff
local GIT_AHEAD="$Y^"
40
40:48d26a4c35ba Ahead/behind commit count.
Anton Shestakov <engored@ya.ru>
previous changes: 39:06ada8ea9a31
line | diff
[[ $GIT_STATUS =~ ahead[^$'\n']+([0-9]+)' 'commit ]] && GIT_AHEAD+=${BASH_REMATCH[1]}
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
fi
34
34:6d42e8d89e7e .bash_prompt: replace grep with "string contains" bashism.
Anton Shestakov <engored@ya.ru>
previous changes: 33:b0de9677e28d
line | diff
if [[ $GIT_STATUS == *'Changes to be committed'* ]]; then
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
local GIT_STAGED="$R!"
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
fi
34
34:6d42e8d89e7e .bash_prompt: replace grep with "string contains" bashism.
Anton Shestakov <engored@ya.ru>
previous changes: 33:b0de9677e28d
line | diff
if [[ $GIT_STATUS == *'Changes not staged'* ]]; then
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
local GIT_UNSTAGED="$P?"
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
fi
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
39
39:06ada8ea9a31 Behind and ahead of branches in git.
Anton Shestakov <engored@ya.ru>
previous changes: 38:aeaac3ebe25e
line | diff
local GIT_INFO=" ${G}${GIT_BRANCH}±${GIT_REV}${GIT_BEHIND}${GIT_AHEAD}${GIT_STAGED}${GIT_UNSTAGED}${RESET}"
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
fi
0
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
fi
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
if [[ $VIRTUAL_ENV ]] ; then
5
5:7b2ad8123a53 virtualenv support.
Anton Shestakov <engored@ya.ru>
previous changes: 3:cb307dcaf2ef
line | diff
local VENV="${G}+"$(basename "$VIRTUAL_ENV")"${RESET}"
5:7b2ad8123a53 virtualenv support.
Anton Shestakov <engored@ya.ru>
previous changes: 3:cb307dcaf2ef
line | diff
fi
5:7b2ad8123a53 virtualenv support.
Anton Shestakov <engored@ya.ru>
previous changes: 3:cb307dcaf2ef
line | diff
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
if [[ $RETURN_CODE != 0 ]] ; then
5
5:7b2ad8123a53 virtualenv support.
Anton Shestakov <engored@ya.ru>
previous changes: 3:cb307dcaf2ef
line | diff
local RETCODE="${R}${RETURN_CODE}${RESET} "
0
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
fi
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
PS1="\
5
5:7b2ad8123a53 virtualenv support.
Anton Shestakov <engored@ya.ru>
previous changes: 3:cb307dcaf2ef
line | diff
${BOLD}[${TIME} \u@\h \
7
7:d3613e95e03f Git info. Git and Mercurial symbols (credit goes to Steve Losh and his extravagant zsh prompt).
Anton Shestakov <engored@ya.ru>
previous changes: 5:7b2ad8123a53
line | diff
${RETCODE}\W${VENV}${HG_INFO}${GIT_INFO}${BOLD}]\
0
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
${PROMPT_COLOR}\\\$${RESET} "
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
}
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
35
35:44a6ddc7f222 Unlocal colors, lose double quotes where not needed.
Anton Shestakov <engored@ya.ru>
previous changes: 34:6d42e8d89e7e
line | diff
export VIRTUAL_ENV_DISABLE_PROMPT=1
0
0:226664158c55 Added .bashrc with hg prompt example.
Anton Shestakov <engored@ya.ru>
previous changes:
line | diff
export PROMPT_COMMAND=prompt_command