Remove new line in zsh theme - zsh

I'm trying to modify zsh theme af-magic. I really like it except one part. It makes a line full if dashes after every command.
I would out that this {(l.COLUMNS..-.)} part does that. If I remove the whole section, or - to make it {(l.COLUMNS...)}, it draws an empty line.
So I want to get rid of this empty line. I tried to find \n anywhere, but there are none.
So this is the theme
# af-magic.zsh-theme
# Repo: https://github.com/andyfleming/oh-my-zsh
# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
# primary prompt
PROMPT='$FG[237]${(l.COLUMNS..-.)}%{$reset_color%}
$FG[032]%~/\
$(git_prompt_info)$(hg_prompt_info)\
$FG[105]%(!.#.)%{$reset_color%}'
PROMPT2='%{$fg[red]%}\ %{$reset_color%}'
RPS1='${return_code}'
# color vars
eval my_gray='$FG[237]'
eval my_orange='$FG[214]'
# right prompt
if type "virtualenv_prompt_info" > /dev/null
then
RPROMPT='$FG[078]$(virtualenv_prompt_info)%{$reset_color%} $my_gray%n#%m%{$reset_color%}%'
else
RPROMPT='$my_gray%n#%m%{$reset_color%}%'
fi
# git settings
ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075]($FG[078]"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
# hg settings
ZSH_THEME_HG_PROMPT_PREFIX="$FG[075]($FG[078]"
ZSH_THEME_HG_PROMPT_CLEAN=""
ZSH_THEME_HG_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_HG_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
As a separate question, which language is this?

Just remove the use of COLUMNS from the prompt.
PROMPT='$FG[237]${(l.COLUMNS..-.)}%{$reset_color%}
$FG[032]%~/\
$(git_prompt_info)$(hg_prompt_info)\
$FG[105]%(!.#.)%{$reset_color%}'
Once you do that, you can also remove the code that colored the now-absent line, to get
PROMPT='$FG[032]%~/\
$(git_prompt_info)$(hg_prompt_info)\
$FG[105]%(!.#.)%{$reset_color%}'
The newline, by the way, was the line break embedded in the value (note there was no \ at the end of the first line of the original prompt).

Related

sqlite3's command history breaks multi-line commands

When I use sqlite3's command history (i.e. arrow-up) after a multi-line command, I only get the last line of the previous command. Pressing arrow-up again, i get the second-last and so on. This seems not very effective if i need the whole last command and fix something. Is there a way to get the full last command, preferable as a multi line?
If not, maybe I'm missing something fundamental: how are you supposed to effectively edit multi-line commands?
My .sqliterc
.headers on
.mode column
My .inputrc:
set completion-ignore-case on
set completion-map-case on
set colored-stats on
set show-all-if-ambiguous on
set show-all-if-unmodified on
set colored-completion-prefix on
set skip-completed-text on
# don't ask for completion if more than x completions
set completion-query-items -1
# don't use a pager but show everything at once
set page-completions off
# incrementally search history (i.e. ss <up> -> )
"\e[A": history-search-backward
"\e[B": history-search-forward

How can I determine why this `test` does not match for tmux's session_name?

I'm trying to give my tmux panes individual titles. Since there is nothing built into tmux to assign titles, I'm using a function that will receive various properties of the pane and then lookup the title that I want based on those properties, and echo it out.
However, the test inside the function is not working as expected. Even when the session_name "portal" is passed in, it does not match the string "portal", even though the output is always exactly "portal".
I've removed all irrelevant code from the function to show just exactly the failing match:
tmux_pane_title() {
local session_name=$1
# ...
if [[ "$session_name" = "portal" ]] && echo ".${session_name}." || echo "-${session_name}-"
# ...
}
tmux set pane-border-format "#P: `tmux_pane_title \"#{session_name}\" \"#{pane_current_command}\" \"#{pane_current_path}\"` "
It always echos out "-portal-", showing the $1 is in fact "portal", but it does not match "portal" in the test.
I have tried using sed to remove newlines, but it made no difference.
However if I hard-code "portal" into the tmux format for pane-border-format it will suddenly work, suggesting there's some weird control character hidden in the name preventing it from working when I pass in session_name
tmux set pane-border-format "#P: `tmux_pane_title \"portal\" \"#{pane_current_command}\" \"#{pane_current_path}\"` "
If that's the case, how can I find and eliminate the control character? (And why would it be there? I did not enter anything weird into my tmuxinator.yml file for the session name.)
I've already tried removing control characters like this:
local session_name=$(echo $1 | tr -d "[:cntrl:]")
If that's not the case, how can I figure out what is breaking this function?
P.S. I'm on tmux 3.1b.
This is NOT an answer to the question, but it is a step in the direction of a solution to the problem that led me to ask the question. If you have the same problem, this may be helpful.
Although I'm still interested in solving the mystery related to the failing test, I found a way to set my pane titles more easily1.
There is a pane_title property that can be used in your pane-border-format:
tmux set pane-border-format "#{pane_title}"
If you set this format, then you can set the title with printf and escape sequences:
printf '\033]2;%s\033\\' 'your desired title'
(I had read about the printf technique elsewhere, both on and off SO, but it fails if you don't have the proper format including pane_title. No where else did I see these two things mentioned together. Without the combination, it fails. Assuming that the default format is set is not a safe assumption.)
A complete answer is still useful, so I could do things like this:
tmux set pane-border-format " #P: #{?pane_title,#{pane_title},`tmux_pane_title \"#{session_name}\" \"#{pane_current_command}\" \"#{pane_current_path}\"`} "
That would choose an explicit title if one were set, and default to the function to choose one. So please don't close this question as a duplicate of others that relate to setting tmux pane titles. IT IS DIFFERENT.
1In other words, I solved the problem but I didn't answer the question. Many people think SO is a problem-solving site, but it describes itself as a question & answer site. I doubt if many people have given this distinction much thought, but they are very different things.

Nvim - I don't understand how to change the options of this plugin

https://raw.githubusercontent.com/jalvesaq/Nvim-R/master/doc/Nvim-R.txt
Section 6 of that document, ctrlF + Nvim-R-options
I'm new to vim, not sure what to do with that information. I want to disable |R_assign|, or possibly reverse the way it works so a double underscore produces a <- in insert mode.
Could someone point me in the right direction please?
The usually recommended method to disable is to add this line to your ~/.vimrc file:
let vimrplugin_assign = 0
But unfortunately it doesn't work (at least for me).
When you go through the .vim script files installed by the plugin, the answer lies in lines 2844-2847 of common_global.vim file in the source code:
" Replace 'underline' with '<-'
if g:R_assign == 1 || g:R_assign == 2
silent exe 'inoremap <buffer><silent> ' . g:R_assign_map . ' <Esc>:call ReplaceUnderS()<CR>a'
endif
So the real solution is to add this line to your ~/.vimrc file:
let R_assign = 0
An easy one-liner to do the job for you (if you use a Unix-like system):
echo "let R_assign = 0" >> ~/.vimrc
Do not forget to put two directions as ">>" in order to append and not replace.

zsh agnoster theme chagne prompt/ps1

How can I change the prompt of my zsh shell while still retaining the cool coloring that agnoster provides? For people who don't know, it looks like this
I want to add some things like ! and \u before the working directories. I've tried the usual PS1="! \u \w" but it just gives this:
EDIT: I found the right escaped characters for inserting information, but it cancels out the styling
How can I change the prompt while maintaining the styling?
You'd have to customise the theme, i.e. .oh-my-zsh/themes/agnoster.zsh-theme, add your own function to the build_prompt function and add whatever you need to the prompt:
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
prompt_context
prompt_dir
prompt_git
prompt_hg
prompt_end
}
I personally added a prompt_custom stub, which I then replace with the real prompt function in my .zshrc, so I only have to maintain that small customisation (probabaly worthty of a pull request at some stage...)
prompt_custom() {
}
You can change the prompt_context() in .oh-my-zsh/themes/.zsh-theme with the following block of code
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)~"
fi
}

Customize zsh's prompt when displaying previous command exit code

Zsh includes the ability to display the return code/exit code of the previous command in the prompt by using the %? escape sequence.
However I would like to have the following prompt:
user#host ~ [%?] %
when the exit code is different from 0 and:
user#host ~ %
when exit code is 0.
If I use %? alone it is always displayed, even if %? is 0.
In addition I want the square brackets but only when the exit code not 0.
What is the simplest way to do this?
Add this in the position in PS1 where you want the exit code to appear:
%(?..[%?] )
It's a conditional expression. The part between the two dots (nothing in this case) is output if the expression before the first dot is true. The part after the second dot is output if it's false.
For example:
PS1='%n%m %~ %(?..[%?] )%# '
Alternatively, you can:
setopt PRINT_EXIT_VALUE
to always print a newline showing previous return value.
I don't prefer this for ordinary use, but it is often good for debugging shell scripts.

Resources