Comments (3)
I assume the library would be something like this:
require 'shellwords'
module TextMate
def TextMate.file_selection
ENV.has_key?('TM_SELECTED_FILES') ? Shellwords.shellwords(ENV['TM_SELECTED_FILES']) : nil
end
def TextMate.file_selection_or_current
return Shellwords.shellwords(ENV['TM_SELECTED_FILES']) if ENV.has_key?('TM_SELECTED_FILES')
return ENV.has_key?('TM_FILEPATH') ? [ ENV['TM_FILEPATH'] ] : nil
end
def TextMate.file_selection_or_project
return Shellwords.shellwords(ENV['TM_SELECTED_FILES']) if ENV.has_key?('TM_SELECTED_FILES')
folder = ENV['TM_PROJECT_DIRECTORY'] || ENV['TM_DIRECTORY']
return folder ? [ folder ] : nil
end
end
I could see a minor advantage of having commands use such library, even though inlining the relevant code is probably not that much more, but probably a bit more arcane.
I’m btw definitely in favor of returning nil
over empty array, as the former can more easily be tested against.
from bundle-support.tmbundle.
Exactly. Btw, there is already TextMate.selected_files
in textmate.rb:
bundle-support.tmbundle/Support/shared/lib/textmate.rb
Lines 213 to 217 in f656497
fallback:
parameter so that it can be called like this:
TextMate.selected_files # default (nil if no files selected)
TextMate.selected_files(fallback: :current_file)
TextMate.selected_files(fallback: :project_dir)
On the other hand, having explicit methods would be more explicit. So not sure what’s the best way.
from bundle-support.tmbundle.
I like having different method names for the different options,
especially with ruby where options are untyped (so one can pass in
virtually anything w/o getting errors).
Encoding the options in the method names also makes it easier to search
for the code which uses the options.
And given that we already have TextMate.selected_files, let’s
definitely move everything to moving that, instead of this shelltokenize
stuff.
The uniquing done by the Git bundle, maybe this was for 1.x projects
where the user could add the same file twice, but there should be no
reason to check for duplicates in TM_SELECTED_FILES with 2.0.
On 29 Aug 2016, at 23:17, Stefan Daschek wrote:
Exactly. Btw, there is already
TextMate.selected_files
in
textmate.rb:
.bundle-support.tmbundle/Support/shared/lib/textmate.rb
Lines 213 to 217 in f656497
Maybe simply add an optionalfallback:
parameter so that it can be
called like this:TextMate.selected_files # default (nil if no files selected) TextMate.selected_files(fallback: :current_file) TextMate.selected_files(fallback: :project_dir)On the other hand, having explicit methods would be more explicit. So
not sure what’s the best way.-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/textmate/bundle-support.tmbundle/issues/25#issuecomment-243259362
from bundle-support.tmbundle.
Related Issues (16)
- Exception when selected theme is missing
- Ruby 1.8 crashing running commands HOT 11
- Encoding of Python files HOT 5
- html_header from webpreview.sh throw warning and incorrect escaped string if TM_THEME_PATH contain non-ASCII character
- images in TextMate::UI.complete HOT 1
- TextMate::UI.complete does not work HOT 2
- Provide API for running Ruby executables like rspec, rubocop etc. HOT 1
- TextMate::Executor.run show broken preview HOT 4
- Please use secure HTTPS transport
- Provide 64-Bit Version of `find_app`
- Create new snippets, etc. HOT 1
- Include 64-Bit Version of CocoaDialog in Bundle HOT 3
- plist.bundle is missing architecture arm64e (M1 error with bundles) HOT 1
- Universal substitute for CocoaDialog which is Intel only HOT 1
- Markdown preview broken (possibly others) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bundle-support.tmbundle.