歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Ubuntu下編寫SHELL實現右鍵用VIM打開指定文件

Ubuntu下編寫SHELL實現右鍵用VIM打開指定文件

日期:2017/2/28 16:39:24   编辑:SHELL編程

這時間放假,閒在家裡無聊,所以,每天就看看書,寫寫程序,,,,當然,,在我的Ubuntu 9.10下,我還是列喜歡那個VIM,,,支持一些快捷的操作和可以運行一些外部命令。不過呢,在選擇編輯某個文件時,卻用VIM打開是個麻煩,每次先開一個終端,然後進入文件目錄下。。。後來,自然而然的就想到把打開某個文件的指令加到右鍵菜單當中。。。我寫了個SHELL,當然這個SHELL很簡單,沒用到與此正則,也沒有太多的指令。如下:

#!/bin/bash
# 這是一個通過Shell調用VI編輯器來打開
# 選定文件的腳本程序。
# 作者:望水
# Email:[email protected]
# 個人網站: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"
Copyright © Linux教程網 All Rights Reserved