由于经常需要通过ssh管理远程服务器,而Mac自带的terminal每次都需要输入密码,很麻烦。

所以想找一个类似Windows下的xShell之类的工具

windows 下远程登录通常会使用 Xshell,而在 Mac 访问虚拟机可以使用 shuttle

 

本文介绍Shuttle的安装以及配置,主要是根据Github上的官方文档进行翻译说明,还有自己的一些补充,如果习惯直接看文档的朋友,可以直接关掉这篇文章了~

这是其在Github上的介绍:http://fitztrev.github.io/shuttle/

 

看一下官方简介,就一句话

  1. A simple SSH shortcut menu for macOS

顾名思义,就是一个Mac上管理SSH的工具

 

接下来,介绍一下Shuttle的用法

shuttle是一个开源软件,其源码托管在github ( shuttle ), 通过访问此地址,可以下载最新版本的shuttle.app

运行shuttle.app, 然后可以看到托盘里会出现一个“火箭”的图标,那个就是shuttle。 点击 图标 -> setting -> Edit , 系统会使用文本编辑器打开一个名为:“.shuttle.json”的文件 , 此文件即为shuttle的配置文件。配置字段描述可见 (JSON Options)里的JSON Options。以下我针对性介绍一下:

  • editor: 使用什么编辑器打开.shuttle.json文件(可选值:default, nano, vi, vim或其他可在终端编辑文件的命令)
  • launch_at_login: 是否自动启用shuttle(可选值: true, false)
  • terminal: 设置执行命令的默认终端(可选值:Terminal.app, iTerm)
  • iTerm_verison: 当terminal参数设置为iTerm时必填(可选值:stable, nightly)
  • default_theme: 设置终端主题
  • open_in: 命令窗口展示方式(可选值:tab, new)
  • show_ssh_config_hosts: 是否解析ssh config,并显示对应的主机到菜单列表中(可选值:true, false)
  • ssh_config_ignore_hosts: 在ssh config需要忽略显示在菜单的主机数组(值为主机名)
  • ssh_config_ignore_keywords: 在ssh config需要忽略的关键字

如果要将~/.ssh/config中的主机显示到菜单中, 可以这样定义主机的Host值:

Host work/servers/web01: 表示web01会出现在shuttle的work菜单下servers子菜单下(一种方便的目录层级定义方式)。

也可以使用另外一种方式:

Host web01

# shuttle.name = work/servers/web01

HostName user@web01.example.com

也就是通过“# shuttle.name”开始来定义shuttle的菜单名与层级关系(注意,这个注释必须位于 Host与HostName之前,否则显示的菜单与实际运行的命令会错乱)

除了以上配置项, shuttle还支持自定义命令配置, 这种方式特别适合用常用命令。

自定义命令配置是定义在.shuttle.json中的hosts键值中,其值为一个数组,每个item为一个对象,结构如下:

{ "菜单名": xxx (对象或数组) }

对象包含字段有:

  • cmd: 需要执行的命令
  • name: 菜单名
  • inTerminal: 命令执行窗口模式(可选值:new, tab, current)
  • theme: 终端主题
  • title: 终端显示标题(缺失时使用name作为标题)

按照上面介绍的步骤完成安装与配置后, 现在点击shuttle图标就应该可以看到一些菜单了。

shuttle dropmenu

目录切换: 里面是平常我使用的常用命令 netease: 就是平时需要远程登录的服务器

