2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-06 09:20:25 +00:00
dotbare/helper/search_file.sh
2020-05-17 23:14:52 +10:00

24 lines
871 B
Bash

#!/usr/bin/env bash
#
# search local file or directory taking consideration of optional dependency
#######################################
# search local file
# Arguments:
# $1: stirng, f or d, search file or directory
# Outputs:
# A user selected file path
#######################################
function search_file() {
local search_type="$1"
if [[ "${search_type}" == "f" ]]; then
find . -maxdepth 1 -type f | sed "s|\./||g" | fzf --multi --preview "head -200 {}"
elif [[ "${search_type}" == "d" ]]; then
if tree --version &>/dev/null; then
find . -maxdepth 1 -type d | awk '{if ($0 != "." && $0 != "./.git"){gsub(/^\.\//, "", $0);print $0}}' | fzf --multi --preview "tree -L 1 -C --dirsfirst {}"
else
find . -maxdepth 1 -type d | awk '{if ($0 != "." && $0 != "./.git"){gsub(/^\.\//, "", $0);print $0}}' | fzf --multi
fi
fi
}