Constantly updated clock in zsh prompt without any drawback? - time

I use the following in my zshrc file:
RPROMPT="%{$fg_bold[blue]%}%n#%M, %D %T%{$reset_color%}"
TMOUT=1
TRAPALRM() { zle reset-prompt }
It works fine, until I use the completion menu:
zmodload -i zsh/complist
zstyle ':completion:*' menu select
Now, the items in the menu become invisible whenever the prompt refreshes (because of the zle reset-prompt). If that wasn't enough, I also get segfaults when navigating the menu…
So, is there a way to update the time in my prompt without breaking anything?
Thank you.

Related

Dismiss ZSH completion list after typing a character

In Fish shell when you press tab, list of completions is shown and if you start typing again it id dismissed
In ZSH after I star typing the completion menu is still shown and useless
Is there a way to make ZSH auto-completion behave the same way as Fish, so dismissing the list after typing?
I do not get this behavior with ZSH 5.7.1.
This is what's in my zshrc:
autoload -Uz compinit && compinit
source $SOFTWARE_HOME/zinit/bin/zinit.zsh
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit ice depth=1; zinit light romkatv/powerlevel10k
zinit light zdharma/fast-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-history-substring-search
setopt glob_complete
setopt menu_complete
zstyle ':completion:*' menu select
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND=(none)
These are my options:
❯ setopt
combiningchars
extendedglob
extendedhistory
globcomplete
histfindnodups
incappendhistory
interactive
login
menucomplete
monitor
promptsubst
pushdsilent
shinstdin
zle
AUTO_MENU : which Automatically use menu completion after the second consecutive request for completion, for example by pressing the tab key repeatedly
MENU_COMPLETE : On an ambiguous completion, instead of listing possibilities or beeping, insert the first match immediately. Then when completion is requested again, remove the first match and insert the second match, etc. When there are no more matches, go back to the first one again
zsh defaults to AUTO_MENU.
if you change it to MENU_AUTOCOMPLETE with setopt menu_complete then it will work almost like fish.
to autoload this setting just save it to your .zshrc config file.
if you want additional information about options you can go to zsh options manual man zshoptions.

How do I get rid of an unassigned "1" that appears in iterm2's input field with every new window?

When using iTerm2, every time I open it or open a new window, a 1 automatically appears in the input field and in the "last login" string above it. In the last login string, it appears before "Last login" when I first open iTerm, but appears as 1% on a new line when I open a new window.
I use the latest iTerm (3.3.7), as well as oh-my-zsh. I don't have anything defined as a command to run at the start of a session in iTerm's preferences. Up until this last update, I was able to keep the dreaded "1" from appearing by adding prompt_context () { } to my .zshrc file — but even that doesn't seem to help anymore. That said, if I completely delete the .zshrc file, the problem still persists.
Here's my current .zshrc file (minus a bunch of auto-generated, commented out lines):
ZSHING_PLUGINS=(
"https://gitlab.com/zakariaGatter/zshing"
)
# source zshing plugin
source $HOME/.zshing/zshing/zshing.zsh
# Path to your oh-my-zsh installation.
export ZSH="/Users/dc/.oh-my-zsh"
ZSH_THEME=powerlevel10k/powerlevel10k
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
git-flow-completion
zsh-syntax-highlighting
zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
# User configuration
export EDITOR="/usr/local/bin/atom --wait"
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_RPROMPT_ON_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUN=4
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_DISABLE_PROMPT=true
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="▶ "
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=""
alias ls='ls -G'
# redefine prompt_context for hiding user#hostname
prompt_context () { }
eval $(thefuck --alias)
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
Here's an image of what happens when I open iTerm2 (I tried to add clear as a command to run at the start of a session to mitigate the problem via general config, but it just ended up sending 1clear instead, so that's why the autocomplete shows what it does):
https://i.gyazo.com/4c6cf3826a2da40d5a8fe225b7d030c7.png
Here's an image of what happens when I open a new iTerm2 window from an existing session: https://i.gyazo.com/06c3ce5727afe053e4f9ec2cd07c26f0.png
Here's an image of my profile's general config — I originally just put the clear in the "send text at start" option:
https://i.gyazo.com/1c3d407686047ddf1fddd957b209bef4.png
Thanks in advance to anyone who takes the time to help!
I'm not quite sure why this worked, but this fixed it:
Go to iTerm2 > Preferences > Profiles > Window
Under the "Settings for New Windows" section, change the "Space" setting from the dropdown to "Current Space"

