vscode快捷键运行shell脚本实现一键编译
由于在服务器编译比较快,但服务器没有rviz、rqt等等可视化,所以开发工作在服务器进行,将编译完成后的文件拷贝到本地电脑上进行可视化调试。编写一个脚本,通过vscode配置一下,可以实现快捷键一键操作。
1. 脚本示例
shell脚本在服务器运行,文件路径为/jl/perception_ws/copy_all.sh, 远程主机ip为172.18.119.40。
#!/bin/bash
catkin_make install
TARGET=juling@172.18.119.40:/home/juling/Documents/iplus/install/
rsync -avz --progress install/ "$TARGET"
以上脚本作用为编译ros工作空间并install,将服务器下install目录拷贝到远程主机的指定文件夹下。不同于scp命令,rsync命令可以只拷贝发生变化的文件,避免只改了一个动态库,每次都要重新拷贝所有动态库,减少拷贝时间。scp和rsync需要两台主机在同一局域网下才能使用。
另外如果不配置一下,scp或rsync命令每次使用都需要输入远程主机密码。
配置方法:
服务器主机端执行
ssh-keygen -t rsa
一路回车,不要设置密码,然后执行
ssh-copy-id juling@172.18.119.40
输入一次密码后,以后所有ssh/scp都免密
如果想确认免密登录是否生效,可以直接测试:ssh juling@172.18.119.40
如果能直接登录而不要求输入密码,说明配置成功。如果仍然需要输入密码,说明密钥没有被正确识别或放置。
ls ~/.ssh/
执行以上命令,确认是否有:
id_rsa_julinger
id_rsa_julinger.pub
手动指定使用的私钥登录测试,如果手动指定私钥不需要输入密码,说明密钥本身没问题,只是系统默认没用它。
ssh -i ~/.ssh/id_rsa_julinger juling@172.18.119.40
在服务器端执行以下命令
cat >> ~/.ssh/config <<EOF
Host 172.18.119.40
User juling
IdentityFile ~/.ssh/id_rsa_julinger
IdentitiesOnly yes
EOF
chmod 600 ~/.ssh/config
之后就可以免密登录ssh juling@172.18.119.40,scp、rsync等命令也会自动使用这个密钥,无需再指定 -i 或输入密码。
2. vscode配置
参考:https://wenfh2020.com/2020/10/24/vscode-shortcut-shell/
1) ctrl+shift+P打开面板搜索关键字,打开keybindings.json


// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+1",
"command": "workbench.action.tasks.runTask",
"args": "copy_files",
"when": "editorTextFocus"
}
]
1) ctrl+shift+P打开面板搜索关键字,打开task.json


{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "copy_files",
"type": "shell",
"command": "/jl/perception_ws/copy_all.sh"
}
]
}
3) 快捷键运行脚本
按下ctrl+1快捷键运行脚本。如果出现权限问题报错,执行以下命令赋予权限。
chmod +x /jl/perception_ws/copy_all.sh
更多推荐
所有评论(0)