jD91mZM2 / powerline-rs

GitLab: https://gitlab.com/jD91mZM2/powerline-rs
MIT License
117 stars 22 forks source link

--rtl option - print modules from right to left #19

Closed lafleurdeboum closed 3 years ago

lafleurdeboum commented 3 years ago

Hello ! You mentioned on powerline-rs's README that pull requests would be welcome, and I noticed that its github code had been updated more recently than its gitlab counterpart, so here I come with my PR.

This adds an --rtl option to powerline-rs, letting it print modules from right to left. While this should be usable for languages that work this way, I personally added this behaviour because I use it with zsh's RPROMPT option. See this screenshot : powerline-rs--rtl

BTW my .zshrc extract looks like this :

# Remove the trailing space in RPROMPT. Used for compatibility with older terminals that would span a newline.
ZLE_RPROMPT_INDENT=0

pw_prompt() {
    PROMPT="$(powerline-rs --shell zsh --cwd-max-depth 2 --theme ~/.config/powerline-rs/tweaks.theme --modules host,cwd,root $?)"
    RPROMPT="$(powerline-rs --rtl --shell zsh --theme ~/.config/powerline-rs/tweaks.theme --modules git,gitstage)"
    # Jump back to cwd on new vte-terminal open :
    if test "$VTE_VERSION" && test -x /usr/lib/vte-urlencode-cwd; then
        printf "\033]7;file://%s%s\033\\" "${HOST}" "$(/usr/lib/vte-urlencode-cwd)"
    fi
}
if $(which powerline-rs); then
    precmd_functions+=(pw_prompt)
fi

Hope you like this contribution ! I think it could be taken even further by letting the cwd module also print from right to left when called ; I guess it wouldn't do it magically :) Tell me if you are interested, I could certainly implement that.

Regards,

la Fleur