Skip to content

Commit fef9ed9

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 a808f79 commit fef9ed9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

contrib/osc-prompt.sh

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

0 commit comments

Comments
 (0)