jovanbulck / jsh

A basic UNIX shell implementation in C
GNU General Public License v3.0
30 stars 10 forks source link

Prompt customizing #3

Open jovanbulck opened 9 years ago

jovanbulck commented 9 years ago

Allow a custom prompt. Things todo:

Updated todo list:

Todo for release 1.0:

Todo for future releases:

jovanbulck commented 9 years ago

See also https://wiki.gentoo.org/wiki/Zsh/HOWTO#Prompts for an example of how it's done in zsh...

jovanbulck commented 9 years ago

Updated feature requests:

KevinMordijck commented 9 years ago

some code is written, but I'm not sure that the current code does the intended work, some review is welcome. bufferoverflow vulnarabilities are still to be concidered

jovanbulck commented 9 years ago

Good work! Elegant solution for the smart truncation :-)

Some thoughts:

jovanbulck commented 9 years ago

Status update:

Done:

See first comment for a full list of things todo --> more ideas --> shout here...

jovanbulck commented 9 years ago

Some info on showing git info in the prompt when the current directory is a git repo (a first proof of concept won't be too hard, I think):

GijsTimmers commented 9 years ago

What's the status of the issue concerning cutting off the path until the lowest directory?

For example, I'd like this to be my prompt:

[gijs@to-therion samba]$

when I'm in the directory /var/log/samba.

GijsTimmers commented 9 years ago

Other ideas for special symbols in user_prompt_string:

GijsTimmers commented 9 years ago

Other ideas for prompt customizing:

%u gets substituted by the username. It would be pretty cool if we could make this username red and bold when the current user is root. It should look like this.

jovanbulck commented 9 years ago

For the prompt coloring: check out the syntax of zsh Apparently bash uses an ugly direct-color-escape-codes syntax, but the page contains lots of examples that can be helpful. Of course you can invent your own better and more elegant syntax, but looking at these example can be a starting point...

Something totally different: the feature-to-undo-all-other-feature-requests is probably to allow the output of any shell command to be included in the prompt. This is possible in zsh and allows really cool things :-) We should think about this...

jovanbulck commented 9 years ago

Hacked in support for user defined coloring of the prompt: check it out at master now :-)

The idea is to use %f{color_name} to turn on non-bold foreground coloring, %F{color_name} for bold/bright foreground text coloring and %b{color_name} for background coloring

e.g. prompt "%F%u%F{reset}@%F{black}%h%F{reset}[%F{cyan}%s%F{reset}]::%d%f{green}%g%f{reset}$ %F{resetall}

Also added support to show the current git branch with %g, if any

Really awesome: check it out

jsh_login_screenshot

jovanbulck commented 9 years ago

@GijsTimmers I implemented your feature request:

Other ideas for prompt customizing:

%u gets substituted by the username. It would be pretty cool if we could make this username red and bold when the current user is root. It should look like this.

Check out the branch sudo_username_red_bold. It should auto detect whether currently sudo is activated (taking into account the timestamps) and print the username red bold. As in:

screenshot from 2014-12-06 14 43 08

Looks cool :-)

Try it out and let me know if it works on your system. I have to look a bit further into it before merging in master since it uses sudo -n true and I'm not sure how portable this is (it's not older versions of sudo I think). Moreover some systems don't have sudo installed so I should detect that too. I want this to be configurable in the prompt command in jshrc too

jovanbulck commented 9 years ago

BTW: another idea/option might be to replace the prompt ending $ with a # when sudo is activated

DONE: use the %$ option in the prompt string command

e.g. prompt "%F%u%F{reset}@%F{black}%h%F{reset}[%F{cyan}%s%F{reset}]::%d%f{green}%g%f{reset}%$ %F{resetall}"

screenshot from 2014-12-06 14 54 57

GijsTimmers commented 9 years ago

Awesome, and yes, I do like the # / $ thing!

GijsTimmers commented 9 years ago

So my username will stay red as long as jsh remembers that I entered the root credentials?

I think this is a very good feature, security-wise. You kinda wonder why other shells don't do this by default.

jovanbulck commented 9 years ago

So my username will stay red as long as jsh remembers that I entered the root credentials?

I think this is a very good feature, security-wise. You kinda wonder why other shells don't do this by default.

Yes indeed, each time the prompt is refreshed, it checks whether you still have root credentials. I like it too :-)

Check out the updated man page:

%u includes the current username %U includes the current username, colored red and bold iff sudo access is activated %$ includes a '$' char or a '#' char iff sudo access is activated (usefull for the prompt ending)

I'm thinking of creating a more general prompt expansion option, something like %r{chars_to_insert_if_root_access}{chars_to_insert_otherwise} that would allow more general things.

This way a user could opt for having other prompt endings then $ and # or to have other things colored in other colors...

jovanbulck commented 9 years ago

should be stable; merged in master Check it out at work:

promtp_features

Share your thoughts ;-)

prompt customizing

prompt expansion options are fully documented in the man page. Short summary below:

git support in prompt:

technical things: