Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash prompt #1379

Open
mcepl opened this issue Aug 9, 2023 · 2 comments
Open

bash prompt #1379

mcepl opened this issue Aug 9, 2023 · 2 comments
Labels

Comments

@mcepl
Copy link
Contributor

mcepl commented Aug 9, 2023

Is your feature request related to a problem? Please describe.
When using osc as a VCS I would like to have a similar prompt indicating the status of my checkout as I have for git. With fish shell it was a trivial to add a function:

function fish_osc_prompt
    [ -d .git ] && return
    set -l osc_binary (type -p osc)
    if [ -n "$osc_binary" -a -x "$osc_binary" -a -f .osc/_package ]
        set -l osc_str (osc status 2>/dev/null |cut -d' ' -f 1|sort|uniq -c|tr -d ' \n')
        # if [ -n "$osc_str" ]
            printf ' (%s)' $osc_str
        # end
    end
end

but I don’t know how to do it with osc.

Describe the solution you'd like
Similar short snippet I would source in ~/.bashrc.

@mcepl mcepl added the Feature label Aug 9, 2023
@mcepl
Copy link
Contributor Author

mcepl commented Aug 9, 2023

Hmm, this could work:

#!/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
}

What do you think?

@dmach
Copy link
Contributor

dmach commented Apr 11, 2024

Sorry it took me so long to look into this.
It seems to be working somehow, but I'd prefer to make it faster (it adds about 1s delay before printing a new prompt line). It probably requires some work on my end to provide desired functionality from osc and do it sufficiently fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants