mirror of https://github.com/kazhala/dotbare
check fd and tree, use find to search
parent
8721dbed81
commit
c45a32a606
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# search local file or directory taking consideration of optional dependency
|
||||
#
|
||||
# @params
|
||||
# Globals
|
||||
# search_type: string, f or d, search file or directory
|
||||
# exe_fd: number, 0 or 1, check if fd is executable
|
||||
# exe_tree: number, 0 or 1, check if tree is executable
|
||||
# Arguments
|
||||
# search_type: string, f or d, search file or directory
|
||||
|
||||
function fd_exists() {
|
||||
wtf -V &>/dev/null
|
||||
echo "$?"
|
||||
}
|
||||
|
||||
function tree_exists() {
|
||||
wtf -V &>/dev/null
|
||||
echo "$?"
|
||||
}
|
||||
|
||||
function search_file() {
|
||||
search_type="$1"
|
||||
exe_fd="$(fd_exists)"
|
||||
if [[ "${search_type}" == "f" ]]; then
|
||||
if [[ "${exe_fd}" -eq 0 ]]; then
|
||||
fd -H -d 1 -t f | fzf --multi --exit-0 --preview "head -50 {}"
|
||||
else
|
||||
find . -maxdepth 1 -type f | sed "s|\./||g" | fzf --multi --exit-0 --preview "head -50 {}"
|
||||
fi
|
||||
elif [[ "${search_type}" == "d" ]]; then
|
||||
exe_tree="$(tree_exists)"
|
||||
if [[ "${exe_fd}" -eq 0 && "${exe_tree}" -eq 0 ]]; then
|
||||
fd -H -d 1 -t d -E .git | fzf --multi --exit-0 --preview "tree -L 1 -C --dirsfirst {}"
|
||||
elif [[ "${exe_tree}" -eq 0 ]]; then
|
||||
find . -maxdepth 1 -type d | awk '{if ($0 != "." && $0 != "./.git"){print $0}}' | sed "s|\./||g" | fzf --multi --exit-0 --preview "tree -L 1 -C --dirsfirst {}"
|
||||
else
|
||||
find . -maxdepth 1 -type d | awk '{if ($0 != "." && $0 != "./.git"){print $0}}' | sed "s|\./||g" | fzf --multi --exit-0
|
||||
fi
|
||||
fi
|
||||
}
|
Loading…
Reference in New Issue