From 04c8e896a59950aa7c13a4b906c21cbf54083ea7 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Fri, 2 Apr 2021 15:36:29 -0700 Subject: [PATCH] edit: enable Sublime Text project view --- .gitignore | 4 +++- .sublime/homebrew.sublime-project | 28 ++++++++++++++++++++++++++++ Library/Homebrew/dev-cmd/edit.rb | 26 +++++++++++++++++--------- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 .sublime/homebrew.sublime-project diff --git a/.gitignore b/.gitignore index 6001fe1574..47daa63362 100644 --- a/.gitignore +++ b/.gitignore @@ -194,5 +194,7 @@ # Unignore tests' bundle config !/Library/Homebrew/test/.bundle/config -# Unignore vscode configuration +# Unignore editor configuration +!/.sublime +/.sublime/homebrew.sublime-workspace !/.vscode diff --git a/.sublime/homebrew.sublime-project b/.sublime/homebrew.sublime-project new file mode 100644 index 0000000000..6a212a4dd6 --- /dev/null +++ b/.sublime/homebrew.sublime-project @@ -0,0 +1,28 @@ +{ + "folders": + [ + { + "//": "Generated based on the contents of our .gitignore", + "path": "..", + "folder_exclude_patterns": [ + "Caskroom", + "Cellar", + "Frameworks", + "bin", + "etc", + "include", + "lib", + "opt", + "sbin", + "share", + "var", + "Library/Homebrew/LinkedKegs", + "Library/Homebrew/Aliases" + ], + "follow_symlinks": true + } + ], + "settings": { + "tab_size": 2 + } +} diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index e60515b6f0..4a50d23926 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -40,16 +40,24 @@ module Homebrew EOS end - paths = args.named.to_paths.select do |path| - next path if path.exist? + paths = if args.named.empty? + # Sublime requires opting into the project editing path, + # as opposed to VS Code which will infer from the .vscode path + if which_editor == "subl" + ["--project", "#{HOMEBREW_REPOSITORY}/.sublime/homebrew.sublime-project"] + else + # If no formulae are listed, open the project root in an editor. + [HOMEBREW_REPOSITORY] + end + else + args.named.to_paths.select do |path| + next path if path.exist? - raise UsageError, "#{path} doesn't exist on disk. " \ - "Run #{Formatter.identifier("brew create --set-name #{path.basename} $URL")} " \ - "to create a new formula!" - end.presence - - # If no formulae are listed, open the project root in an editor. - paths ||= [HOMEBREW_REPOSITORY] + raise UsageError, "#{path} doesn't exist on disk. " \ + "Run #{Formatter.identifier("brew create --set-name #{path.basename} $URL")} " \ + "to create a new formula!" + end.presence + end exec_editor(*paths) end