Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
7d739082
Unverified
Commit
7d739082
authored
Oct 20, 2020
by
Marc Cornellà
Committed by
GitHub
Oct 20, 2020
Browse files
fzf: add check for OpenSUSE and OpenBSD packages (#9327)
parent
f9f45ca2
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugins/fzf/README.md
View file @
7d739082
# fzf
# fzf
This plugin enables
[
junegunn's fzf
](
https://github.com/junegunn/fzf
)
fuzzy auto-completion and key bindings
This plugin tries to find
[
junegunn's fzf
](
https://github.com/junegunn/fzf
)
based on where
it's been installed, and enables its fuzzy auto-completion and key bindings.
To use it, add
`fzf`
to the plugins array in your zshrc file:
To use it, add
`fzf`
to the plugins array in your zshrc file:
```
zsh
```
zsh
plugins
=(
... fzf
)
plugins
=(
... fzf
)
```
```
## Settings
## Settings
Add these before the
`plugins=()`
line in your zshrc file:
All these settings should go in your zshrc file, before Oh My Zsh is sourced.
### `FZF_BASE`
Set to fzf installation directory path:
```
zsh
export
FZF_BASE
=
/path/to/fzf/install/dir
```
### `FZF_DEFAULT_COMMAND`
Set default command to use when input is tty:
```
zsh
```
zsh
# Set fzf installation directory path
export
FZF_DEFAULT_COMMAND
=
'<your fzf default commmand>'
# export FZF_BASE=/path/to/fzf/install/dir
```
If not set, the plugin will try to set it to these, in the order in which they're found:
# Uncomment to set the FZF_DEFAULT_COMMAND
-
[
`rg`
](
https://github.com/BurntSushi/ripgrep
)
# export FZF_DEFAULT_COMMAND='<your fzf default commmand>'
-
[
`fd`
](
https://github.com/sharkdp/fd
)
-
[
`ag`
](
https://github.com/ggreer/the_silver_searcher
)
# Uncomment the following line to disable fuzzy completion
### `DISABLE_FZF_AUTO_COMPLETION`
# DISABLE_FZF_AUTO_COMPLETION="true"
# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C)
Set whether to load fzf auto-completion:
# DISABLE_FZF_KEY_BINDINGS="true"
```
zsh
DISABLE_FZF_AUTO_COMPLETION
=
"true"
```
```
| Setting | Example value | Description |
### `DISABLE_FZF_KEY_BINDINGS`
|-----------------------------|----------------------------|-------------------------------------------------------------|
| FZF_BASE |
`/path/to/fzf/install/dir`
| Set fzf installation directory path (
**export**
) |
Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C):
| FZF_DEFAULT_COMMAND |
`fd --type f`
| Set default command to use when input is tty (
**export**
) |
| DISABLE_FZF_AUTO_COMPLETION |
`true`
| Set whether to load fzf auto-completion |
```
zsh
| DISABLE_FZF_KEY_BINDINGS |
`true`
| Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C) |
DISABLE_FZF_KEY_BINDINGS
=
"true"
```
plugins/fzf/fzf.plugin.zsh
View file @
7d739082
function
setup_using_base_dir
()
{
function
setup_using_base_dir
()
{
# Declare all variables local not no mess with outside env in any way
local
fzf_base fzf_shell fzfdirs
dir
local
fzf_base
local
fzf_shell
local
fzfdirs
local dir
test
-d
"
${
FZF_BASE
}
"
&&
fzf_base
=
"
${
FZF_BASE
}
"
test
-d
"
${
FZF_BASE
}
"
&&
fzf_base
=
"
${
FZF_BASE
}
"
...
@@ -31,38 +27,37 @@ function setup_using_base_dir() {
...
@@ -31,38 +27,37 @@ function setup_using_base_dir() {
fi
fi
fi
fi
if
[[
-d
"
${
fzf_base
}
"
]]
;
then
if
[[
!
-d
"
${
fzf_base
}
"
]]
;
then
# Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
return
1
if
[[
!
-d
"
${
fzf_base
}
/shell"
]]
;
then
fi
fzf_shell
=
"
${
fzf_base
}
"
else
fzf_shell
=
"
${
fzf_base
}
/shell"
fi
# Setup fzf binary path
# Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
if
!
((
${
+commands[fzf]
}
))
&&
[[
!
"
$PATH
"
==
*
$fzf_base
/bin
*
]]
;
then
if
[[
!
-d
"
${
fzf_base
}
/shell"
]]
;
then
export
PATH
=
"
$PATH
:
$fzf_base
/bin"
fzf_shell
=
"
${
fzf_base
}
"
fi
else
fzf_shell
=
"
${
fzf_base
}
/shell"
fi
#
Auto-completion
#
Setup fzf binary path
if
[[
!
"
$DISABLE_FZF_AUTO_COMPLETION
"
=
=
"true"
]]
;
then
if
((
!
${
+commands[fzf]
}
))
&&
[[
"
$PATH
"
!
=
*
$fzf_base
/bin
*
]]
;
then
[[
$-
==
*
i
*
]]
&&
source
"
${
fzf_shell
}
/completion.zsh"
2> /dev/null
export
PATH
=
"
$PATH
:
$fzf_base
/bin"
fi
fi
# Key bindings
# Auto-completion
if
[[
!
"
$DISABLE_FZF_KEY_BINDINGS
"
==
"true"
]]
;
then
if
[[
-o
interactive
&&
"
$DISABLE_FZF_AUTO_COMPLETION
"
!=
"true"
]]
;
then
source
"
${
fzf_shell
}
/key-bindings.zsh"
source
"
${
fzf_shell
}
/completion.zsh"
2> /dev/null
fi
fi
else
return
1
# Key bindings
if
[[
"
$DISABLE_FZF_KEY_BINDINGS
"
!=
"true"
]]
;
then
source
"
${
fzf_shell
}
/key-bindings.zsh"
fi
fi
}
}
function
setup_using_debian_package
()
{
function
setup_using_debian_package
()
{
((
$+
commands[dpkg]
))
&&
dpkg
-s
fzf &> /dev/null
if
((
!
$+
commands[dpkg]
))
||
!
dpkg
-s
fzf &>/dev/null
;
then
if
((
$?
))
;
then
# Either not a debian based distro, or no fzf installed
# Either not a debian based distro, or no fzf installed. In any case skip ahead
return
1
return
1
fi
fi
...
@@ -76,8 +71,8 @@ function setup_using_debian_package() {
...
@@ -76,8 +71,8 @@ function setup_using_debian_package() {
local
key_bindings
=
"/usr/share/doc/fzf/examples/key-bindings.zsh"
local
key_bindings
=
"/usr/share/doc/fzf/examples/key-bindings.zsh"
# Auto-completion
# Auto-completion
if
[[
$-
==
*
i
*
]]
&&
[[
!
"
$DISABLE_FZF_AUTO_COMPLETION
"
=
=
"true"
]]
;
then
if
[[
-o
interactive
&&
"
$DISABLE_FZF_AUTO_COMPLETION
"
!
=
"true"
]]
;
then
source
$completions
2> /dev/null
source
$completions
2> /dev/null
fi
fi
# Key bindings
# Key bindings
...
@@ -88,16 +83,74 @@ function setup_using_debian_package() {
...
@@ -88,16 +83,74 @@ function setup_using_debian_package() {
return
0
return
0
}
}
function
setup_using_opensuse_package
()
{
# OpenSUSE installs fzf in /usr/bin/fzf
# If the command is not found, the package isn't installed
((
$+
commands[fzf]
))
||
return
1
# The fzf-zsh-completion package installs the auto-completion in
local
completions
=
"/usr/share/zsh/site-functions/_fzf"
# The fzf-zsh-completion package installs the key-bindings file in
local
key_bindings
=
"/etc/zsh_completion.d/fzf-key-bindings"
# If these are not found: (1) maybe we're not on OpenSUSE, or
# (2) maybe the fzf-zsh-completion package isn't installed.
if
[[
!
-f
"
$completions
"
||
!
-f
"
$key_bindings
"
]]
;
then
return
1
fi
# Auto-completion
if
[[
-o
interactive
&&
"
$DISABLE_FZF_AUTO_COMPLETION
"
!=
"true"
]]
;
then
source
"
$completions
"
2>/dev/null
fi
# Key bindings
if
[[
"
$DISABLE_FZF_KEY_BINDINGS
"
!=
"true"
]]
;
then
source
"
$key_bindings
"
2>/dev/null
fi
return
0
}
function
setup_using_openbsd_package
()
{
# openBSD installs fzf in /usr/local/bin/fzf
if
[[
"
$OSTYPE
"
!=
openbsd
*
]]
||
((
!
$+
commands[fzf]
))
;
then
return
1
fi
# The fzf package installs the auto-completion in
local
completions
=
"/usr/local/share/zsh/site-functions/_fzf_completion"
# The fzf package installs the key-bindings file in
local
key_bindings
=
"/usr/local/share/zsh/site-functions/_fzf_key_bindings"
# Auto-completion
if
[[
-o
interactive
&&
"
$DISABLE_FZF_AUTO_COMPLETION
"
!=
"true"
]]
;
then
source
"
$completions
"
2>/dev/null
fi
# Key bindings
if
[[
"
$DISABLE_FZF_KEY_BINDINGS
"
!=
"true"
]]
;
then
source
"
$key_bindings
"
2>/dev/null
fi
return
0
}
function
indicate_error
()
{
function
indicate_error
()
{
print
"[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
\n
"
\
cat
>
&2
<<
EOF
"Please add
\`
export FZF_BASE=/path/to/fzf/install/dir
\`
to your .zshrc"
>
&2
[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
Please add
\`
export FZF_BASE=/path/to/fzf/install/dir
\`
to your .zshrc
EOF
}
}
# Check for debian package first, because it easy to short cut
# Indicate to user that fzf installation not found if nothing worked
# Indicate to user that fzf installation not found if nothing worked
setup_using_debian_package
||
setup_using_base_dir
||
indicate_error
setup_using_openbsd_package
\
||
setup_using_debian_package
\
||
setup_using_opensuse_package
\
||
setup_using_base_dir
\
||
indicate_error
unset
-f
setup_using_debian_package setup_using_base_dir indicate_error
unset
-f
setup_using_opensuse_package
setup_using_debian_package setup_using_base_dir indicate_error
if
[[
-z
"
$FZF_DEFAULT_COMMAND
"
]]
;
then
if
[[
-z
"
$FZF_DEFAULT_COMMAND
"
]]
;
then
if
((
$+
commands[rg]
))
;
then
if
((
$+
commands[rg]
))
;
then
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment