Skip to content

Commit

Permalink
osc prompt for Bash.
Browse files Browse the repository at this point in the history
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: #1379
  • Loading branch information
mcepl committed Oct 23, 2024
1 parent 4ccb00b commit 9590683
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contrib/osc-prompt.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9590683

Please sign in to comment.