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的菜单,在这个菜单下才是我们新建的脚本的文件名,所以显得有些不方便。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端