blob: 70aed74df9bd8f10e8323942c06abe99ac827490 (
plain) (
blame)
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
|
#!/usr/bin/env bash
# Easily search for strings within the files within the current directory.
# Specify file extensions and directories to exclude to improve accuracy.
# The file selected from fzf will be opened in vim.
function vfzopen() {
echo -n "Search Term: "
read search_query
echo -n "Filename: "
read filetype
echo -n "Exclude Directory: "
read exclude_dir
if [ ! -z "$exclude_dirs" ]; then
filename=$(find . -type f -name "$filetype" | \
xargs grep -l "$search_query" | fzf)
else
filename=$(find . -type f -name "$filetype" -not -path "./${exclude_dir}/*" \
| xargs grep -l "$search_query" | fzf)
fi
if [ ! -z "$filename" ]; then
echo "$filename"
vim +/"$search_query" "$filename"
return 0
else
return 1
fi
}
|