前言
在Xcode開發(fā)環(huán)境中,有一些可以自定義的快捷Behavior新啼,可以大大提高開發(fā)效率。
自定義Behavior
如何配置Behavior
以下是在Xcode中配置Behavior的通用步驟:
- 打開Xcode的偏好設(shè)置。
- 點擊“Behaviors”選項卡涝登。
- 點擊左下角的"+"號創(chuàng)建一個新的Behavior趟紊。
- 為Behavior命名氮双,例如你希望調(diào)用的腳本名。
- 在“Run”下選擇“Script”霎匈,然后選擇你寫好的腳本戴差。
- 按需配置快捷鍵,并保存铛嘱。
現(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:打開項目文件夾
#!/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乾忱,我們可以更快速地訪問項目文件夾和命令行
等,從而提高開發(fā)效率历极。如果大家有其他想法或者需求窄瘟,歡迎在評論區(qū)留言,后續(xù)會不斷更新????趟卸。