As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label PS1. Show all posts

Have you ever done this?


git status

on a Mercurial repo and stared at the error message for a couple of seconds?

I had seen some PS1 with repo information and I thought it’s time for adding that to my Bash loadable Vim-like PS1.

I found a great project called vcprompt, which supports Git, Mercurial, Subversion, CVS, and Fossil. I only need the first two actually. It is fast and that is the point of why I chose to use this.

If your PS1 is Bash script based (I probably am the only one whose PS1 is written in C code on Earth), then you can use:


__git_ps1
hg branch

to get the current branch name. The first one (a Bash function) comes with Bash completion and it runs in reasonably fast speed, but Mercurial command isn’t that fast. I was giving up when I realized it would take almost one second for first run on a directory, then I saw vcprompt.

Not only it is fast but also I can have multiple VCS support at the same time with customizable output format, it is awesome. The only issue is I needed to re-code my PS1 C code because the position of the output of vcprompt.

However, it could be an advantage if I include vcprompt’s code in my C code. I made these changes and this is what my PS1 looks now:

http://farm8.staticflickr.com/7191/6820798790_e359d3b132_z.jpg

Prompt with VCS status information

A year ago, I didn't even know you can write a C code for Bash extension. Yesterday, I stumbled on Using and Writing Bash Dynamically Loadable Built-In Commands and I knew I could do something with this new discovery.

So, I wrote a C code for replacing my Bash version script. The speed is only three times fast, I am so disappointed I expected much faster. Anyway, it's really hardly can gain much from improving PS1, it's not as if your PS1 is required to update 1000 times per second.

You can go check some loadable builtins comes with Bash, they should be installed at /usr/lib[64]/bash/. Use enable <name> to enable and to disable with -d.

If you want to develop your own builtin, you will need to download the Bash source code. I doubt any distro will install header files of Bash for you. A basic ./configure is needed to generate necessary header files and also you will need to run make pathnames.h for that header at least.