Skip to content

Commit 3714792

Browse files
committed
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: openSUSE#1379
1 parent f8a9c93 commit 3714792

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

contrib/osc-prompt.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
__osc_prompt() {
4+
# Git has a precedence
5+
if [ -d .git ] ; then
6+
# Test for the existence of bash function
7+
declare -F __git_ps1 >/dev/null && printf "%s" "$(__git_ps1 "$@")"
8+
return
9+
fi
10+
# Are we even in the OSC checkout?
11+
[ -d .osc ] || return
12+
13+
local osc_binary osc_pattern osc_str;
14+
osc_binary=$(type -p osc)
15+
if [ -n "$1" ] ; then osc_pattern="${*}" ; else osc_pattern="(%s)" ; fi
16+
if [ -n "$osc_binary" ] && [ -x "$osc_binary" ] && [ -f .osc/_package ] ; then
17+
osc_str="$(osc status 2>/dev/null |cut -d' ' -f 1|sort|uniq -c|tr -d ' \n')"
18+
# shellcheck disable=SC2059
19+
printf " ${osc_pattern}" "$osc_str"
20+
fi
21+
}

0 commit comments

Comments
 (0)