From 95906836083fcc01106ed7b63f3102e05db81183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Thu, 10 Aug 2023 08:45:55 +0200 Subject: [PATCH 1/2] osc prompt for Bash. Equivalent of `__git_ps1` for git. Suggested use: # Prompt for osc [[ -f /usr/share/bash-completion/completions/osc-prompt.sh ]] && \ source /usr/share/bash-completion/completions/osc-prompt.sh export PS1='\h:\W$(__osc_prompt) \$ ' Fixes: https://github.com/openSUSE/osc/issues/1379 --- contrib/osc-prompt.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 contrib/osc-prompt.sh diff --git a/contrib/osc-prompt.sh b/contrib/osc-prompt.sh new file mode 100644 index 000000000..8d8b63075 --- /dev/null +++ b/contrib/osc-prompt.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +__osc_prompt() { + # Git has a precedence + if [ -d .git ] ; then + # Test for the existence of bash function + declare -F __git_ps1 >/dev/null && printf "%s" "$(__git_ps1 "$@")" + return + fi + # Are we even in the OSC checkout? + [ -d .osc ] || return + + local osc_binary osc_pattern osc_str; + osc_binary=$(type -p osc) + if [ -n "$1" ] ; then osc_pattern="${*}" ; else osc_pattern="(%s)" ; fi + if [ -n "$osc_binary" ] && [ -x "$osc_binary" ] && [ -f .osc/_package ] ; then + osc_str="$(osc status 2>/dev/null |cut -d' ' -f 1|sort|uniq -c|tr -d ' \n')" + # shellcheck disable=SC2059 + printf " ${osc_pattern}" "$osc_str" + fi +} From 294001c46ea22fc39dfa739a6b9a388e8fccfad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Thu, 24 Oct 2024 16:24:18 +0200 Subject: [PATCH 2/2] fix[osc-prompt]: correctly check for being inside of git checkout Unfortunately, it breaks git-prompt.sh, so it was a bitch to debug. --- contrib/osc-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/osc-prompt.sh b/contrib/osc-prompt.sh index 8d8b63075..9cb9b4bdd 100644 --- a/contrib/osc-prompt.sh +++ b/contrib/osc-prompt.sh @@ -2,7 +2,7 @@ __osc_prompt() { # Git has a precedence - if [ -d .git ] ; then + if git rev-parse --quiet --git-dir >/dev/null 2>&1 ; then # Test for the existence of bash function declare -F __git_ps1 >/dev/null && printf "%s" "$(__git_ps1 "$@")" return