Xcode快捷Behavior

前言

在Xcode開發(fā)環(huán)境中,有一些可以自定義的快捷Behavior,可以大大提高開發(fā)效率。


自定義Behavior

如何配置Behavior

以下是在Xcode中配置Behavior的通用步驟:

  1. 打開Xcode的偏好設(shè)置。
  2. 點(diǎn)擊“Behaviors”選項(xiàng)卡。
  3. 點(diǎn)擊左下角的"+"號創(chuàng)建一個新的Behavior。
  4. 為Behavior命名,例如你希望調(diào)用的腳本名。
  5. 在“Run”下選擇“Script”,然后選擇你寫好的腳本。
  6. 按需配置快捷鍵,并保存。

現(xiàn)在,每當(dāng)你使用配置的快捷鍵時,它就會運(yùn)行你的腳本。

Behavior示例

Behavior1:打開終端并cd到當(dāng)前工作目錄

創(chuàng)建open_terminal.sh,寫入以下內(nèi)容

#!/bin/bash
open -a terminal "`pwd`"

并添加執(zhí)行權(quán)限

sudo chmod +x open_terminal.sh

添加Behavior并在Run處選中該腳本路徑,配置好快捷鍵。
當(dāng)你使用配置的快捷鍵時,就會打開終端并cd到當(dāng)前工作目錄。

后面就只給出腳本代碼了,其他步驟一樣的就不重復(fù)了

Behavior2:打開項(xiàng)目文件夾

#!/bin/bash

# Path to your project
project_path="$1"

# Open the project folder in Finder
open "$project_path"

Behavior3:執(zhí)行pod install

#!/bin/bash

current_directory=`pwd`

osascript -e "
  tell application \"iTerm\"
      activate
      if (count of windows) = 0 then
          set newWindow to (create window with default profile)
          tell newWindow
              tell current session
                  write text \"cd $current_directory; pod install\"
              end tell
          end tell
      else
          tell current window
              create tab with default profile
          end tell
          tell current session of current tab of current window
              write text \"cd $current_directory; pod install\"
          end tell
      end if
  end tell"

總結(jié)

通過配置Behavior,我們可以更快速地訪問項(xiàng)目文件夾和命令行等,從而提高開發(fā)效率。如果大家有其他想法或者需求,歡迎在評論區(qū)留言,后續(xù)會不斷更新????。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容