Add some *grep

This commit is contained in:
Mathieu Maret 2018-04-27 15:39:33 +02:00
parent e145523147
commit 62b4c4eaa5
2 changed files with 35 additions and 0 deletions

View File

@ -102,6 +102,9 @@ cgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@" find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
} }
hgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
}
# Echo NULL separeted file if they exist # Echo NULL separeted file if they exist
displayExist(){ displayExist(){
while IFS= read -r -d '' f; do while IFS= read -r -d '' f; do
@ -117,6 +120,10 @@ jgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@" find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
} }
pygrep () {
find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.py" -print0 | xargs -0 grep --color -n "$@"
}
cjgrep () { cjgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name "*.java" \) -print0 | xargs -0 grep --color -n "$@" find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name "*.java" \) -print0 | xargs -0 grep --color -n "$@"
} }
@ -141,6 +148,10 @@ sepgrep() {
} }
docgrep () {
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.doc' -o -name '*.docx' -o -name '*.pdf' -o -name '*.odt' \) -print0 | xargs -i -0 docgrepfile {} "$@"
}
gettop () gettop ()
{ {

24
scripts/docgrepfile Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
file=$1
shift
if [[ ${file} == *.pdf ]]; then
pdfgrep -H "$@" "${file}"
elif [[ ${file} == *.doc ]]; then
grepoutput=$(catdoc "${file}" | grep -n --color "$@")
if [ $? -eq 0 ];then
echo "${file}:${grepoutput}"
fi
elif [[ ${file} == *.docx ]]; then
grepoutput=$(docx2txt < "${file}" | grep -n --color "$@")
if [ $? -eq 0 ];then
echo "${file}:${grepoutput}"
fi
elif [[ ${file} == *.odt ]]; then
grepoutput=$(odt2txt "${file}" | grep -n --color "$@")
if [ $? -eq 0 ];then
echo "${file}:${grepoutput}"
fi
else
grep -n --color $@ ${file}
fi