zsh clears previous line of prompt - zsh

I have a multi-line prompt in zsh. I've found that sometimes when I CTRL-C out of an autocompletion the previous line of the prompt gets erased unexpectedly. Here's a gif showing this happening with ls, vim and fzf: http://imgur.com/1jTrrzA
Here's an outline of events that happen:
ls all the files
ls then tab complete and CTRL-C out of the first completion (previous line of prompt gets erased)
ls then tab complete and CTRL-C out of the second completion. The previous line of the prompt doesn't get erased
same as step 2 but with vim instead
same as step 3 but I hit Enter instead of CTRL-C, this is my mistake. However, if I CTRL-C out of this example (the not-first completion) the previous line isn't erased
Show how fzf suffers from the same problem several times
I've found that the issue as shown during step 2 and step 4 still exists with a single line prompt. However fzf isn't broken with a single line prompt.
My entire prompt can be found at http://pastebin.com/JwufRy6m which is a modified version of https://github.com/sorin-ionescu/prezto/blob/master/modules/prompt/functions/prompt_sorin_setup to work with mercurial repositories at my company. The lines of interest (I think) in my prompt file are 166 and 167 (line 167 == line 166 minus $prompt_newline).
I've tried creating a multiline prompt without using $prompt_newline by doing:
NEWLINE=$'\n'
PROMPT=.....${NEWLINE}....
But that didn't help either which kinda makes sense to me because part of the problem still exists with single-line prompts.

Related

ZSH vi normal mode to move around printed text

Can I use zsh vi normal mode to move around previous commands output or the printed text in the shell to copy/yank it ?
For example in the screenshot below. I want to move to the output of ls to copy something. When I press j/k zsh cycle my command history but doesn't move up to the printed text. j/k move one line down/up only when I have multiple line command that I'm currently writing but haven't executed yet.
To the best of my knowledge, the ability to access the output of commands interactively is the domain of your terminal (-emulator), not the shell. You would use commands like sed, awk, grep, possibly in a pipe, to access, manipulate and use output you know in advance is the part you are interested in.
To access the output with keyboard shortcuts/command-keys, I suggest using the like of tmux - it allows to copy/yank from the whole terminal display as if it was a text-file in an editor.

test command is showing in green on zsh terminal

In zsh, test command is showing in green
This only happens when there is a valid binary exists for the command.
I am just curious why it is showing green for test command furthermore it is not giving any error on hitting the test command
echo $ZSH_THEME
powerlevel10k/powerlevel10k
zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)
You have a small extension (possibly part of the powerlevel10k theme) that colorizes the text on the command line. One thing it does is do progressive path lookup on the name of the command you are typing. If no command is found, the text is red. Once a valid command is found, the color becomes green.
This is independent of whether the command, when executed, succeeds or fails. test with no arguments fails, as noted by the 1x in the following prompt.

after reset-prompt,the command line jump to next line automatically

①I have tried to use an dynamic clock with time refresh settings in ~/.zshrc
TMOUT=1
TRAPALRM ()
{ zle reset-prompt }
②my full modified theme file is bullet-train.zsh-theme
my whole ~/.zshrc file is.zshrc
My problem is:
when my terminal enter into a git repository,
the command line will jump to the next line automatically.
the jump behavior is like this:
when I change the name of .git to .git__xx folder.
then jump behaviorstop
I swear that I did not press Enter,
the terminal jump to the next line automatically.
I guess it's caused by Anaconda and the time refresh settings in ~/.zshrc
The phenomenon is recorded in here
Did I press Enter deliberately and post this question to waste others' time?
No,here's the effect
if I press Enterto make command line jump to the next line
some unproper solution:
delete git part in theme file bullet-train.zsh-theme.
Then the phenomenon disappear,but the git display function is also disabled.
Could you tell me how to solve this bug?
Thanks for your help.

R command history: how to configure up-arrow to treat "multiline, brace-enclosed input" as one line?

This question is about configuring the R console to behave like a bash shell when it comes to navigating the command history. It is somewhat related to the ?history. For brace-enclosed multi-lines, I'd like to configure the command history navigation of R to be similar to bash.
Presently when running R in an xterm under Linux, using the up-arrow to navigate the command history causes each previous line to be recalled one by one, even if a set of lines had been enclosed in braces. This occurs, for example, when copy/pasting a multi-line function from a text editor into the R console. Not so with bash.
Here is an example of how bash functions in this regard:
In a bash shell within an xterm under Linux, after typing the following five lines...
a=1
{
x=1
y=1
}
... the first press of the up-arrow will recall a single line reformulation of the brace-enclosed commands, like this ...
{ x=1; y=1; }
... and the second press will recall this ...
a=1
It seems that in R, the up-arrow navigates backwards one line at a time, regardless of encapsulation. Is there a way to configure R so that it's command history navigation functions like bash's?
You could use rlwrap. I use it for other console programs and it works very well. You will need to prepend the R command with the rlwrap binary and then your history lines can be restored in a number of ways, including multi-line matching.
Workaround for Linux/Unix
Similarly as in Rstudio (thanks to Ari B. Friedman comment), where user in R console is using ShiftEnter to bypass RETURN, you can start newline (in R terminal) without accepting newline command using Ctrl-VCtrl-J. This way the multi-line command will be accepted into history as one-liner with line-feeds instead of enters and you will even have the chance to edit it. You can even manage in your .inputrc file to have custom combination for this action.
I do not think direct reconfiguration of R is possible.
Readline man page may help more.

Constantly updated clock in zsh prompt?

I know that I can exec a date command in my zsh prompt.
However, it shows the old time; to see the current time, I have to hit <return> and get a new prompt with the current time.
Is there a way to configure the zsh prompt to constantly update itself every second?
Note: I wrote this answer for a similar question, but seeing how this question has more views I think reposting my answer here would be useful.
This is in fact possible without resorting to strange hacks. I've got this in my .zshrc
RPROMPT='[%D{%L:%M:%S %p}]'
TMOUT=1
TRAPALRM() {
zle reset-prompt
}
The TRAPALRM function gets called every TMOUT seconds (in this case 1), and here it performs a prompt refresh, and does so until a command starts execution (and it doesn't interfere with anything you type on the prompt before hitting enter).
Source: http://www.zsh.org/mla/users/2007/msg00944.html (It's from 2007!)
Sounds like a pleasant request to me. If anything it makes more sense than showing the time when the prompt was displayed.
Fortunately Peter Stephenson posted a technique. Try something like this in .zshrc:
PROMPT="[%T] %n#%M %~ %# "
schedprompt() {
emulate -L zsh
zmodload -i zsh/sched
# Remove existing event, so that multiple calls to
# "schedprompt" work OK. (You could put one in precmd to push
# the timer 30 seconds into the future, for example.)
integer i=${"${(#)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
(( i )) && sched -$i
# Test that zle is running before calling the widget (recommended
# to avoid error messages).
# Otherwise it updates on entry to zle, so there's no loss.
zle && zle reset-prompt
# This ensures we're not too far off the start of the minute
sched +30 schedprompt
}
schedprompt
This would be .... unpleasant in a standard zsh prompt (or bash, or other shells).
I suggest you'd be better off using Gnu Screen.
Screen can have a status line which can show the time.
Here's an example screenrc scroll down to "Red Hat Magazine A guide to GNU Screen" to see the sample (i'll reproduce that here) which will, when screen is run, show the current time in the lower right corner of the terminal:
~/.screenrc
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
# Default screens
screen -t shell1 0
screen -t shell2 1
http://www.gnu.org/software/screen/

Resources