免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2651 | 回复: 8
打印 上一主题 下一主题

完美结合CLI和GUI的notify! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-09-13 19:15 |只看该作者 |倒序浏览
本帖最后由 jiannma 于 2010-09-13 19:36 编辑

作为一个大忙人,相信你经常开N个终端干活;作为一个CLI控,相信你也经常使用wget之类的工具下载东西。

你是否希望能在make完成、wget完成之后能有一个工具来通知你呢?为了追求效率总不可能盯着终端,或者经常切来切去地看吧?

现在隆重推出——notify:一个完美结合CLI和GUI的小工具,帮助CLI控们在做一些消耗时间的任务时,能在第一时间得到有效的提醒。

嗯,有图有真相:

应用场景:sudo apt-get update

这是用Deiban系的Linuxer经常执行的一条命令,而且会花点时间。何不用notify在update完后告诉你呢?


很简单,这样就用就行了:

notify sudo apt-get update





执行完这条命令后,你就可以去干其他事情了。

当update完成后,notification机制能非常有意思地提醒你:Cool~"sudo apt-get update" finished!





同理,如果你在./configure,make等很消耗时间的任务上,也可以这么做。

假设这次失败了,notify会说:Oh No! "./configure" failed!





哈哈,是不是很有意思呢?

实际上这只是一个非常简单的小脚本,但是对我来说非常有用。


test@cal ~: cat  notify.sh


  1. #!/bin/sh

  2. KERNEL=`uname -s`
  3. if [ $KERNEL == 'Linux' ]; then

  4. $* && \
  5. notify-send "Cool~ \"$*\" finished!" -i'emblem-cool' || \

  6. notify-send "Oh No! \"$*\" failed!" -i 'emblem-ohno'

  7. fi


复制代码
下载后直接放在$PATH路径下即可,另外建议在~/.bashrc中加入
    complete -o filenames -F _root_command notify

这样bash补全的时候会有比较好的效果。

Enjoy!

论坛徽章:
2
IT运维版块每日发帖之星
日期:2016-02-10 06:20:01IT运维版块每日发帖之星
日期:2016-02-11 06:20:00
2 [报告]
发表于 2010-09-13 19:33 |只看该作者
能否解释下complete使用说明

论坛徽章:
2
IT运维版块每日发帖之星
日期:2016-02-10 06:20:01IT运维版块每日发帖之星
日期:2016-02-11 06:20:00
3 [报告]
发表于 2010-09-13 19:42 |只看该作者
能不能解释下complete命令的用法及说明?

论坛徽章:
0
4 [报告]
发表于 2010-09-13 19:44 |只看该作者
本帖最后由 jiannma 于 2010-09-13 19:46 编辑

回复 2# nxlinux



test@cal ~: man complete  


   
complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix]
              [-X filterpat] [-F function] [-C command] name [name ...]
  complete -pr [name ...]
              Specify how arguments to each name should be completed.  If the -p option is supplied, or if no options are
supplied,  existing  completion specifications are printed in a way that allows them to be reused as input.  The -r
              option removes a completion specification for each name, or, if no names are supplied, all completion
             specifica- tions.

              The  process  of  applying  these completion specifications when word completion is attempted is described above
              under Programmable Completion.

              Other options, if specified, have the following meanings.  The arguments to the -G, -W, and -X options (and,  if
              necessary, the -P and -S options) should be quoted to protect them from expansion before the complete builtin is
              invoked

     -o comp-option
                      The comp-option controls several aspects of the compspec’s behavior beyond the simple generation
                    of completions.  comp-option may be one of:
                      bashdefault
                              Perform the rest of the default bash completions if the compspec generates no matches.
                      default Use readline’s default filename completion if the compspec generates no matches.
                      dirnames
                              Perform directory name completion if the compspec generates no matches.
                      filenames
                              Tell  readline  that  the  compspec generates filenames, so it can perform any filename-specific
                              processing (like adding a slash to directory names or suppressing trailing spaces).  Intended to
                              be used with shell functions.



      -F function
                      The shell function function is executed in the current shell environment.  When it finishes, the
                   possible completions are retrieved from the value of the COMPREPLY array variable.

论坛徽章:
0
5 [报告]
发表于 2010-09-14 09:25 |只看该作者
不错,掌声鼓励一下

论坛徽章:
0
6 [报告]
发表于 2010-09-14 10:12 |只看该作者
我觉得需要继续传递返回值。。。

论坛徽章:
2
狮子座
日期:2014-08-29 16:15:422015亚冠之阿尔纳斯尔
日期:2015-08-28 17:47:49
7 [报告]
发表于 2010-09-14 10:31 |只看该作者
Cool

论坛徽章:
0
8 [报告]
发表于 2010-09-14 16:57 |只看该作者
ub的fans啊

论坛徽章:
0
9 [报告]
发表于 2010-09-14 16:58 |只看该作者
好东西,赞一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP