【问题标题】:Distributing executable terminal commands on macOS在 macOS 上分发可执行的终端命令
【发布时间】:2017-04-09 07:48:07
【问题描述】:

我为我的开发工作流程中的所有内容(todo、pullrequest、asciiart、remind 等)创建了 bash/ruby 命令。与我一起工作的人总是要求我与他们分享我的命令,但为此,我将文件传输到他们的计算机,然后通过 chmod +x 和 mv /usr/local/bin 将每个文件传输到 xargs。

想知道我可以先做哪些工作来简化导入过程。可以使用一些 Mac 安装程序工具或 git 和 makefile 解决方案,但如果可能的话,我真的很想将过程简化为单击或命令。

【问题讨论】:

    标签: bash macos shell unix terminal


    【解决方案1】:

    在 Nix 包管理器中使用 Nix 表达式:https://en.m.wikipedia.org/wiki/Nix_package_manager !它在 Mac 上受支持。

    【讨论】:

      【解决方案2】:

      只需在 Finder 中选择终端命令并按下键盘快捷键,即可使终端命令可执行。

      以下是解决问题的方法。

      1.使用 Automator 创建 macOS 服务

      1.1 打开 Automator 并创建一个新服务
      1.2 在顶部,选择Service receive selected no input in Finder
      1.3 将 Get Selected Finder Items 操作拖到工作流
      1.4 将 Run Shell Script 动作拖到工作流
      1.5 在 Run Shell Script 动作中,选择 Pass input: as arguments 并在文本字段中输入:
      chmod u+x "$@" && mv "$@" /usr/local/bin
      1.6 保存服务

      2。向同事的计算机分发服务

      2.1 创建的服务位于~/Library/Services
      2.2 移动到其他电脑打开文件安装,或者手动复制服务到~/Library/Services

      3.将服务绑定到键盘快捷键

      3.1 打开系统偏好设置 → 键盘 → 快捷方式 → 服务 → 常规
      3.2 为您的服务选择合适的键盘快捷键

      您也可以通过右键单击文件并在上下文菜单底部的服务子菜单中选择操作来运行服务。

      【讨论】:

      • 感谢截图和努力
      【解决方案3】:

      与他们共享一个包含您的脚本的 Dropbox 目录,并确保该目录位于他们的PATH 中。

      改进脚本时无需更新,因为它们会自动看到最新版本。

      使用git 管理目录以进行版本控制。

      【讨论】:

        【解决方案4】:

        为了完成,我想我会发布标准的 makefile 解决方案。适用于 macOS/ 和 GNU(Linux)

        在项目目录中放置一个makefile。

        所以目录看起来像 [ my-executable makefile readme.md ] 或其他什么

        # makefile
        
        install: 
        
            # side note: `@` prevents make from printing the command itself
        
            @echo "installing..."
            @chmod +x my-executable
            @cp my-executable /usr/local/bin
            @echo "done!"
        

        然后通知收件人从项目目录下载/克隆并运行sudo make install

        或者对于单线解决方案(假设收件人过于信任您)

        git clone https://githost.com/myaccount/myrepo.git && 
        sudo make install -C myrepo && 
        rm -rf myrepo 
        

        (下载、安装、删除克隆目录)——用户 16 分钟前

        【讨论】:

        • 一行git clone https://githost.com/myaccount/myrepo.git && sudo make install -C myrepo && rm -rf myrepo"(下载、安装、删除克隆目录)
        猜你喜欢
        • 2019-03-15
        • 2016-04-05
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 2015-05-27
        • 2011-05-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多