在ubuntu的nautilus窗口(对应的就是windows中的资源管理器)中打开目录,有时候想在当前窗口打开终端进行操作,如果选择菜单-》应用程序-》附件-》终端,然后再cd到该目录下,对于我这样的懒人来说,是一件非常麻烦的事。于是我就想,有没有办法通过快捷键直接在当前窗口启动终端?
动手之前,先搜索一番。找到了一个脚本:
1
#
!
/
bin
/
bash
2 # This script opens a gnome-terminal in the directory you select .
3 # Distributed under the terms of GNU GPL version 2 or later
4 # Install in ~ /. gnome2 / nautilus-scripts or ~ / Nautilus / scripts
5 # You need to be running Nautilus 1.0 . 3 + to use scripts .
6 # When a directory is selected , go there . Otherwise go to current
7 # directory . If more than one directory is selected , show error .
8
9 if [ -n " $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS " ] ; then
10 set $ NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
11 if [ $# -eq 1 ] ; then
12 destination = " $1 "
13
14 # Go to file's directory if it's a file
15 if [ ! -d " $destination " ] ; then
16 destination = " `dirname " $ destination " ` "
17 fi
18 else
19 zenity --error --title = " Error - Open terminal here " \
20 --text = " You can only select one directory. "
21 exit 1
22 fi
23 else
24 destination = " `echo " $ NAUTILUS_SCRIPT_CURRENT_URI " | sed 's/^file:\/\///'` "
25 fi
26
27 # It's only possible to go to local directories
28 if [ -n " `echo " $ destination " | grep '^[a-zA-Z0-9]\+:'` " ] ; then
29 zenity --error --title = " Error - Open terminal here " \
30 --text = " Only local directories can be used. "
31 exit 1
32 fi
33
34 cd " $destination "
35 exec x-terminal-emulator
2 # This script opens a gnome-terminal in the directory you select .
3 # Distributed under the terms of GNU GPL version 2 or later
4 # Install in ~ /. gnome2 / nautilus-scripts or ~ / Nautilus / scripts
5 # You need to be running Nautilus 1.0 . 3 + to use scripts .
6 # When a directory is selected , go there . Otherwise go to current
7 # directory . If more than one directory is selected , show error .
8
9 if [ -n " $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS " ] ; then
10 set $ NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
11 if [ $# -eq 1 ] ; then
12 destination = " $1 "
13
14 # Go to file's directory if it's a file
15 if [ ! -d " $destination " ] ; then
16 destination = " `dirname " $ destination " ` "
17 fi
18 else
19 zenity --error --title = " Error - Open terminal here " \
20 --text = " You can only select one directory. "
21 exit 1
22 fi
23 else
24 destination = " `echo " $ NAUTILUS_SCRIPT_CURRENT_URI " | sed 's/^file:\/\///'` "
25 fi
26
27 # It's only possible to go to local directories
28 if [ -n " `echo " $ destination " | grep '^[a-zA-Z0-9]\+:'` " ] ; then
29 zenity --error --title = " Error - Open terminal here " \
30 --text = " Only local directories can be used. "
31 exit 1
32 fi
33
34 cd " $destination "
35 exec x-terminal-emulator
将该脚本拷到主目录的./gnome2/nautilus-scripts下,任意起个名字(例如“打开终端”),chmod 777.就ok了。
测试一下:
在任意窗口,右键-》脚本-》“打开终端”(就是脚本的名字)。
果然就打开了一个终端,并且也自动切换到了当前目录。这正是我想要的!
(该脚本是基于nautilus的,估计不仅ubuntu,所有使用nautilus的系统应该都可以运行这个脚本。)