Skip to content

Commit

Permalink
Merge pull request #35 from BarbUk/new/fzf_tab_completion
Browse files Browse the repository at this point in the history
BASH: tab complete using fzf
  • Loading branch information
skywind3000 authored Feb 5, 2019
2 parents 642549b + a842fb9 commit 4c5d0aa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ z -i foo # cd with interactive selection

if you want `z.lua` print the new directory after cd.

If you want `fzf` tab completion use:

eval "$(lua /path/to/z.lua --init bash fzf)"

- zsh:

put something like this in your `.zshrc`:
Expand Down
33 changes: 33 additions & 0 deletions z.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
-- * put something like this in your .bashrc:
-- eval "$(lua /path/to/z.lua --init bash enhanced)"
--
-- Bash fzf tab completion Mode:
-- * put something like this in your .bashrc:
-- eval "$(lua /path/to/z.lua --init bash fzf)"
--
-- Zsh Install:
-- * put something like this in your .zshrc:
-- eval "$(lua /path/to/z.lua --init zsh)"
Expand Down Expand Up @@ -1866,6 +1870,27 @@ if [ -n "$BASH_VERSION" ]; then
fi
]]

local script_fzf_complete_bash = [[
if command -v fzf >/dev/null 2>&1; then
# To redraw line after fzf closes (printf '\e[5n')
bind '"\e[0n": redraw-current-line'
_zlua_fzf_complete() {
local query="${COMP_WORDS[COMP_CWORD]}"
local selected=$(_zlua --complete | $zlua_fzf --query "$query")
printf '\e[5n'
if [ -n "$selected" ]; then
COMPREPLY=("$selected")
return 0
fi
}
complete -o bashdefault -F _zlua_fzf_complete ${_ZL_CMD:-z}
fi
]]

local script_complete_zsh = [[
_zlua_zsh_tab_completion() {
# tab completion
Expand Down Expand Up @@ -1901,6 +1926,14 @@ function z_shell_init(opts)
end
end
print(script_complete_bash)
if opts.fzf ~= nil then
fzf_cmd = "fzf --reverse --inline-info +s"
if not os.getenv('_ZL_FZF_FULLSCR') then
fzf_cmd = fzf_cmd .. ' --height 35%'
end
print('zlua_fzf="' .. fzf_cmd .. '"')
print(script_fzf_complete_bash)
end
elseif opts.zsh ~= nil then
if prompt_hook then
print(once and script_init_zsh_once or script_init_zsh)
Expand Down

0 comments on commit 4c5d0aa

Please sign in to comment.