You are not logged in.

#1 2015-03-13 03:16:35

Serge2702
Member
From: México City
Registered: 2014-01-14
Posts: 73

[solved] No search history in apps using readline after installing zsh

Hello. I'm an intensive user of applications that uses readline, for example octave, ipython2 and sbcl with rlwrap. I use history search with just pressing the up and down arrows a lot, as explained in the wiki. I decided to give zsh a try, and so far I like it. I have configured it to behave like vim, and history backwards search works correctly in the zsh shell by pressing the up and down arrows. The problem is that now history backwards search stopped working in octave, ipython, etc, even tough I didn't modified .bashrc or .inputrc. Changing back to bash didn't work, because now not even bash has history search using the up and down arrows. Ctrl+R still works, but I don't understand why I can't restore the previous behaviour.

Here is my .inputrc

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

#History completion
"\e[A": history-search-backward
"\e[B": history-search-forward

#autocompletar
set show-all-if-ambiguous on
set show-all-if-unmodified on

My zshrc is like this (sorry because it's really messy, I deleted aliases and some functions.) I don't know if it's relevant.

export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
# export MANPATH="/usr/local/man:$MANPATH"
#================================================================================
#NO EDITAR DESPUÉS DE ESTA LÍNEA
# The following lines were added by compinstall

zstyle ':completion:*' auto-description 'Introduce %d'
zstyle ':completion:*' completer _oldlist _expand _complete _ignored _match _correct _approximate _prefix
zstyle ':completion:*' completions 1
zstyle ':completion:*' condition 0
zstyle ':completion:*' file-sort name
zstyle ':completion:*' format 'Completando %d'
zstyle ':completion:*' glob 1
zstyle ':completion:*' group-name ''
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]} r:|[._-]=* r:|=*'
zstyle ':completion:*' max-errors 2
zstyle ':completion:*' menu select=1
zstyle ':completion:*' original true
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*' substitute 1
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/sergio/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=65536
SAVEHIST=65536
setopt appendhistory autocd nomatch
unsetopt beep
bindkey -v
# End of lines configured by zsh-newuser-install
#NO EDITAR ANTES DE ESTA LÍNEA
#===================================================
typeset -A key

key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
key[Up]=${terminfo[kcuu1]}
key[Down]=${terminfo[kcud1]}
key[Left]=${terminfo[kcub1]}
key[Right]=${terminfo[kcuf1]}
key[PageUp]=${terminfo[kpp]}
key[PageDown]=${terminfo[knp]}

# setup key accordingly
[[ -n "${key[Home]}"     ]]  && bindkey  "${key[Home]}"     beginning-of-line
[[ -n "${key[End]}"      ]]  && bindkey  "${key[End]}"      end-of-line
[[ -n "${key[Insert]}"   ]]  && bindkey  "${key[Insert]}"   overwrite-mode
[[ -n "${key[Delete]}"   ]]  && bindkey  "${key[Delete]}"   delete-char
#[[ -n "${key[Up]}"       ]]  && bindkey  "${key[Up]}"       up-line-or-history
#[[ -n "${key[Down]}"     ]]  && bindkey  "${key[Down]}"     down-line-or-history
[[ -n "${key[Left]}"     ]]  && bindkey  "${key[Left]}"     backward-char
[[ -n "${key[Right]}"    ]]  && bindkey  "${key[Right]}"    forward-char
[[ -n "${key[PageUp]}"   ]]  && bindkey  "${key[PageUp]}"   beginning-of-buffer-or-history
[[ -n "${key[PageDown]}" ]]  && bindkey  "${key[PageDown]}" end-of-buffer-or-history
[[ -n "${key[Up]}"   ]]  && bindkey  "${key[Up]}"    history-beginning-search-backward
[[ -n "${key[Down]}" ]]  && bindkey  "${key[Down]}"  history-beginning-search-forward

# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
    function zle-line-init () {
        printf '%s' "${terminfo[smkx]}"
    }
    function zle-line-finish () {
        printf '%s' "${terminfo[rmkx]}"
    }
    zle -N zle-line-init
    zle -N zle-line-finish
fi
#autoload -U promptinit
#promptinit
setopt prompt_subst
autoload -U colors && colors

