【问题标题】:How to make Terminal suggest custom command's option?如何让终端建议自定义命令的选项?
【发布时间】:2015-01-26 18:18:29
【问题描述】:

我是 Kubuntu 用户。

如果我输入

$ apt-get (tab)

在终端上,Shell 建议选项:
自动清理、构建-dep、检查、...、清理、下载、安装、删除、更新

如果我想在路径中使用别名或 shell 脚本的选项来使用自定义命令,我怎样才能让终端(或 Shell)建议选项?


例如,命令是“myclock”,它的选项是“us”和“korea”。

如果我输入

$ myclock 韩国

->(打印韩国时间)

如果我输入

$ myclock 我们

->(打印美国时间)

输入时如何让终端建议选项(“我们”或“韩国”)

$ myclock(标签)

提前谢谢!

【问题讨论】:

    标签: linux shell ubuntu terminal console


    【解决方案1】:

    您需要通过 .bash_profile 或 kubuntu .profile 添加自定义别名

    sudo 进入 root 并使用您选择的文本编辑器。我更喜欢 vi 但你可以使用 nano!

     sudo -i
      root@server vi .profile
    

    默认情况下,您的个人资料应如下所示

    if [ "$BASH" ]; then
      if [ -f ~/.bashrc ]; then
        . ~/.bashrc
      fi
    fi
    
    mesg n
    

    所以现在添加一个别名。你可以为你的别名命名任何东西!这是我使用的 .profile 的自定义别名。我在旧金山工作,住在奥克兰,所以天气可能会略有不同,所以我创建了一个自定义别名来为天气卷曲

    alias weatherSF="curl -s 'http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=en|us|san-francisco-ca|94103' | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'"
    alias weatherOak="curl -s 'http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=en|us|Oakland-ca|94612' | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'"
    

    现在请注意,如果您尝试使用标签,它不会起作用..所以您需要做的是

    source ~/.profile
    

    在来源之后,您应该能够标记您的新别名!

    如果您对其他别名感兴趣,这里有一些其他示例

    alias myip='curl ip.appspot.com'                    # myip:         Public facing IP Address
    alias netCons='lsof -i'                             # netCons:      Show all open TCP/IP sockets
    alias flushDNS='dscacheutil -flushcache'            # flushDNS:     Flush out the DNS Cache
    alias lsock='sudo /usr/sbin/lsof -i -P'             # lsock:        Display open sockets
    alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP'   # lsockU:       Display only open UDP sockets
    alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP'   # lsockT:       Display only open TCP sockets
    alias ipInfo0='ipconfig getpacket en0'              # ipInfo0:      Get info on connections for en0
    alias ipInfo1='ipconfig getpacket en1'              # ipInfo1:      Get info on connections for en1
    alias openPorts='sudo lsof -i | grep LISTEN'        # openPorts:    All listening connections
    alias showBlocked='sudo ipfw list'                  # showBlocked:  All ipfw rules inc/ blocked IPs
    

    check this website for some tips

    【讨论】:

      猜你喜欢
      • 2020-07-23
      • 2020-12-31
      • 2011-07-24
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      相关资源
      最近更新 更多