yairchu
yairchu

Reputation: 24784

Using Xcode as EDITOR environment variable or opening a specific file in Xcode from the command line

I would like to open files in Xcode, which I use to develop, also in my conflict resolution process using git-mediate -e. Is there a command line command which I can set in the EDITOR enviroment variable that will invoke Xcode to edit a given file? (bonus: also in the specified line)

Upvotes: 0

Views: 111

Answers (2)

mr. fixit
mr. fixit

Reputation: 1552

if you have installed Xcode's command line tools, you have xed

% which xed
/usr/bin/xed
% xed --help
Options:
    -c, --create           Create the files if they do not exist.
    -p, --project <path>   Open the project, workspace, or package at <path> before opening the requsted files.
    -w, --wait             Wait for file to be closed by Xcode before terminating xed.
    -l, --line <number>    Select line <number> after opening file.
    -b, --background       Leave Xcode in the background (don't activate it).
    -h, --help             Show this information.
    -v, --version          Print version information.

So the following is what you want

export EDITOR="xed -w"

Upvotes: 1

mamadnazar
mamadnazar

Reputation: 60

In order to open a specific file in Xcode from the command line, use open -a /Applications/Xcode.app

For example:

open -a /Applications/Xcode.app your_file_name.txt

For being able to use as EDITOR, wrap this in a script xcode-edit.sh:

#!/bin/sh
open -a /Applications/Xcode.app $@

Now, you can use EDITOR=xcode-edit.sh git-mediate -e

Upvotes: 1

Related Questions