For further research: terminology about manipulating command before hitting RET in terminal

I just found out in zsh if I have a variable, namely abc="cba", and if I type echo ${!abc} and pressing enter, it doesnt go as command but instead open new prompt below with expanded variable echo ${abc="cba"}.
And probably included that powerful zsh plugin that let us automatically insert sudo just by double tapping Esc.
So for further studying and probably opening new possibilities, what is the right terminology about that typed-command-but-not-entered manipulation?
Thanks...
Those seem to be unrelated. The first is zsh asking you to verify history expansion. The second is a ZLE (Zsh Line Editor) widget with a keybinding to modify the current command line. You can see what this ZLE widget looks like in oh-my-zsh the source code.

Bash Login prompt disappeared

I recently made changes to my /etc/profile, and afterwards when I open a new tab in iTerm or Terminal I don't get a prompt. I tried reverting the changes in /etc/profile to the way I thought they were before - using Vim's undo - but I still don't get a login prompt, I just get a blank screen with a blinking cursor in the top left corner. I tried logging in as a different user, and the other user has the same problem, so I think the error is in the global bash login. /etc/motd doesn't run, but I'm not sure about the other files. Normally I would restart the computer but I have one shell that works and I'm hesitant to lose it by restarting the computer. Is there anywhere where an error would be logged? Thanks for your help,
Kevin
Here's my /etc/profile:
#put this in to try and debug, but does not show on the screen
echo "hello"
export PYTHONPATH=/Library/Python/2.6/site-packages:$PYTHONPATH
# System-wide .profile for sh(1)
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
fortune
Since when you open a new terminal it remains open, it seems that bash is still running but:
It does not show a prompt because you broke $PS1. In that case you might be still able to enter commands. export PS1='$ ' would be a good start in that case.
or
It is still doing something from /etc/profile. Either it's waiting for another process, or it has entered some kind of infinite loop - like the one caused by a shell file source loop.
Since you have a working terminal, you should check the running processes in ps before and after you start a new shell, to get an idea on what's going on.
I accidentally closed the window, and after I did I tried restarting the computer. When I logged back in the prompt displayed properly. Thanks for the help in the meantime.

To bind clear to ^l in Bash

I would like to have Ctrl-l for clear in my Bash.
How can you bind Ctrl-l to clear in Bash?
Put this in your ~/.inputrc:
C-L: backward-kill-line
(assuming by "clear" you mean "clear current input line"; if you mean "clear screen" then put clear-screen instead of backward-kill-line).
in a particular case where the clear-screen didn't work for me either, I found out that putting in ~/.bashrc the line: bind -x $'"\C-l":clear;' was better than "\C-l":'clear\n' in ~/.inputrc because it cleared the screen and left the currently typed command in place; for example (^L show where I hit the combo):
With "\C-l": clear-screen in ~/.inputrc:
user#darkstar:~$ date^L
user#darkstar:~$ date
user#darkstar:~$ ^L
user#darkstar:~$
With "\C-l":'clear\n' in ~/.inputrc:
user#darkstar:~$ date^L
-bash: dateclear: command not found
user#darkstar:~$ ^L
# screen effectively redrawn
With bind -x $'"\C-l":clear;' in ~/.bashrc:
user#darkstar:~$ date^L
# screen redrawn and the top line is now:
user#darkstar:~$ date
And for now I have not been able to get the same result as bind -x using only the inputrc file...
Edit
I found that in some cases where clear-screen wasn't working for me were caused by my attempts to get more colors in the CLI.
For example I had the issue with TERM=xterm-256color (or screen-256color, etc.) and removing the -256color part solved the problem.
I have not yet found a way to get a 256 colors term working along CTRL+l (in xterm, urxvt, etc).

Resources