flutter_ecommerce_app icon indicating copy to clipboard operation
flutter_ecommerce_app copied to clipboard

z -I seen as z -i when bash shell option nocasematch is set

Open jpcirrus opened this issue 5 years ago • 2 comments

In bash, when the environment has shopt -s nocasematch set then options -i and -I are considered equal and so interactive fzf is never used.

A solution is in the function _zlua in the script_zlua variable to make the following changes:

  1. Before the case statement add the following:
local restore_nocasematch=$(shopt -p nocasematch; true)
shopt -u nocasematch
  1. After the case statement add the following:
$restore_nocasematch

I don't know the situation in zsh.

jpcirrus avatar Dec 07 '19 22:12 jpcirrus

The function _zlua is not just for bash exclusively, but for all the posix shells like zsh and dash.

So there should not be any bash special code. nocasematch is rarely set in most working environment, before I make my decision whether or not include this, you can patch your self, append the code below after zlua 's initialization:

function _zlua_safe() {
    local restore_nocasematch=$(shopt -p nocasematch; true)
    shopt -u nocasematch
    _zlua "$@"
    $restore_nocasematch
}

alias z='_zlua_safe'

skywind3000 avatar Dec 09 '19 17:12 skywind3000

I realised that the function was used by other shells after having a look at the code, but nocasematch is set here when [ -n "$PS1" ] (primarily for easier terminal use of the [[ conditional expression) and it took me some time to find out why fzf interactive selection wasn't working. It was only after I found the undocumented variable _ZL_LOG_NAME that I found -I was being seen as -i and so knew the issue. I thought perhaps my proposed changes could be wrapped in

if [ -n "$BASH_VERSION" ]; then
...
fi

as used elsewhere in the code for bash specific processing, to ensure that this potential issue didn't affect other fzf users.

Anyway, having moved from autojump, many thanks for this project.

jpcirrus avatar Dec 09 '19 22:12 jpcirrus