warpdotdev / Warp

Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.
https://warp.dev
Other
21.34k stars 372 forks source link

Custom prompt text (PS1) also becomes the command, preventing using commands #2516

Open mieubrisse opened 1 year ago

mieubrisse commented 1 year ago

Discord username (optional)

No response

Describe the bug

I have a custom Bash prompt like so:

function __prompt_command() {
    local LAST_EXIT_CODE="${?}"

    # Regular ASCII colors
    # NOTE: The wrapping \[ and \] are necessary so Bash can  correctly calculate the size
    #  of the prompt:
    # https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Terminfo_escape_sequences
    local RESET_COLOR="\[$(tput sgr0)\]"
    local BOLD="\[$(tput bold)\]"

    # Sexy 256-color colors
    # local SXY_DIR_FORE='\[\e[38;5;94m\]'
    # local LIGHT_GREY_BLUE=110
    local light_grey=243
    local dark_grey=236
    local very_dark_grey=235
    local very2_dark_grey=234
    local red=124
    local dark_red=88
    # local green=76
    local algae_green=76
    local orange=214
    local brightish_red=160
    local grey_blue=110
    local sky_blue=117
    # local off_white=256
    local white=255

    # local timestamp_color="$(__get_color fore ${light_grey})"
    local timestamp_color="\[\e[38;5;${light_grey}m\]"

    # Change the color of the command text based on which machine I'm working on - personal or work
    if [ "${MACHINE_CONTEXT}" == "WORK" ]; then
        local command_color="${BOLD}\[\e[38;5;${algae_green}m\]"
    elif [ "${MACHINE_CONTEXT}" == "PERSONAL" ]; then
        local command_color="${BOLD}\[\e[38;5;${orange}m\]"
    else
        local command_color="${BOLD}\[\e[38;5;${sky_blue}m\]"
    fi

    # local dir_color="${BOLD}$(__get_color back "${very_dark_grey}")"
    # if [ ${LAST_EXIT_CODE} -ne 0 ]; then
    #     dir_color+="$(__get_color fore "${red}")"
    # fi

    local background_color="\[\e[48;5;${very_dark_grey}m\]"
    local success_dir_color="\[\e[38;5;${white}m\]"
    local failure_dir_color="\[\e[38;5;${red}m\]"
    local success_gitdir_color="\[\e[38;5;${grey_blue}m\]"
    local failure_gitdir_color="\[\e[38;5;${brightish_red}m\]"

    # Setup prompt background
    PS1="${RESET_COLOR}${background_color}"

    # Add timestamp
    PS1+="${timestamp_color} $(date +%H:%M:%S) "

    # Add working dir
    PS1+="${BOLD}"
    __render_working_dir "${LAST_EXIT_CODE}" "${success_dir_color}" "${failure_dir_color}" "${success_gitdir_color}" "${failure_gitdir_color}"
    PS1+="${retval}"

    # Add Git branch info
    __render_git_prompt
    PS1+="${retval}"

    # Clear prompt background & color command text
    PS1+=" "
    PS1+="${RESET_COLOR} ${command_color}"

    if [ "${__new_wd:=$PWD}" != "${PWD}" ]; then
        ls
        [ -d ".git" ] && command -v git >/dev/null 2>&1 && ( git fetch --prune >/dev/null 2>&1 >/dev/null & )

        # Commenting out because this randomly became ultra-slow
        # __jenv_set_java_home
    fi
    __new_wd=$PWD
}
PROMPT_COMMAND=__prompt_command

When I tell Warp to use my custom prompt command my prompt command shows up as expected (good), but it also fills the command-I'm-typing to be the contents of the prompt:

Screen Shot 2023-01-18 at 11 17 46 Screen Shot 2023-01-18 at 11 18 09

To Reproduce

Should be just add my prompt command to a .bashrc and try to use Warp

Expected behaviour

My prompt command correctly generates the prompt, and I get a clean slate for writing my command every time

Screenshots

No response

Operating System

MacOS

OS Version

12.5

Shell Version

GNU bash, version 5.2.15(1)-release (aarch64-apple-darwin21.6.0)

Warp Version

v0.2023.01.10.08.02.stable_01

Additional context

No response

Does this block you from using Warp daily?

Yes, this issue prevents me from using Warp daily.

Warp Internal (ignore): linear-label:b8107fdf-ba31-488d-b103-d271c89cac3e

None

Dx-wmc commented 1 year ago

Similar questions, warp's own PS1 does not have such a hint of time, could we customize the PS1 of warp or add a time hint?

mieubrisse commented 1 year ago

Hey @warpdotdev-dx , any chance of movement on this? I'd love to try out Warp but this "echoing my prompt as the command" bug is preventing me from doing so

dannyneira commented 1 year ago

Hi @mieubrisse < Thanks for submitting, sorry to hear about this issue. So I'm not 100% about your prompt setup, but just in case, there are a number of known issues possibly affecting your prompt ( in particular with right-sided or multi-line prompts ) see: https://docs.warp.dev/features/prompt#known-incompatibilities

As a workaround, I recommend you try a modern prompt like starship or oh-my-posh ( which does support multi-line in Warp ) See: https://docs.warp.dev/features/prompt#custom-prompt-compatibility-table

mieubrisse commented 1 year ago

Hey @dannyneira thanks for the response! Those definitely make sense on why they'd be difficult; my prompt isn't actually multiline or right-sided though - I'm just using vanilla PS1 with ANSI color codes.

dannyneira commented 1 year ago

Good point about the colors, i switched my shell to bash and tried this in my .bashrc file but wasn't able to render any prompt. I suggest trying without the colors possibly, or as I mentioned above a different prompt al together starship can do a lot of what you need and just works out of the box with multiple systems/shells.

beamery-tomht commented 1 year ago

Having the same issue on bash when trying to use on-my-posh

I also have the same issue with direnv when loading an .enrc, the output from direnv is filled into my command, where I have to manually remove it to enter any new commands

GNU bash, version 5.2.15 Warp v0.2023.02.07.08.03.stable_01

Kapture 2023-02-16 at 10 22 48

beamery-tomht commented 1 year ago

Seems related to this https://github.com/warpdotdev/Warp/issues/1142#issuecomment-1300337275

swpalmer commented 1 year ago

If Starship prompts output a message about timeouts, that output is considered part of the next command. I have to workaround selecting all and deleting before typing if one of the commands that generated the Starship prompt took too long. Very frustrating.

MadBomber commented 1 year ago

I have the same issue. My prompt is not multi-line nor does it have color in it.

I just added an issue and then searched the issues database for like minded problems. Should have done it in reverse.

I'm going to delete my duplicate issue and hope to hear a resolution here.

MadBomber commented 1 year ago

I closed my issue #2882 as a duplicate.