function calcula_ancho {
TERMWIDTH=${COLUMNS}
temp="┌──[${USER}]───[${PWD}]──┐"

let fillsize=${TERMWIDTH}-${#temp}-1
if [ "$fillsize" -gt "0" ]
then
    fill="──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
    fill="${fill:0:${fillsize}}"
    newPWD="${PWD}"
fi

if [ "$fillsize" -lt "0" ]
then
    
	fill=""
    fillsize=-1*${fillsize}
	let cut=3+${fillsize}
	newPWD="...${PWD:${cut}}"
fi
}

#precmd(){((cols=$COLUMNS-${#temp}))}
precmd(){calcula_ancho}
#PROMPT='%{$fg_bold[blue]%}┌──%{$fg_bold[red]%}[%{$fg_bold[green]%}%n%{$fg_bold[red]%}]%{$fg_bold[blue]%}───%{$fg_bold[red]%}[%{$fg_bold[yellow]%}%$cols<...<%~%<<%{$fg[red]%}]%{$reset_color%}%{$fg_bold[blue]%}──┘%{$reset_color%b%}
PROMPT='%{$fg_bold[blue]%}┌──%{$fg_bold[red]%}[%{$fg_bold[green]%}%n%{$fg_bold[red]%}]%{$fg_bold[blue]%}$fill───%{$fg_bold[red]%}[%{$fg_bold[yellow]%}$newPWD%{$fg[red]%}]%{$reset_color%}%{$fg_bold[blue]%}──┐%{$reset_color%b%}
%{$fg_bold[blue]%}└%(0?..%{$fg_bold[red]%})──╼%{$reset_color%b%} '
vim_ins_mode="%{$fg_bold[blue]%}╾─%{$fg[red]%}[%{$fg[white]%}%{$fg_bold[white]%}ins%{$fg[red]%k%}]%{$fg_bold[blue]%}──┘%{$reset_color%b%}"
vim_cmd_mode="%{$fg_bold[blue]%}╾─%{$fg[red]%}[%{$fg[white]%}%{$fg_bold[red]%}cmd%{$fg[red]%k%}]%{$fg_bold[blue]%}──┘%{$reset_color%b%}"
#vim_cmd_mode="%{$bg[green]%}%{$fg_bold[white]%} CMD %{$reset_color%b%}"
vim_mode=$vim_ins_mode

function zle-keymap-select {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  zle reset-prompt
}
zle -N zle-keymap-select

function zle-line-finish {
  vim_mode=$vim_ins_mode
}
zle -N zle-line-finish
# Fix a bug when you C-c in CMD mode and you'd be prompted with CMD mode indicator, while in fact you would be in INS mode
# Fixed by catching SIGINT (C-c), set vim_mode to INS and then repropagate the SIGINT, so if anything else depends on it, we will not break it
function TRAPINT() {
  vim_mode=$vim_ins_mode
  return $(( 128 + $1 ))
}
RPROMPT='${vim_mode}'
#Editar la línea con el editor de texto
autoload -U   edit-command-line
zle -N        edit-command-line
bindkey -M vicmd 'v' edit-command-line

Last edited by Serge2702 (2015-03-16 03:50:28)

Offline

#2 2015-03-13 04:15:22

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [solved] No search history in apps using readline after installing zsh

Zsh doesn't use readline, it uses zle.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-03-13 05:46:20

Serge2702
Member
From: México City
Registered: 2014-01-14
Posts: 73

Re: [solved] No search history in apps using readline after installing zsh

Yes, I know that. But octave and rlwrap use GNU readline, and that uses inputrc for its configuration. Apparently zle doesn't affect them. That's why I don't know why backwards search history stopped working after changing to zsh. I changed several options in inputrc (like enabling vim mode) and they work, they affect the behaviour of many applications even tough my shell is zsh right now. But still, my arrows still only show the previous command when I press them.

Apparently, as far as I know it's no possible to use zle as a wrapper for other applications, like rlwrap. And I don't know if its possible to make zshrc or other config file to take control of other applications that use readline.

Offline

#4 2015-03-16 03:49:26

Serge2702
Member
From: México City
Registered: 2014-01-14
Posts: 73

Re: [solved] No search history in apps using readline after installing zsh

Well, I solved it. The problem was in my .zshrc file. I don't know why, but the function zle-line-finish was interfering with the other applications. I just deleted it. Now history search works in all applications, and my prompt still says if  I'm in command or insert mode.

Offline

Board footer

Powered by FluxBB