LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1300|回复: 2

xdg-open只支持kde,gnome,xfce大型wm,让它也支持FVWM,FLUXBOX,OPENBOX等轻量wm.

[复制链接]
发表于 2009-11-21 23:45:06 | 显示全部楼层 |阅读模式
根据http://bugs.gentoo.org/220915
修改xdg-open,让它也支持轻量wm,解决了xarchiver总用firefox打开文件和firefox打开下载文件的问题.
将open_generic()函数修改为:
  1. open_generic()
  2. {
  3.    if [ '`echo "$url" | grep ^file://`' ] ; then
  4.       url=`echo "$url" | sed "s/^file\:\/\///"`
  5.    fi
  6.    mimetype=`xdg-mime query filetype "$url" |cut -f 1 -d \;`
  7.    echo "$mimetype"
  8.    opener=`xdg-mime query default $mimetype | xargs cat | grep ^Exec | cut -f 2 -d = |cut -f 1 -d \ `
  9.    if [ -z "${opener}" ] ; then
  10.    #   exit_failure_operation_impossible "no method available for opening '$url'"
  11.    opener=firefox
  12.   fi
  13.    echo "$opener"
  14.    "$opener" "$url"
  15. }
复制代码
然后xdg-open myfvwm.tar.gz
获得mime类型application/x-gzip
然后xdg-mime default /usr/share/applications/xarchiver.desktop application/x-gzip
指定用xarchiver打开x-gzip类型文件
再运行xdg-open myfvwm.tar.gz,就用xarchiver打开了.
xdg-mime default /usr/share/applications/rox-rox.desktop application/x-directory设置rox为默认文件管理器
注:xdg-mime命令修改的是~/.local/share/applications/defaults.list.

又发现个更详细的帖子:http://forum.ubuntu.org.cn/viewt ... 41781&view=next
发表于 2009-11-22 00:26:49 | 显示全部楼层
以后都用gio就好了,就没这个问题了。。虽然我不太喜欢gvfs。。但是这个东西规范应该更早的时候就做出。。这样文件管理器也会非常简单
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-11-23 00:44:20 | 显示全部楼层
又发现xdg-mime对轻量wm,调用file来获取mime类型,好多类型(比如ods,flv,7z)不能得到正确的mime类型,最完美的解决办法,修改open_generic()如下:
  1. open_generic()
  2. {
  3.     if [ '`echo "$url" | grep ^file://`' ] ; then
  4.       url=`echo "$url" | sed "s/^file\:\/\///"`
  5.     fi
  6.     opener=rox
  7.     "$opener" "$url"
  8. }
复制代码
如果你用pcmanfm,更简单:
  1. open_generic()
  2. {
  3.     opener=pcmanfm
  4.     "$opener" "$url"
  5. }
复制代码
这样只用将rox,pcmanfm的打开方式设置好,就行了!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表