Dynamic Bash Shell Prompt (dash)

So it’s been a busy year this year and I haven’t gotten a chance to post much on the good old blog here but I wanted create something that provided me with more dynamically updating information in my bash shell. It’s just a demo and work in progress but it launches 2 bash shell processes (one for the updated PS1 information and the other for the interactive login). It tries to detect your default PS1 format based on a simple regex which can be changed and modified based on your formatting and needs. You’ll also need to write a shell script to place inside the PS1 prompt which gathers the dynamic info you are interested in for your own shell. This can allow you to automatically update and display all sorts of information without needing to type anything out! For example: hostname, LAN/WAN IP, WiFi channel/speed, date/time, weather information, etc. Small demo video below!

Edit: I found another wordpress blog that has posted about a “more-official/proper” way to run an interactive shell with a pty fork/spawn that may be worth incorporating here: https://sqizit.bartletts.id.au/2011/02/14/pseudo-terminals-in-python/

Proof-Of-Concept Code (DASH)

Update: So I’ve tried to incorporate the code from the blog site above into a newer version of this hacky-dynamic-interactive-bash-shell python script, now placed in a dedicated repository: https://github.com/stoops/dash/

One thought on “Dynamic Bash Shell Prompt (dash)

  1. I would be very careful with this. While I also customize prompt to have a time, current directory an new line character, it is easy to lock Yourself out. For example, bash is not always in /bin. On distros like Nix it could be anywhere. It is better to check env variables, theu usually know where to find shell executables.

Leave a comment