sh/bash/dash/ksh/zsh等Shell脚本
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#1
帖子
由 eexpress » 2009-03-10 13:38
鼠标选择文字,根据不同的正则匹配,执行不同的命令。这里是查阅ip,打开地址,和缺省的翻译。
加到热键:Super+A
代码: 全选
#!/bin/bash
l=`xsel -o`
reg[0]="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
reg[1]="^http://[^\ ]*$"
#reg[2]="^[A-Za-z]*$"
cmd[0]="~/应用/脚本/ip-show.bash"
cmd[1]="~/应用/脚本/opera-open-file $l"
#cmd[2]="~/应用/脚本/sdcv-notify-send.bash"
n=${#reg[*]}
#for i in ${reg[*]}
for i in `seq $n`
do
#echo $l
#echo ${reg[$i-1]}
if [[ $l =~ ${reg[$i-1]} ]]; then
#echo ${cmd[$i-1]}
eval ${cmd[$i-1]}
exit
fi
done
#default cmd
~/应用/脚本/sdcv-notify-send.bash
反正glipper 的Actions不对头。klipper的别人也说不对。
可能是正则匹配,是使用的语法内嵌正则库,导致表达式不需要转义那些括号类的。使用这2个软件的,可参考如上脚本的写法试试。
● 鸣学
-
c\nc
- 帖子: 231
- 注册时间: 2007-12-25 12:51
#2
帖子
由 c\nc » 2009-03-10 14:40
加个判断怎么样? xsel 还有 3 个参数:
-p, --primary
operate on the PRIMARY selection (default).
-s, --secondary
operate on the SECONDARY selection.
-b, --clipboard
operate on the CLIPBOARD selection.
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#3
帖子
由 eexpress » 2009-03-10 14:43
The ICCCM defines these as follows:
"The selection named by the atom PRIMARY is used for all commands that take only a single argument and is the principal means of communication between clients that use the selection mechanism.
The selection named by the atom SECONDARY is used:
As the second argument to commands taking two arguments (for
example, "exchange primary and secondary selections")
As a means of obtaining data when there is a primary selection and
the user does not want to disturb it
加参数?我根本不使用ctrl-c的。那clipboard没意义。而secondary被废弃了的。
现在是没法监视剪贴板而已。不归dbus管理。在瞎看。
● 鸣学
-
zhan
- 帖子: 1880
- 注册时间: 2005-08-15 0:04
- 来自: 南7技校
#5
帖子
由 zhan » 2009-03-10 15:28
依依的哲学就是生命在于折腾,不仅自己折腾,还会拉着别人折腾。。。
lerosua 写了:ee尽在折腾
-
roylez
- 帖子: 1928
- 注册时间: 2005-10-04 10:59
- 来自: 上海
#6
帖子
由 roylez » 2009-03-10 17:42
我的python脚本放在那里好久了,还带手机归属地查询呢,ee就喜欢造新轮子。
-
greco
- 帖子: 2487
- 注册时间: 2007-04-06 10:24
- 来自: ~/Shanghai
#7
帖子
由 greco » 2009-03-10 18:46
这有啥用,麻不麻烦
好好的正则就被你们这么折腾
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#8
帖子
由 eexpress » 2009-03-11 9:20
roylez, 你的py监视剪贴板更新了?只有做到这点,才可以代替glipper/klipper里面的正则动作。
要不,何用啊。
再说py的,怎么会比bash的简单/通用的。还不是你不用bash。lol
我这用在fvwm的,整合热键的。
btw: 不利用系统已经带了的命令,才叫重新造轮子呢,比如py。呵呵。
● 鸣学
-
roylez
- 帖子: 1928
- 注册时间: 2005-10-04 10:59
- 来自: 上海
#9
帖子
由 roylez » 2009-03-11 9:40
你见过哪个发行版默认不带python的?
监视剪切板干什么?没必要为这个又搞个daemon,就是说你那语音控制的,也是一样。我不喜欢太多daemon。原来弄过perlbox的,玩过一次就烦了。
btw,发现一好玩的。scim输入itime,idate。
-
bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
-
联系:
#10
帖子
由 bones7456 » 2009-03-11 10:02
zhan 写了:依依的哲学就是生命在于折腾,不仅自己折腾,还会拉着别人折腾。。。
lerosua 写了:ee尽在折腾
ee怎么不听胡主席的话啊?
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#11
帖子
由 eexpress » 2009-03-11 10:15
怎么说到缺省带不带的问题了。而且这点上py肯定比不过bash/perl的啊。perlbox我去看看。
监视剪切板,是为了剩下按热键。有好处的。有想不到的好处的。
scim的,我早总结过啊。
btw: 其他说折腾的,都是不会正则和shell的。可以无视。
● 鸣学
-
aBiNg
- 帖子: 1331
- 注册时间: 2006-07-09 12:22
- 来自: 南京
#12
帖子
由 aBiNg » 2009-03-11 10:41
代码: 全选
#!/bin/bash
sel=`xsel -o`
if [ $sel =~ "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" ]; then
. ~/应用/脚本/ip-show.bash
elif [ $sel =~ "^http://[^\ ]*$" ]; then
. ~/应用/脚本/opera-open-file $sel
fi
~/应用/脚本/sdcv-notify-send.bash
搞那复杂做什么啊。