-
[Xcode Behavior] Xcode에서 터미널명령어 바로 실행하기개발 환경/Xcode 2022. 1. 10. 00:04
Xcode로 작업하다가 중간에 터미널을 열어야 하는 경우가 종종 있습니다.
- CocoaPod Install
- CocoaPod Update
- 등등...
그럴 때, 해당 프로젝트의 경로로 한번에 찾아들어가기 굉장히 귀찮습니다.
script를 등록함으로써 이런 번거로움들을 한번에 해결할 수 있습니다.
아래 코드는 순서대로
open_terminal
,pod init
,pod update
입니다.원하는 코드를 복사해 파일로 만들어주세요.
코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters#!/bin/bash open -a iTerm `pwd` This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters#!/bin/bash # move project dir PROJECT_HOME=`pwd` echo "cd $PROJECT_HOME" > /tmp/tmp.sh # search .xcodeproj file and strip filename PROJECT_NAME="" for f in *.xcodeproj; do PROJECT_NAME="${f%.*}" break done if [[ -z "$PROJECT_NAME" ]] || [ "$PROJECT_NAME" == "*" ]; then osascript -e 'tell application (path to frontmost application as text) to display dialog "Cannot find project file" buttons {"OK"} with icon stop' exit fi # pod init & update echo "pod init;pod install;clear;" >> /tmp/tmp.sh # reload workspace file echo "wait" >> /tmp/tmp.sh echo "echo \"Close '$PROJECT_NAME' Xcode window\"" >> /tmp/tmp.sh echo "open $PROJECT_NAME.xcworkspace" >> /tmp/tmp.sh echo "rm /tmp/tmp.sh" >> /tmp/tmp.sh chmod +x /tmp/tmp.sh # M1 사용자의 경우 terminal을 rosetta로 여는것이 좋다. open -a Terminal /tmp/tmp.sh This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters#!/bin/bash # move project dir PROJECT_HOME=`pwd` echo "cd $PROJECT_HOME" > /tmp/tmp.sh # pod init & update echo "pod update" >> /tmp/tmp.sh echo "rm /tmp/tmp.sh" >> /tmp/tmp.sh chmod +x /tmp/tmp.sh open -a Terminal /tmp/tmp.sh 적용
Xcode - Preference - Behaviors 왼쪽아래 +버튼을 눌러서 이름을 지어준 후, 오른쪽 표시된 곳에서 알맞는 스크립트를 불러오면 됩니다.
단축키 자세히 보면 단축키도 지정할 수 있기 때문에 원하는 단축키로 더 생산성을 높일 수 있습니다.
더 많은 Behaviors
글에서 설명한 간단한 기능 말고도 많은 행동들을 설정해서 사용할 수 있습니다.
그 중 TTS 활용 과 같은 흥미로운 것들도 많이 있으니 더 찾아보고 적용해보면 좋을 것 같습니다.
명령어 실행 후 터미널 종료 설정
명령어를 다 실행하고도 계속해서 아래와 같이 터미널이 남아있다면 굉장히 번거로울 것입니다.
터미널의 설정(
Command
+,
)에 들어가 아래와 같이 설정해주면, 명령어 실행 이후 터미널이 알아서 종료됩니다.출처
'개발 환경 > Xcode' 카테고리의 다른 글
[Xcode] Info.plist가 사라졌다. (0) 2022.05.04 [Playground] 3rd_party 라이브러리 사용하기 (0) 2021.12.11