点击其中的菜单项,将会使用iTerm打开窗口并运行命令(我配置的是iTerm)。

 

 

  1. 首先到Shuttle的官网下载:
    下载地址:https://github.com/fitztrev/shuttle/releases
    然后把Shuttle复制到Application文件夹下即可

  2. 这部分比较重要,要注意一下
    通过命令 open ~/.shuttle.json 打开.shuttle.json文件

    • “editor”: “VALUE”, 设置编辑器,可选项default, nano, vi, vim

    • “launch_at_login”: VALUE, 设置是否开机启动

    • “terminal”: “VALUE”, 设置终端,一般是Terminal.app或者iTerm

    • “iTerm_version”: “VALUE”, 设置iTerm版本,分别有三种

      “iTerm_version”: “legacy”, 2.14版本

      1. "iTerm\_version": "stable", 最新版本
      2. "iTerm\_version": "nightly", nightly build 版本
    • “default_theme”: “Homebrew” 设置终端主题

    • open_in”: “VALUE” 有两个可选项 Tab 或者 new 顾名思义,新建一个Tab 或者 在新窗口执行命令

    • “show_ssh_config_hosts”: VALUE 设置是否解析config文件,默认是true
    • “ssh_config_ignore_keywords”: [“VALUE”] 设置忽略解析的关键字
    • “cmd”: “VALUE” 设置命令
      例如 “cmd”: “ps aux | grep [s]sh”

    • “name”: “VALUE” 设置菜单栏显示的名称

    • “inTerminal”: “VALUE”

      new 新建一个窗口执行命令

      1. tab 新建一个Tab执行命令
      2. current 在当前窗口执行命令
    • “theme”: “VALUE” 设置主题~我用的是basic

    • “title”: “VALUE” 这个标题是显示在终端窗口的标题~
  1. {
  2. "_comments": [
  3. "Valid terminals include: \'Terminal.app\' or \'iTerm\'",
  4. "In the editor value change \'default\' to \'nano\', \'vi\', or another terminal based editor.",
  5. "Hosts will also be read from your ~/.ssh/config or /etc/ssh_config file, if available",
  6. "For more information on how to configure, please see http://fitztrev.github.io/shuttle/"
  7. ],
  8. "editor": "default",
  9. "launch_at_login": true,
  10. "terminal": "iTerm",
  11. "iTerm_version": "nightly",
  12. "default_theme": "Homebrew",
  13. "open_in": "new",
  14. "show_ssh_config_hosts": false,
  15. "ssh_config_ignore_hosts": [],
  16. "ssh_config_ignore_keywords": [],
  17. "hosts": [
  18. {
  19. "cmd": "ps aux | grep defaults",
  20. "name": "Grep - Opens in Default-window-theme-title"
  21. },
  22. {
  23. "Spouses Servers": [
  24. {
  25. "cmd": "echo \'—->WARNING! Running commands<-- Are you sure? y/n\'; read sure; if [ $sure == y ]; then echo running command && ps aux | grep [a]pple; else echo save to history and show... && history -s \'ps aux | grep [a]pple\' && osascript -e \'tell application \"System Events\" to keystroke \"p\" using {control down}\'; fi",
  26. "inTerminal": "current",
  27. "name": "Logs - Opens in the current active terminal window"
  28. },
  29. {
  30. "Jane’s Servers": [
  31. {
  32. "cmd": "ssh username@blog2.example.com",
  33. "inTerminal": "tab",
  34. "name": "SSH blog - Opens in Tab of active window",
  35. "theme": "basic",
  36. "title": "title of tab"
  37. },
  38. {
  39. "cmd": "ssh username@shop1.example.com",
  40. "inTerminal": "new",
  41. "name": "SSH Shop - Opens in New Window",
  42. "theme": "basic",
  43. "title": "title of new window"
  44. }
  45. ]
  46. }
  47. ]
  48. },
  49. ]
  50. }

 

(2)JSON格式说明

  1. {
  2. "菜单名称": [
  3. {
  4. "cmd": "需要执行的 ssh 命令",
  5. "inTerminal": "命令执行的窗口模式:new/tab/current",
  6. "name": "子菜单名",
  7. "theme": "终端主题:basic",
  8. "title": "新窗口/新标签页标题,缺失时使用 name 作为标题",
  9. }
  10. ]
  11. },

 

  1. "hosts": [
  2. {
  3. "cmd": "ssh root@192.168.0.100 -p 4000",
  4. "inTerminal": "tab",
  5. "name": "SSH - root用户",
  6. "theme": "basic",
  7. "title": "Blue"
  8. },
  9. {
  10. "cmd": "ssh root@192.168.0.200 -p 4000",
  11. "inTerminal": "tab",
  12. "name": "SSH - git用户",
  13. "theme": "basic",
  14. "title": "Blue"
  15. }
  16. ]

shuttle 除了可以用来当SSH管理工具以外,还能执行多条命令操作,提高效率,只要用分号分隔即可

  1. 例如 pwd; ls; cd /; 就会按顺序执行以上三条命令。


    下面的配置也可以参考:
  1. {
  2. "_comments": [
  3. "Valid terminals include: \'Terminal.app\' or \'iTerm\'",
  4. "In the editor value change \'default\' to \'nano\', \'vi\', or another terminal based editor.",
  5. "Hosts will also be read from your ~/.ssh/config or /etc/ssh_config file, if available",
  6. "For more information on how to configure, please see http://fitztrev.github.io/shuttle/"
  7. ],
  8. "editor": "default",
  9. "launch_at_login": false,
  10. "terminal": "Terminal.app",
  11. "iTerm_version": "nightly",
  12. "default_theme": "Homebrew",
  13. "open_in": "new",
  14. "show_ssh_config_hosts": false,
  15. "ssh_config_ignore_hosts": [ ],
  16. "ssh_config_ignore_keywords": [ ],
  17. "hosts": [
  18. {
  19. "cmd": "ssh username@host",
  20. "name": "SSH - MayiYun",
  21. "inTerminal": "new",
  22. "theme": "basic",
  23. },
  24. {
  25. "cmd": "adb shell",
  26. "name": "Open - ADB Shell",
  27. "inTerminal": "new",
  28. "theme": "basic",
  29. }
  30. ]
  31. }

配置了两个快捷菜单:

  1. SSH – MayiYun 用来登陆我的蚂蚁云服务器
  2. Open – ADB Shell 做安卓开发的时候,快速打开adb

 

 

当然,这里只是简单介绍了shuttle的基本用法,还有更多其他功能值得去探索~

 

版权声明:本文为haochuang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/haochuang/p/10056962.html