Browse Source

Fix findinpkg.sh script

master
Pekka Helenius 4 years ago
parent
commit
ed043476bd
1 changed files with 18 additions and 20 deletions
  1. +18
    -20
      tools/findinpkg.sh

+ 18
- 20
tools/findinpkg.sh View File

@ -9,7 +9,7 @@ function help() {
exit exit
} }
if [[ $# -ne 2 ]]; then
if [[ ${#@} -ne 2 ]]; then
help help
fi fi
@ -25,29 +25,27 @@ lines_total=0
files_total=0 files_total=0
esc=$(printf '\033') esc=$(printf '\033')
separate() {
linenro=$(printf '%s' ${1} | sed -r 's/^.*?:([0-9]+$)/\1/')
filename_=$(printf '%s' ${1} | sed -r 's/^(.*?):[0-9]+$/\1/')
if [[ "${filename}" == "" ]]; then filename=${filename_}; fi
let lines_total++
if [[ ! "${filename}" == "${filename_}" ]]; then
echo "${esc}[35m${filename}${esc}[92m: ${esc}[31m${lines[*]}${esc}[0m"
let files_total++
lines=()
fi
filename="${filename_}"
lines+=(${linenro})
let lines_total++
}
for file in $(pacman -Ql "${1}" | sed "s/^${1}\s//g"); do for file in $(pacman -Ql "${1}" | sed "s/^${1}\s//g"); do
if [[ -f "${file}" ]]; then if [[ -f "${file}" ]]; then
line=$(grep --line-number --with-filename --binary-files=without-match -i "${2}" "${file}" | sed -r "s/^(.*?:)([0-9]+):.*/\1\2/g") line=$(grep --line-number --with-filename --binary-files=without-match -i "${2}" "${file}" | sed -r "s/^(.*?:)([0-9]+):.*/\1\2/g")
for l in ${line[@]}; do for l in ${line[@]}; do
separate "${l}"
linenum=$(printf '%s' ${l} | sed -r 's/^.*?:([0-9]+$)/\1/')
filename_=$(printf '%s' ${l} | sed -r 's/^(.*?):[0-9]+$/\1/')
lines+=(${linenum})
if [[ ! "${filename}" == "${filename_}" ]]; then
echo "${esc}[35m${filename_}${esc}[92m: ${esc}[31m${lines[*]}${esc}[0m"
lines_total=$(( ${lines_total} + ${#lines[@]} ))
let files_total++
lines=()
fi
filename="${filename_}"
done done
fi fi
done done
printf "\nFound %d matching lines for pattern '%s' in %d files in %s package.\n" ${lines_total} "${2}" ${files_total} "${1}"
printf "\nFound %d matching lines for pattern '%s' in %d files in package '%s'.\n\n" ${lines_total} "${2}" ${files_total} "${1}"

Loading…
Cancel
Save