atweiden / fzf-extras

Key bindings from fzf wiki
MIT License
193 stars 23 forks source link

Adding opened file to history #15

Open joshuamcginnis opened 5 years ago

joshuamcginnis commented 5 years ago

fe [FUZZY PATTERN] | Open selected file with $EDITOR

I use fe often, but I recently setup fzf on a new machine and I realized that after I select a file using fe and the file is opened with my $EDITOR (in this case, vim), when I exit vim, there is nothing added to my zsh history. I often will close out a file and would like to just quickly go back to it.

Is there a way to add the command used to open a file with fe to history?

u1and0 commented 5 years ago

How about it?

 fe() {
   local IFS=$'\n'
   local files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
-  [[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
+  [[ -n "$files" ]] && echo "${EDITOR:-vim} ${files[@]}" | runcmd
 }

runcmd is included in fzf-extra.sh

# utility function used to run the command in the shell
runcmd () {
  perl -e 'ioctl STDOUT, 0x5412, $_ for split //, <>'
}
joshuamcginnis commented 5 years ago

Thanks @u1and0 - I appreciate this.

How would you suggest making these changes locally? I use zplug currently to manage my zsh plugins. Is there an opportunity for a PR that I could contribute that would make these changes available to everyone?

joshuamcginnis commented 5 years ago

I also tested this and it didn't work. It has something to do with runcmd. For example, this hangs:

vim fzf-extras.sh | runcmd and this just returns ls | runcmd

u1and0 commented 5 years ago

Try echo "vim fzf-extras.sh" | runcmd

joshuamcginnis commented 5 years ago

This also does not work - it just returns.

Presuming we find a working version, how do you recommend I make this change locally in a way that will ensure I continue to receive upstream updates?

u1and0 commented 5 years ago

Did you try? https://github.com/atweiden/fzf-extras/issues/15#issuecomment-497893019

echo $(vim fzf-extra.sh) | runcmd is bad. I modified echo "vim fzf-extra.sh | runcmd" in few minuets later.

joshuamcginnis commented 5 years ago

I tried both. The second one just echos the command.

╰─$ echo "vim fzf-extra.sh | runcmd"                                                                                                                                                     127 ↵
vim fzf-extra.sh | runcmd
u1and0 commented 5 years ago

╰─$ echo "vim fzf-extra.sh | runcmd"

Look more carefully, end of double quote position must be BEFORE PIPE.

We would like to pass the strings "vim [filename]" to runcmd.

2019年6月4日(火) 8:27 Josh McGinnis notifications@github.com:

I tried both. The second one just echos the command.

╰─$ echo "vim fzf-extra.sh | runcmd" 127 ↵

vim fzf-extra.sh | runcmd

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/atweiden/fzf-extras/issues/15?email_source=notifications&email_token=AD5GCVA2C2JSKSNLQWDP3BLPYWSHVA5CNFSM4HQYORSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW267FA#issuecomment-498462612, or mute the thread https://github.com/notifications/unsubscribe-auth/AD5GCVAXJ6ATJJKZFPEEAYDPYWSHVANCNFSM4HQYORSA .

joshuamcginnis commented 5 years ago

It still just returns

╭─me ~ 
╰─$ echo "vim fzf-extras.sh" | runcmd ↵
╭─me ~ 
╰─$