From 62b4c4eaa59273dcc00040b1c1fce7b8236e4dc0 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Fri, 27 Apr 2018 15:39:33 +0200 Subject: [PATCH] Add some *grep --- .zsh/40_function.zsh | 11 +++++++++++ scripts/docgrepfile | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 scripts/docgrepfile diff --git a/.zsh/40_function.zsh b/.zsh/40_function.zsh index 037393c..fdd38f6 100755 --- a/.zsh/40_function.zsh +++ b/.zsh/40_function.zsh @@ -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 "$@" } +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 displayExist(){ 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 "$@" } +pygrep () { + find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.py" -print0 | xargs -0 grep --color -n "$@" +} + 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 "$@" } @@ -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 () { diff --git a/scripts/docgrepfile b/scripts/docgrepfile new file mode 100755 index 0000000..1c7678c --- /dev/null +++ b/scripts/docgrepfile @@ -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