nutools/lib/profile.d/bash_prompt.shared

196 lines
5.3 KiB
Bash
Raw Permalink Normal View History

2013-08-27 15:14:44 +04:00
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
if [ -n "$UTOOLS_BASH_PROMPT" ]; then
# PS1
if [ "$UNAME_SYSTEM" != "Linux" -o "$USER" == "$(id -un)" ]; then
DEFAULT_PS1='\u@\h \w \$ '
else
DEFAULT_PS1="$USER"'(\u)@\h \w \$ '
fi
if [ -z "$UTOOLS_CHROOT" ]; then
if [ -n "$debian_chroot" ]; then
UTOOLS_CHROOT="$debian_chroot"
elif [ -r /etc/debian_chroot ]; then
UTOOLS_CHROOT="$(</etc/debian_chroot)"
fi
fi
2013-08-27 15:14:44 +04:00
if [ "$UTOOLS_CHROOT" == "1" ]; then
DEFAULT_PS1="[CHROOT] $DEFAULT_PS1"
elif [ -n "$UTOOLS_CHROOT" ]; then
DEFAULT_PS1="[CHROOT:$UTOOLS_CHROOT] $DEFAULT_PS1"
fi
GENERATE_PS1='function __genps1() {
2018-02-01 14:56:00 +04:00
local cvs svn git pff uinst woinst suffix p="$PWD"
if [ -n "$UTOOLS_AUTO" ]; then
2013-08-27 15:14:44 +04:00
PS1=
2018-11-12 16:36:58 +04:00
if [ "$DOCKER_MACHINE_WRAPPED" == true -a -n "$DOCKER_MACHINE_NAME" ]; then
PS1="DK-|$DOCKER_MACHINE_NAME|"
fi
2013-08-27 15:14:44 +04:00
while [ "$p" != "$HOME" -a "$p" != "" ]; do
if [ -z "$cvs" -a -d "$p/CVS" ]; then
PS1="${PS1:+$PS1,}cvs$suffix"
cvs=1
fi
if [ -z "$svn" -a -d "$p/.svn" ]; then
if [ "$UTOOLS_AUTO" != "f" ]; then
2013-08-27 15:14:44 +04:00
flag="?svn"
elif [ -n "$(svn status -q --ignore-externals 2>/dev/null)" ]; then
flag="*svn"
else
flag="svn"
fi
PS1="${PS1:+$PS1,}$flag$suffix"
svn=1
fi
if [ -z "$git" -a -d "$p/.git" ]; then
if [ "$UTOOLS_AUTO" != "f" ]; then
2013-08-27 15:14:44 +04:00
flag="?git"
elif [ -n "$(git status -s 2>/dev/null)" ]; then
flag="*git"
else
flag="git"
fi
2014-01-27 18:15:41 +04:00
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
[ "$branch" != "master" ] && flag="$flag:$branch"
if [ -n "$UTOOLS_VCS_OFFLINE" ]; then
flag="$flag,offline"
2013-08-27 15:14:44 +04:00
fi
PS1="${PS1:+$PS1,}$flag"
git=1
fi
2018-02-01 14:56:00 +04:00
if [ -z "$pff" -a -d "$p/pff" -a -f "$p/.pff.conf" ]; then
flag=pff
if [ -L "$p/pff/.Current" ]; then
2018-04-17 17:01:52 +04:00
flag="$flag$(source "$p/.pff.conf" 2>/dev/null; echo "${VERSION:+:$VERSION}"):$(readlink "$p/pff/.Current")"
2018-02-01 14:56:00 +04:00
fi
PS1="${PS1:+$PS1,}$flag"
pff=1
fi
2013-08-27 15:14:44 +04:00
if [ -z "$uinst" ]; then
if [ -f "$p/.uinst.conf" ]; then
PS1="${PS1:+$PS1,}uinst$suffix"
uinst=1
fi
if [ -f "$p/.udir" ]; then
if grep -q "^udir_types=.*uinst" "$p/.udir"; then
PS1="${PS1:+$PS1,}uinst$suffix"
uinst=1
fi
fi
fi
if [ -z "$woinst" ]; then
if [[ "${p##*/}" == *.framework ]]; then
PS1="${PS1:+$PS1,}woinst$suffix"
woinst=1
fi
if [[ "${p##*/}" == *.woa ]]; then
PS1="${PS1:+$PS1,}woinst$suffix"
woinst=1
fi
fi
suffix="/..."; p="${p%/*}"
done
PS1="${PS1:+[$PS1] }$DEFAULT_PS1"
else
PS1="$DEFAULT_PS1"
fi
}; __genps1; unset -f __genps1'
# PROMPT_COMMAND
if [ "$UNAME_SYSTEM" == "Darwin" ]; then
# Cas particuliers
[ "$TERM" == "vt100" ] && TERM=xterm
fi
case "$TERM" in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND='
if [ -n "$UTOOLS_AUTO" ]; then
2013-08-27 15:14:44 +04:00
echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~} $(
if [ -f build.properties ]; then
if grep -q "^project\(_\|\.\)name=" build.properties; then
if grep -q "^project\.name=" build.properties; then
echo -n "[$(sed -ne "/^project\.name=/{s/^project\.name=//
p
}" build.properties)"
elif grep -q "^project_name=" build.properties; then
echo -n "[$(sed -ne "/^project_name=/{s/^project_name=//
p
}" build.properties)"
fi
if [ -f VERSION.txt ]; then
echo -n "-$(sed -ne "1{s/-r.*\$//
p
}" VERSION.txt)"
fi
echo -n "]"
fi
fi)\007"
fi
eval "$GENERATE_PS1"
'
;;
2018-12-08 11:57:53 +04:00
screen*)
2013-08-27 15:14:44 +04:00
PROMPT_COMMAND='
if [ -n "$UTOOLS_AUTO" ]; then
2013-08-27 15:14:44 +04:00
echo -ne "\033_[screen] ${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~} $(if [ -f build.properties ]; then
if grep -q "^project\(_\|\.\)name=" build.properties; then
if grep -q "^project\.name=" build.properties; then
echo -n "[$(sed -ne "/^project\.name=/{s/^project\.name=//
p
}" build.properties)"
elif grep -q "^project_name=" build.properties; then
echo -n "[$(sed -ne "/^project_name=/{s/^project_name=//
p
}" build.properties)"
fi
if [ -f VERSION.txt ]; then
echo -n "-$(sed -ne "1{s/-r.*\$//
p
}" VERSION.txt)"
fi
echo -n "]"
fi
fi)\033\\"
fi
eval "$GENERATE_PS1"
'
;;
*)
PROMPT_COMMAND='
if [ -n "$UTOOLS_AUTO" ]; then
2013-08-27 15:14:44 +04:00
if [ -f build.properties ]; then
if grep -q "^project\(_\|\.\)name=" build.properties; then
if grep -q "^project\.name=" build.properties; then
echo -n "\033[34m[$(sed -ne "/^project\.name=/{s/^project\.name=//
p
}" build.properties)"
elif grep -q "^project_name=" build.properties; then
echo -n "\033[34m[$(sed -ne "/^project_name=/{s/^project_name=//
p
}" build.properties)"
fi
if [ -f VERSION.txt ]; then
echo -n "-$(sed -ne "1{s/-r.*\$//
p
}" VERSION.txt)"
fi
echo -e "]\033[0m"
fi
fi
fi
eval "$GENERATE_PS1"
'
;;
esac
UDIR_VISITED_DIRS=:
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND
}"'if [ -f .udir -a "${UDIR_VISITED_DIRS//:$PWD:/}" == "$UDIR_VISITED_DIRS" ]; then
udir --show-note
UDIR_VISITED_DIRS="$UDIR_VISITED_DIRS$PWD:"
fi'
export PS1 DEFAULT_PS1 GENERATE_PS1 PROMPT_COMMAND UDIR_VISITED_DIRS
fi