2012年7月12日星期四

ubuntu在右键菜单中添加打开终端快捷方式

在linux中经常用到的终端,在ubuntu中打开就比较麻烦了,需要先打开dash,在搜索终端或者terminal,在点选图标,如果幸运,或者可以直接按回车,但无论怎样,都感觉很麻烦啊!

要是可以在文件管理窗口的右键菜单中添加直接打开终端的快捷方式就好了!对于nautilus文件管理器来说,这个是完全可以实现的,因为该管理器支持脚本。

首先我们需要在nautilus检查脚本的地方添加一个脚本文件

首先在你喜欢的任何地方新建一个空白文档,例如桌面上,名字是任意的,但是这个名字最终将会在你的右键菜单上显示出来

然后打开文档,把以下我从google上找到的代码复制进去
#!/bin/bash
#
# This script opens a gnome-terminal in the directory you select.
#
# Distributed under the terms of GNU GPL version 2 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"
# Go to file's directory if it's a file
if [ ! -d "$destination" ]; then
destination="`dirname "$destination"`"
fi
else
zenity --error --title="Error - Open terminal here" \
--text="You can only select one directory."
exit 1
fi
else
destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`"
fi

# It's only possible to go to local directories
if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then
zenity --error --title="Error - Open terminal here" \
--text="Only local directories can be used."
exit 1
fi

cd "$destination"
exec x-terminal-emulator

保存文档,再在终端进入到你新建文档的地方,并且执行以下命令:

sudo chmod +x 你的文档名
sudo cp 你的文档名   ~/.gnome2/nautilus-scripts

好,完成了,以后你可以直接在文件管理器上直接右键进入终端了,而且还很智能识别出当前文件夹目录。

对于动脚本语言的人,其实还可以写很多其他功能,并且添加进入,例如修改权限等,暂时我还不懂脚本语言呢,有什么需要的功能以后再添加吧

没有评论:

发表评论