ubuntu中为vscode添加右键菜单--网上没有—就自己做了个
Ubuntu 添加右键菜单项
在 ubuntu 中,经常是 open-in-terminal,然后执行相应命令,想起之前一个工具的 readme 中处理过添加到右键的办法,查找一下相关用法:
在$HOME/.local/share/nautilus/script/添加相关执行文件
此时我们知道了应该去$HOME/.local/share/nautilus/script/目录下面添加脚本:
新建一个 文件 ,文件名任意(这个文件名会显示在右键菜单里,最好是通俗易懂的,文件内容如下。
-
#!/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 visual-studio-code "$destination"
添加完后,把此文件加上可执行的权限。
chmod +x 刚才创建的文件名
第二种方法建出来的是一个二级菜单,它先是在右键菜单中添加一个名叫scripts的菜单,在这个菜单下才是我们新建的脚本的文件名,所以显得有些不方便。