2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-16 00:12:47 +00:00

feat(fgrep): added option to configure search delimiter

This commit is contained in:
Kevin Zhuang 2020-08-03 21:59:31 +10:00
parent ce041753ff
commit 77657d3eb8
2 changed files with 13 additions and 2 deletions

View File

@ -202,11 +202,12 @@ function get_stash() {
#######################################
function grep_words() {
local header="${1:-select matches to edit}"
local delimiter="${2:-3}"
set_fzf_multi "$2"
cd "${DOTBARE_TREE}" || exit
git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
grep --line-number -- . \
| fzf --delimiter : --nth 3.. --header="${header}" \
| fzf --delimiter : --nth "${delimiter}".. --header="${header}" \
--preview "${mydir}/../helper/preview.sh ${DOTBARE_TREE}/{}" \
| awk -F ":" -v home="${DOTBARE_TREE}" '{
print home "/" $1 ":" $2

View File

@ -26,9 +26,19 @@ Optional arguments:
}
selected_lines=()
fzf_search_delimiter=3
while [[ "$#" -gt 0 ]]; do
case "$1" in
-d|--delimiter)
fzf_search_delimiter="$2"
shift
shift
;;
-f|--full)
fzf_search_delimiter=1
shift
;;
-h|--help)
usage
exit 0
@ -52,7 +62,7 @@ while IFS= read -r line; do
selected_lines+=("${line}")
;;
esac
done < <(grep_words)
done < <(grep_words "select matches to edit" "${fzf_search_delimiter}")
[[ "${#selected_lines[@]}" -eq 0 ]] && exit 1