diff options
author | Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> | 2024-01-21 18:25:52 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-21 13:55:52 +0100 |
commit | 5ead13d6aa6303c85c562f1b940048cc539667cd (patch) | |
tree | 1188b3b4d65fb971999c30a5eb188556572a43dc /src | |
parent | 8d0d68c3f062c06872a65980b249d031cbd9bfad (diff) |
feat(bash): Support right prompt and transience (#4902)
* Support right prompt in bash
* Docs for transience in bash
* Apply suggestions from review
* Simplify conditional
* Use ble.sh hooks, if available
* Properly quote args
* Use BLE_PIPESTATUS
* Update starship.bash
* Update src/init/starship.bash
Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
---------
Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/init/starship.bash | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/init/starship.bash b/src/init/starship.bash index b7f7cb0e5..5a62be857 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -33,6 +33,9 @@ starship_preexec() { starship_precmd() { # Save the status, because commands in this pipeline will change $? STARSHIP_CMD_STATUS=$? STARSHIP_PIPE_STATUS=(${PIPESTATUS[@]}) + if [[ ${BLE_ATTACHED-} && ${#BLE_PIPESTATUS[@]} -gt 0 ]]; then + STARSHIP_PIPE_STATUS=("${BLE_PIPESTATUS[@]}") + fi if [[ "${#BP_PIPESTATUS[@]}" -gt "${#STARSHIP_PIPE_STATUS[@]}" ]]; then STARSHIP_PIPE_STATUS=(${BP_PIPESTATUS[@]}) fi @@ -64,21 +67,30 @@ starship_precmd() { eval "$_PRESERVED_PROMPT_COMMAND" + local -a ARGS=(--terminal-width="${COLUMNS}" --status="${STARSHIP_CMD_STATUS}" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="${NUM_JOBS}") # Prepare the timer data, if needed. if [[ $STARSHIP_START_TIME ]]; then STARSHIP_END_TIME=$(::STARSHIP:: time) STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME)) - PS1="$(::STARSHIP:: prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)" + ARGS+=( --cmd-duration="${STARSHIP_DURATION}") unset STARSHIP_START_TIME - else - PS1="$(::STARSHIP:: prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS")" + fi + PS1="$(::STARSHIP:: prompt "${ARGS[@]}")" + if [[ ${BLE_ATTACHED-} ]]; then + local nlns=${PS1//[!$'\n']} + bleopt prompt_rps1="$nlns$(::STARSHIP:: prompt --right "${ARGS[@]}")" fi STARSHIP_PREEXEC_READY=true # Signal that we can safely restart the timer } +# If the user appears to be using https://github.com/akinomyoga/ble.sh, +# then hook our functions into their framework. +if [[ ${BLE_VERSION-} && _ble_version -ge 400 ]]; then + blehook PREEXEC!='starship_preexec "$_"' + blehook PRECMD!='starship_precmd' # If the user appears to be using https://github.com/rcaloras/bash-preexec, # then hook our functions into their framework. -if [[ "${__bp_imported:-}" == "defined" || $preexec_functions || $precmd_functions ]]; then +elif [[ "${__bp_imported:-}" == "defined" || $preexec_functions || $precmd_functions ]]; then # bash-preexec needs a single function--wrap the args into a closure and pass starship_preexec_all(){ starship_preexec "$_"; } preexec_functions+=(starship_preexec_all) |