#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/cid setopt extendedglob search-docu () { # input local key=$1 local archive=$2 # e.g., "rfc" local docpath=$3 # "/usr/share/doc/RFC" # search local files=("${(@f)$(\grep -i -w $key -l ${docpath}/**/*.(gz|info|txt)(.))}") # fallout local hits local occs local filename # output local occs_str local archive_str for f in $files; do hits=$(\grep -w -c -H -i $key $f) occs=${hits##*:} filename=${hits%:*} occs_str=${(l:3:: :::)${occs}} archive_str=${(r:10:: :::)${archive}} echo "${occs_str} ${archive_str}${filename}" done } # $ sudo apt-get install doc-rfc search-rfc () { local key=$1 search-docu $key "rfc" "/usr/share/doc/RFC" } # $ sudo apt-get install jargon-text # $ sudo gunzip -k /usr/share/doc/jargon-text/jargon.txt.gz search-jargon () { local key=$1 search-docu $key "jargon" "/usr/share/doc/jargon-text" } search-emacs () { local key=$1 search-docu $key "emacs" "/usr/share/info/emacs-24" } search-man () { local key=$1 search-docu $key "manpage" "/usr/share/man" } cid () { local args=($@) local key # default: search _all_ bodies local do_emacs_search=true local do_jargon_search=true local do_man_search=true local do_rfc_search=true local a for a in $args; do if [[ $a[1] == '-' ]]; then # option: don't do any searches... do_emacs_search=false do_jargon_search=false do_man_search=false do_rfc_search=false # ...except the one(s) specified case $a[2] in ('e') do_emacs_search=true ;; ('j') do_jargon_search=true ;; ('m') do_man_search=true ;; ('r') do_rfc_search=true ;; (*) echo "options are -e, -j, -m, and -r" >&2 return ;; esac else # not an option, so its the search key key=$a fi done { ($do_emacs_search) && search-emacs $key ($do_jargon_search) && search-jargon $key ($do_man_search) && search-man $key ($do_rfc_search) && search-rfc $key } | sort -nr }