forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfzf.plugin.bash
More file actions
47 lines (39 loc) · 1.33 KB
/
fzf.plugin.bash
File metadata and controls
47 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# shellcheck shell=bash
# Load after the system completion to make sure that the fzf completions are working
# BASH_IT_LOAD_PRIORITY: 375
cite about-plugin
about-plugin 'load fzf, if you are using it'
if ! _bash-it-component-item-is-enabled plugin blesh; then
if [ -r ~/.fzf.bash ]; then
# shellcheck disable=SC1090
source ~/.fzf.bash
elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ]; then
# shellcheck disable=SC1091
source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash
fi
fi # only sources the keybindings and integration if blesh is not integrated already
# No need to continue if the command is not present
_command_exists fzf || return
if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd; then
export FZF_DEFAULT_COMMAND='fd --type f'
fi
fe() {
about "Open the selected file in the default editor"
group "fzf"
param "1: Search term"
example "fe foo"
local IFS=$'\n' line
local files=()
while IFS='' read -r line; do files+=("$line"); done < <(fzf-tmux --query="$1" --multi --select-1 --exit-0)
[[ -n "${files[0]}" ]] && ${EDITOR:-vim} "${files[@]}"
}
fcd() {
about "cd to the selected directory"
group "fzf"
param "1: Directory to browse, or . if omitted"
example "fcd aliases"
local dir
dir=$(find "${1:-.}" -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) \
&& cd "$dir" || return 1
}