Skip to content

Commit

Permalink
[zsh] emulate -L zsh to avoid issues with incompatible options
Browse files Browse the repository at this point in the history
Close #858
  • Loading branch information
junegunn committed Mar 1, 2017
1 parent c89ac34 commit 3a6af27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions shell/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ __fzf_generic_path_completion() {
tail=$6
fzf="$(__fzfcmd_complete)"

setopt localoptions nonomatch
setopt nonomatch
dir="$base"
while [ 1 ]; do
if [[ -z "$dir" || -d ${~dir} ]]; then
Expand Down Expand Up @@ -142,8 +142,8 @@ _fzf_complete_unalias() {
}
fzf-completion() {
emulate -L zsh
local tokens cmd prefix trigger tail fzf matches lbuf d_cmds
setopt localoptions noshwordsplit noksh_arrays
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
Expand Down
7 changes: 5 additions & 2 deletions shell/key-bindings.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __fzfcmd() {
}

fzf-file-widget() {
emulate -L zsh
LBUFFER="${LBUFFER}$(__fsel)"
local ret=$?
zle redisplay
Expand All @@ -38,9 +39,10 @@ bindkey '^T' fzf-file-widget

# ALT-C - cd into the selected directory
fzf-cd-widget() {
emulate -L zsh
setopt pipefail 2> /dev/null
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
-o -type d -print 2> /dev/null | cut -b3-"}"
setopt localoptions pipefail 2> /dev/null
local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"
if [[ -z "$dir" ]]; then
zle redisplay
Expand All @@ -57,8 +59,9 @@ bindkey '\ec' fzf-cd-widget

# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
emulate -L zsh
setopt pipefail 2> /dev/null
local selected num
setopt localoptions noglobsubst pipefail 2> /dev/null
selected=( $(fc -l 1 |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS +s --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(q)LBUFFER} +m" $(__fzfcmd)) )
local ret=$?
Expand Down

4 comments on commit 3a6af27

@junegunn
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the feedback. Can you post a minimal zshrc (preferably without oh-my-zsh, prezto, etc) that I can use to reproduce the problem you describe? Also if you have a more conservative solution to #858 than this, please let me know.

@junegunn
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just setopt localoptions noallexport noposixbuiltins instead of emulate -L zsh?

/cc @pjcj

@junegunn
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix pushed to master. Please update and see if it works.

@pjcj
Copy link

@pjcj pjcj commented on 3a6af27 Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame the emulate -L zsh solution doesn't work in this case because, I suspect, we will need to reset further options as they are found to cause problems, but I don't see another solution.

Please sign in to comment.