Skip to content

Instantly share code, notes, and snippets.

@y8
Created January 30, 2021 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y8/85098fc322fa861e68184e10dab189a3 to your computer and use it in GitHub Desktop.
Save y8/85098fc322fa861e68184e10dab189a3 to your computer and use it in GitHub Desktop.
alias apropos "$__fish_config_dir/patches/apropos.patched"
#!/bin/sh
#
# apropos -- search the whatis database for keywords.
# whatis -- idem, but match only commands (as whole words).
#
# Copyright (c) 1990, 1991, John W. Eaton.
# Copyright (c) 1994-1999, Andries E. Brouwer.
#
# You may distribute under the terms of the GNU General Public
# License as specified in the README file that comes with the man
# distribution.
#
# apropos/whatis-1.5m aeb 2003-08-01 (from man-1.6g)
#
# keep old PATH - 000323 - Bryan Henderson
# also look in /var/cache/man - 030801 - aeb
program=`basename $0`
# When man pages in your favorite locale look to grep like binary files
# (and you use GNU grep) you may want to add the 'a' option to *grepopt1.
aproposgrepopt1='i'
aproposgrepopt2=''
whatisgrepopt1='iw'
whatisgrepopt2=''
grepopt1=$aproposgrepopt1
grepopt2=$aproposgrepopt2
whatis_cache_path='/usr/local/var/db/apropos'
if [ $# = 0 ]
then
echo "usage: $program keyword ..."
exit 1
fi
manpath=`man --path | tr : '\040'`
if [ "$manpath" = "" ]
then
echo "$program: manpath is null"
exit 1
fi
args=
for arg in $*; do
case $arg in
--version|-V|-v)
echo "$program from man-1.6g"
exit 0
;;
--help|-h)
echo "usage: $program keyword ..."
exit 0
;;
-*)
echo "$program: $arg: unknown option"
exit 1
;;
*)
args="$args $arg"
esac
done
while [ "$1" != "" ]
do
found=0
for d in $manpath
do
whatis_cache="$whatis_cache_path$d"
if [ -f $d/whatis ]
then
if grep -"$grepopt1" "$grepopt2""$1" $d/whatis
then
found=1
# Some people are satisfied with a single occurrence
# But it is better to give all
# break
fi
# Check if cached version exists
elif [ -f $whatis_cache/whatis ]
then
if grep -"$grepopt1" "$grepopt2""$1" $whatis_cache/whatis
then
found=1
fi
else
# Build whatis database and store it in $whatis_cache_path
if [ -d $d ] && mkdir -p $whatis_cache && /usr/libexec/makewhatis.local "-o /dev/fd/1" $d | tee > $whatis_cache/whatis | grep -"$grepopt1" "$grepopt2""$1" $whatis_cache/whatis
then
found=1
# Some people are satisfied with a single occurrence
# But it is better to give all
# break
fi
fi
done
if [ $found = 0 ]
then
echo "$1: nothing appropriate"
fi
shift
done | eval ${PAGER:-more -E}
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment