Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function tex_search (
- TEX_PKGS_DIR=/usr/share/texlive/texmf-dist/tex/
- echo -n Looking for \\$1 in $TEX_PKGS_DIR ...
- # This amount of needed \\ is because we're doing escapes for bash strings and also for grep.
- results_fname=$(mktemp)
- find $TEX_PKGS_DIR -type f \( -iname '*.tex' -or -iname '*.sty' -or -iname '*.cls' \) -exec grep -Ei "(command|cmd|new|def|decl)[^\\\\]*\\\\$1[^a-zA-Z]" '{}' + | grep "\\\\$1[^a-zA-Z]" > $results_fname
- echo ' (done)'
- echo
- echo Found possible symbol definition for \\$1 in files:
- # read -r makes it treat backslash not as an escape character, but as part of the string.
- cat $results_fname | while read -r occur
- do
- basename $(echo $occur | cut -d ':' -f 1)
- done | sort -u | tr '\n' '\t' | fmt
- echo
- echo Full results:
- cat $results_fname | while read -r occur
- do
- full_path=$(echo $occur | cut -d ':' -f 1)
- code=$(echo $occur | cut -d ':' -f 2)
- full_dir=$(dirname $full_path)
- dir=${full_dir#*$TEX_PKGS_DIR}
- echo $(basename $full_path) in $dir
- echo -en "\t"
- echo $code | tr -d '\n' | grep -i "\\\\$1" --color=always
- done
- rm $results_fname
- )
- # The option -R in less is so that it handle colors well.
- tex_search "$1" | less -R
Advertisement
Add Comment
Please, Sign In to add comment