microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.71k stars 1.4k forks source link

Allow non-codespaces bash prompt in .bashrc in common*.sh scripts #1196

Open brian-finisher opened 2 years ago

brian-finisher commented 2 years ago

The common-debian.sh and other common-*.sh script sets up a custom bash and zsh prompt (__bash_prompt) which executes a number of git commands to generate the PS1 prompt.

In our use case, in addition to running the dev container within vscode, we also run this development container on an embedded device which, for whatever reason (perhaps no internet access or permissions issues?), these commands fail, causing the prompt to hang and requiring us to hit Ctrl-C to get back to a prompt after every command execution. While clever, the breakage isn't worth showing git information in the prompt.

Other than setting RC_SNIPPET_ALREADY_ADDED=true before running the script (which would skip adding another rc_snippet) there's not a way to customize the prompt or simply not write the prompt snippet. Ideally, this would be an command line argument to the script.

Relates to:

Chuxel commented 2 years ago

You can disable this part of the prompt by adding a git setting. The same model is used by Oh My Zsh! and works with zsh based one.

git config codespaces-theme.hide-status 1

You can also apply it globally, but this would survive a "rebuild" event.

https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/common.md#speeding-up-the-command-prompt-in-large-repositories

Chuxel commented 2 years ago

Also note that this is in the user ~/.bashrc so you can modify it or remove it. If you have dotfiles setup, you can automatically overwrite it with your preferences.

If you want to automate that as a part of a Dockerfile, this is a one liner:

RUN sed -i 's/__bash_prompt//' /home/vscode/.bashrc

Adjust /home/vscode based on the username for the particular image you are using. The same general thing can be done for ~/.zshrc to change the Oh My Zsh theme.

davetapley commented 1 year ago

@Chuxel would you accept a PR to omit the userpart similar to how codespaces-theme.hide-status can be used to hide gitbranch? https://github.com/microsoft/vscode-dev-containers/blob/d2d7419316156d2cb78e2b77dc194af2adc9fdd6/container-templates/docker-compose/.devcontainer/library-scripts/common-debian.sh#L303-L307


As an aside: I'm not actually sure what the use case for showing username is really? It looks like it came in here: https://github.com/microsoft/vscode-dev-containers/blob/e1c56beb90f65d6caff6b33e02c291ef54087ce2/containers/codespaces-linux/.devcontainer/library-scripts/common-debian.sh#L185-L193

I get that current user in the prompt makes sense if you're doing sysadmin stuff, but I wonder is it actually necessary in the context of a devcontainer prompt, being a single purpose and isolated development environment by design?


Ref for myself as part of my quest to free up space on the prompt: https://github.com/orgs/community/discussions/11923#discussioncomment-4347853

Chuxel commented 1 year ago

@davetapley We've migrated script content into Features at the devcontainer/features repo and it is getting some refactoring to support additional OS's. https://github.com/devcontainers/features/pull/326

Part of this adds the ability to enable or disable the "dirty" flag. In concept this could be added the same way as long as it doesn't have a perf impact.