mank - dotfiles - leot's dotfiles
 (HTM) hg clone https://bitbucket.org/iamleot/dotfiles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       mank
       ---
            1 #!/bin/sh
            2 #
            3 # AUTHOR: Leonardo Taccari
            4 #
            5 # DATE: Mon Oct 23 21:00:04 CEST 2017
            6 #
            7 # DESC: Elvi to search the man-k.org man pages
            8 # elvis: mank           -- Search man-k.org for Unix man pages
            9 . surfraw || exit 1
           10 
           11 w3_config_hook() {
           12 defyn   SURFRAW_mank_freebsd    no
           13 defyn   SURFRAW_mank_netbsd     no
           14 defyn   SURFRAW_mank_openbsd    no
           15 }
           16 
           17 w3_usage_hook () {
           18     cat <<EOF
           19 Usage: $w3_argv0 [options] [search-string | man]...
           20 Description:
           21   Search Unix man pages via man-k.org
           22 Local options:
           23   -freebsd[=(yes|no)]           Search for FreeBSD man pages
           24                                 Default: $SURFRAW_mank_freebsd
           25                                 Environment: SURFRAW_mank_freebsd
           26   -netbsd[=(yes|no)]            Search for NetBSD man pages
           27                                 Default: $SURFRAW_mank_netbsd
           28                                 Environment: SURFRAW_mank_netbsd
           29   -openbsd[=(yes|no)]           Search for OpenBSD man pages
           30                                 Default: $SURFRAW_mank_openbsd
           31                                 Environment: SURFRAW_mank_openbsd
           32 Examples:
           33   $w3_argv0                     Go to man-k.org website
           34   $w3_argv0 list files          Search for man pages regarding list files
           35   $w3_argv0 -freebsd man(1)     Show the FreeBSD man(1) page
           36   $w3_argv0 -netbsd man(1)      Show the NetBSD man(1) page
           37   $w3_argv0 -openbsd man(1)     Show the OpenBSD man(1) page
           38 EOF
           39     w3_global_usage
           40 }
           41 
           42 w3_parse_option_hook () {
           43     opt="$1"
           44     optarg="$2"
           45     case "$opt" in
           46         -freebsd)    setoptyn    SURFRAW_mank_freebsd    yes     ;;
           47         -freebsd=)   setoptyn    SURFRAW_mank_freebsd    $optarg ;;
           48         -netbsd)     setoptyn    SURFRAW_mank_netbsd     yes     ;;
           49         -netbsd=)    setoptyn    SURFRAW_mank_netbsd     $optarg ;;
           50         -openbsd)    setoptyn    SURFRAW_mank_openbsd    yes     ;;
           51         -openbsd=)   setoptyn    SURFRAW_mank_openbsd    $optarg ;;
           52         *) return 1 ;;
           53     esac
           54     return 0
           55 }
           56 
           57 w3_config
           58 w3_parse_args "$@"
           59 # w3_args now contains a list of arguments
           60 test -z "$w3_args" || escaped_args=`w3_url_of_arg $w3_args`
           61 
           62 if ok SURFRAW_mank_freebsd; then
           63     if test -z "$escaped_args"; then
           64         w3_browse_url "http://man-k.org/"
           65     else
           66         w3_browse_url "http://man-k.org/f/${escaped_args}"
           67     fi
           68     exit $?
           69 fi
           70 if ok SURFRAW_mank_netbsd; then
           71     if test -z "$escaped_args"; then
           72         w3_browse_url "http://man-k.org/"
           73     else
           74         w3_browse_url "http://man-k.org/n/${escaped_args}"
           75     fi
           76     exit $?
           77 fi
           78 if ok SURFRAW_mank_openbsd; then
           79     if test -z "$escaped_args"; then
           80         w3_browse_url "http://man-k.org/"
           81     else
           82         w3_browse_url "http://man-k.org/o/${escaped_args}"
           83     fi
           84     exit $?
           85 fi
           86 if test -z "$escaped_args"; then
           87     w3_browse_url "http://man-k.org/"
           88 else
           89     escaped_args=`w3_url_of_arg $w3_args`
           90     w3_browse_url "http://man-k.org/search?q=${escaped_args}"
           91 fi
           92 exit $?