215 points · by jonisalonen · 14y ago · 131 comments
The simpler fix is just to notice that your prompt has shifted over (it's almost impossible not to notice) and just hit return before doing anything.
zsh prompt:
PROMPT='
%{$prompt_default_color%} %~ %* %{${fg[$prompt_user]}%}%n%{$prompt_default_color%}@%{${fg[$prompt_host]}%}%M%{$prompt_default_color%} ${vcs_info_msg_0_}_
$ %{${fg[default]}%}'
Bash has come a long way since then and it's just a "brew install bash" away. There's absolutely no good reason to stick with the version that ships with OSX for your personal shell.
I'm not sure which zsh OSX ships with, but it should be much more up to date since it uses a BSD-like license.
Part of this is because I try to automate anything I do more than once or twice and I use a real language to do so. For anything non-trivial the differences between zsh and bash are an order of magnitude less significant than either compared with Python, Ruby, etc.
In brief, bash, like mysql (or Windows) is always there. Most people know how to use bash and wouldn't notice any difference by switching (except for a possible unnecessary learning curve).
Lets turn it around. Assuming (and a big assumption) that zsh is more powerful, why does this matter to someone who probably spends most of their time at a terminal thinking and puts anything half way repetitive into a script? Its like telling a carpenter than a brand X chisel is more powerful than a brand Y chisel.
Show me how a skilled zsh user is 'more powerful' than a skilled bash user at anything that matters. Perhap some people spend too much time typing and not enough time thinking.
Power beyond need or capability is complexity (the bad kind).
cout >> "Hello world"; // with no endl.
Prepending the prompt with a new line might be a better idea than over-writing the current line. [\[\033[1;32m\]\D{%Y-%m-%d %H:%M:%S}\[\033[0m\]] \[\033[1;32m\]\u\[\033[0m\]\[\033[1;32m\]@\h\[\033[0m\]:\[\033[1;36m\]\w\[\033[0m\]\n#
It's actually dynamically generated by my .bashrc so that different servers have different colors; at a glance, I can generally tell whether I'm on one of my machines, or on a work build server, or an amazon ec2 instance. PS1="\[\e[32;1m\]\[\e[37;1m\]\`if [ \$? = 0 ]; then echo \[\e[33m\] :\)\[\e[0m\]; else echo \[\e[31m\] X\(\[\e[0m\]; fi\`\[\e[32;1m\] \[\e[32;1m\](\[\e[37;1m\]\h:\u\[\e[32;1m\])-(\[\e[37;1m\]\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n\[\e[0m\]"
Here's how it appears: :) (seas456:narayana)-(0)-(~/personal)
[this line is where your cursor blinks; notice no symbol at the start of this line]
You can't see the colors here. The smiley face turns into a bright red frowny face if the exit code of the last job is nonzero.https://github.com/dylanahsmith/dotfiles/blob/master/.config...
This does break if the terminal has auto wrap turned off (echo -e "\033[?7l"), but otherwise it's very clever.
specifically your function just sort of sits there doing nothing when i try it....
rpatterson@rpatterson-tba 04/27/2012 01:24 PM ~
$
This gives me a full row to type a command, and lets me see how long ago the last command finished. Each of those components is bold and colored differently. [prakash@kaveri 16:39:05 ~ :) ]
>> sleep 10
^C
[prakash@kaveri 16:39:18 ~ :( ] PS1="\[\033[G\]$PS1"
instead of $PS1="\[\033[G\]$PS1"A) When I hit ^C, I am always seeing a newline occur after the ^C and before my prompt is redrawn. I have tried this with cat (blocked on read) and ssh (blocked on password).
B) When I purposely attempt to cause this (using echo -n and interpreting "a very long command" to mean "long enough that it wrapped to the next line"), hitting up redraws and overwrites part of the prompt in order to guarantee that the position of the prompt will edit correctly.
But terminal corruption used to be far more common (line noise, etc...) and bash has a built-in escape for this. Ctrl-L (chosen for the analogy with form-feed/"vertical tab" on a printer) will blank the screen and redraw your current edit environment at the top.
BTW, it's the readline library that handles the Ctrl-L key binding to clear the screen rather than bash per se.
$ bind -p | grep '\\C-l'
"\C-l": clear-screen
$It doesn't really help me "maximise my processor usage" I find.
Do I have this right?
the path to "user-friendly" shell nirvana (i.e. interactive use, not scripts) can be achieved through use of a library like editline, without installing a huge, "kitchen sink" package like zsh... if size is an issue. make the shell cmd line behave like the editor you know well.
But the first $ is wrong, it should read PS1="\[\033[G\]$PS1"
PS1='\['"$(tput cr)$(tput ed)"'\]$ '
is better since it clears to the end of the screen, e.g. try seq 1000 | fmt; tput cup 10 20
with and without it.But the thing is, with either that approach or the one in the article, you're wiping out what may be useful; that unfinished line causing PS1 to be pushed along may have vital data on it, data that's hard to re-create.
Worth double-checking, anyway. I've occasionally pondered some sort of prompt-lint/validator given the reams of dubious examples out there, and problems people face when customising their own.
turns out i'm willing to tolerate a lot of pain to have emacs operations in a shell buffer, haha
As far as colors go, shell mode does its own highlighting. I used to have problems with ANSI code colors, but they have been working properly recently. (I just tried ls --color=always which worked as expected, unexpectedly.)
Which version of Emacs are you on?
Note that this is all without any configuration. The only thing I did was add a command for opening a new shell in the current directory which turned out to be extremely useful. It even works for remote files, so now I use shell mode for almost everything.
(one of the readline features i rediscover every three months or so and promptly forget)
$if lisp
set comment-begin ;
M-;: insert-comment
$endifI set mine to standard for successful output "[user@host:truncated path]$ ".
Having my shell smile at me all the time makes me think it's up to something.
export PS1="\n\W\$(parse_git_branch) $ "
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'; }Is there any way of getting bash to only output a '\n' if the cursor isn't already at the start of a line?
$ echo -n foo bar
zob ~ ⚡ cat
^C zob ~ ⚡
default bash settings real termina, like xterm this is bash of course.
and its better than ^C is not erased.
saurik ~ ö bob
saurik ~ ö cat
^C
saurik ~ öthe lightning bolt is just an utf8 fancy char
this is my PS1 if you like it: \[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;33m\]⚡\[\e[m\] \[\e[1;37m\]