Bash - Powerline-Go
In some previous articles, we covered the GNU/Bash and adjusted it to our liking. But you can do even more. Powerline-Go is an awesome way to make your GNU/Bash prompt more useful and beautiful.
In some previous articles, we covered the GNU/Bash and adjusted it to our liking. But you can do even more. Powerline-Go is an awesome way to make your GNU/Bash prompt more useful and beautiful.
You can also check out the previous articles "Bash - Tweaks and Tuning" and "Bash - Prompt and Colors" beforehand or afterwards.
Powerline-Go
Powerline is/was a piece of software to decorate your VIM status line and make it more usable. It was very popular among heavy VIM users, and therefore people thought of implementing the same for the Shell prompt. Powerline-Shell was born. But Powerline-Shell was becoming slow and quite bloated. For me, waiting for the prompt was not a desired thing.
The Powerline-Go developers were having the same problem and implemented an alternative to Powerline-Shell in the Go programming language. You are getting Powerline-Shell, but faster. But, what does that mean?
Well, Powerline-Go makes your prompt to look like this:
It adds Git integration, Python VirtualEnv, showing error codes and much more to your Bash prompt. It also offers different themes and is very easy to install on Fedora.
Installation
Installing Powerline is really a piece of cake. Just run the below command, and you can start to configure it.
# Install Powerline Go
$ sudo dnf install powerline-go
Configuration
Enabling and configuring Powerline-Go for GNU/Bash is also quite simple. There are two major options:
Current User Only
To enable Powerline-Go for your current user only, or user-by-user, you can edit the ~/.bashrc
file. Just open it with the editor of your choice and append the below snippet to it.
This will already do the trick, and you can restart your terminal emulator or open a new tab in it to see the results.
System-Wide
If you want to enable Powerline-Go for all users on your system (including root), you can create a new file in /etc/profile.d/
. I suggest naming it z_powerline.sh
, since it will be at the very end, and you can ensure no other script is overriding it here. There is no need to apply the "Current User Only" part from above.
Starting a new terminal or opening a new tab will already show you the new prompt. If you change to root via sudo -i
, you will also see the new prompt for root.
Configuring
Now that the Powerline-Go prompt is enabled, you can also tune and tweak it to your liking. This is done by adjusting the arguments of this line: PS1=$("${GOPATH}"/bin/powerline-go -error $? -cwd-max-depth 3 -hostname-only-if-ssh -jobs "$(jobs -p | wc -l)")
. Just add, change and remove arguments that you need. You can find a nice overview of all supported arguments in the Powerline-Go repository.
I for example, do like the -hostname-only-if-ssh
option, which does not show the hostname unless, I am connected to the host via SSH. Another cool option is the -theme THEME
option. This can be used to tune the colors of the prompt.
You can also adjust how the Git indicator for repositories is displayed or how your Python Virtual Environment is looking. There are lots of options to make it your own.
More Powerline?
If you like the powerline-look, you may be interested in more cool status lines and prompts. In the past, I was using some of the below and address these in another article in more details.
- https://github.com/vim-airline/vim-airline
- https://github.com/erikw/tmux-powerline
- https://github.com/b-ryan/powerline-shell
For now, have fun by checking them out on your own.
Docs & Links
The Linux community is putting lots of love in the Shell prompts. I have gathered some additional articles and documentation, that may be interesting for you.
Conclusion
I assume that was my last "Bash - Prompt" article for now. But, we will have a look at Bash scripting and some more customization soon.
Please let me know, how you tuned your Bash prompt and maybe post a screenshot how it is looking like. I would love to get in touch via Twitter, Mastodon or Mail.