用bash-completion 实现pman自动补全


前言

每次查php函数的用法,都要查看手册,感觉好麻烦,于是决心在自己的命令行里实现pman自动补全


提示:以下是本篇文章正文内容,下面案例可供参考

一、安装

先安装pear命令。不是本文重点,请自行查阅

Manual :: Installation (PEAR)

执行命令

pear install doc.php.net/pman

二、直接使用

代码如下(示例):

pman gettype

结果如下 

三、按装 bash-completion

先安装EPEL。不是本文重点,请自行查阅php manal

执行命令

yum install bash-completion

接着还需要在指定目录(bash-completion存放其驱动脚本的目录,不同版本可能略有区别,)做一个软连接以便激活脚本:

 ln -s /usr/share/bash-completion/completions/pman /etc/bash_completion.d/pman

我的 bash-completion 脚本可以看下面的代码

cat /usr/share/bash-completion/completions/pman
# pman(1) completion

#have pman &&
_pman()
{
    local cur manpath

    COMPREPLY=()

    cur="${COMP_WORDS[COMP_CWORD]}"

    manpath="$(tail -n 1 $(which pman))"
    manpath="$(echo ${manpath%/*} | awk '{print $NF}')"

    if [ -n "$cur" ]; then
        COMPREPLY=($manpath/man*/$cur*)
    else
        COMPREPLY=($manpath/man*/*)
    fi

    COMPREPLY=(${COMPREPLY[@]##*/})
    COMPREPLY=(${COMPREPLY[@]%.*.*})

    COMPREPLY=($(compgen -W '${COMPREPLY[@]}' -- "$cur"))

    return 0
} &&
complete -F _pman pman

最后运行一下

source /etc/bash_completion.d/pman
root@jianchao ~]# pman get
get_browser                 get_extension_funcs         getallheaders               getmyinode
get_called_class            get_headers                 getcwd                      getmypid
get_cfg_var                 get_html_translation_table  getdate                     getmyuid
get_class                   get_include_path            getenv                      getopt
get_class_methods           get_included_files          gethostbyaddr               getprotobyname
get_class_vars              get_loaded_extensions       gethostbyname               getprotobynumber
get_current_user            get_magic_quotes_gpc        gethostbynamel              getrandmax
get_declared_classes        get_magic_quotes_runtime    gethostname                 getrusage
get_declared_interfaces     get_meta_tags               getimagesize                getservbyname
get_declared_traits         get_object_vars             getimagesizefromstring      getservbyport
get_defined_constants       get_parent_class            getlastmod                  gettext
get_defined_functions       get_required_files          getmxrr                     gettimeofday
get_defined_vars            get_resource_type           getmygid                    gettype
[root@jianchao ~]# pman get_browser 

打完收功!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

游思宇影

您的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值