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


这时间放假,闲在家里无聊,所以,每天就看看书,写写程序,,,,当然,,在我的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"
  • 1
  • 2
  • 下一页

相关内容