手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu下编写SHELL实现右键用VIM打开指定文件

[日期:2010-02-13] 来源:www.oscoder.cn  作者:望水 [字体:大 中 小]

这时间放假,闲在家里无聊,所以,每天就看看书,写写程序,,,,当然,,在我的Ubuntu 9.10下,我还是列喜欢那个VIM,,,支持一些快捷的操作和可以运行一些外部命令。不过呢,在选择编辑某个文件时,却用VIM打开是个麻烦,每次先开一个终端,然后进入文件目录下。。。后来,自然而然的就想到把打开某个文件的指令加到右键菜单当中。。。我写了个SHELL,当然这个SHELL很简单,没用到与此正则,也没有太多的指令。如下:

Ubuntu下编写SHELL实现右键用VIM打开指定文件
Ubuntu下编写SHELL实现右键用VIM打开指定文件
#!/bin/bash
# 这是一个通过Shell调用VI编辑器来打开
# 选定文件的脚本程序。
# 作者:望水
# Email:csauthor@gmail.com
# 个人网站:http://www.oscoder.cn
# Distributed under the terms of GNU GPL version2 or later
#
# install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts
# You need to be running Nautilus 1.0.3+ to use scripts.
# When a directory is selected, go there. Otherwise go to current
# directory. If more than one directory is selected, show error.
if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ];then
	set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
	if [ $# -eq 1 ];then
		destination="$1"
		if [ -f "$destination" ];then
			destination="$1"
		else
			zenity --error --title="Error-Open Vi here"\
			--text="You can only select a file that Vi supported!"
			exit 1
		fi
	else
		zenity --error --title="Error-Open Vi here"\
		--text="Only select the one file."
		exit 1
	fi
fi
exec x-terminal-emulator -e vi "$destination"
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款