From: Elan Ruusamäe Date: Sat, 9 Jan 2016 15:54:55 +0000 (+0200) Subject: include current VERSION from spec in PS1 X-Git-Tag: auto/th/rpm-build-tools-4.8-3~8 X-Git-Url: https://git.pld-linux.org/?a=commitdiff_plain;ds=sidebyside;h=4299a37c54933882ebe40d95637c361aa18d3d95;p=packages%2Frpm-build-tools.git include current VERSION from spec in PS1 --- diff --git a/shrc.sh b/shrc.sh index 05ec24c..d0f91f7 100755 --- a/shrc.sh +++ b/shrc.sh @@ -286,7 +286,8 @@ __bash_prompt_command() { local LIGHT_GRAY="\[\033[0;37m\]" local COLOR_NONE="\[\e[0m\]" - local prompt="${BLUE}[${RED}\w${GREEN}$(__bash_parse_git_branch)${BLUE}]${COLOR_NONE} " + local rpmver=$(__package_rpmversion) + local prompt="${BLUE}[${RED}\w${GREEN}${rpmver:+($rpmver)}$(parse_git_branch)${BLUE}]${COLOR_NONE} " if [ $previous_return_value -eq 0 ]; then PS1="${prompt}➔ " else @@ -331,3 +332,11 @@ __bash_parse_git_branch() { echo " (${branch})${remote}${state}" fi } + +# if we are in rpm subdir and have exactly one .spec in the dir, include package version +__package_rpmversion() { + if [[ $PWD =~ $(rpm -E %_topdir) ]] && [ "$(echo *.spec | wc -w)" = 1 ]; then + # give only first version (ignore subpackages) + rpm --specfile *.spec -q --qf '%{VERSION}\n' | head -n1 + fi +}