Open jovanbulck opened 10 years ago
See also https://wiki.gentoo.org/wiki/Zsh/HOWTO#Prompts for an example of how it's done in zsh...
Updated feature requests:
jsh-common.h
for UNIX tty color escape code definitions && jsh-common.c
|| mini-grep.c
for example uses.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
Good work! Elegant solution for the smart truncation :-)
Some thoughts:
NULL
instead of 0´ in the check
(ptr != 0)`else
block the i++
can be illegal: when the user supplied strings ends in a single '%' this will result in a buffer overread (although harmless: the \0
char), I thinksnprintf
), instead of printing one on stdout with printf
. As you'll see this messes readline
up when using the history arrows....Status update:
Done:
prompt
built_in that can be used to set the custom prompt (e.g. in the jshrc
file)getprompt()
function with %char
interpretation and smart truncation of the directory (thanks @KevinMordijck )See first comment for a full list of things todo --> more ideas --> shout here...
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):
zsh
) codezsh
project to bash
and fish
; porting it to jsh
is probably impossible, but we can maybe re-use some of the script to get the output right...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
.
Other ideas for special symbols in user_prompt_string:
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.
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...
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
@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 .
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:
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
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}"
Awesome, and yes, I do like the #
/ $
thing!
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.
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...
should be stable; merged in master Check it out at work:
Share your thoughts ;-)
prompt expansion options are fully documented in the man
page. Short summary below:
Allow a custom prompt. Things todo:
prompt "user defined prompt string"
built_in shell commandchar* getprompt(int status)
function injsh.c
char* getprompt(int status, char *user_prompt_string)
%l max_value
?) for the cur directory and truncating it to min{curdir, max_value} and if truncated -> delete the beginning of the string until the first '/'Updated todo list:
Todo for release 1.0:
CustomizingPrompt
MAX_DIR_LENGTH
. This should be user definable, maybe in the prompt string (as in zsh) or using yet another built_inset
or so? Note theMAX_PROMPT_LENGTH
can remain hardcoded as we always need a (reasonable) limit for the prompt. When a user tries to set a prompt of more then 100 chars, he's probably hacking :pTodo for future releases:
#
when sudo is activated~
git
support (would be really cool ;-) )