exedit 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +2 -0
- data/exedit.gemspec +26 -0
- data/lib/exedit.rb +1 -0
- data/lib/exedit/command.rb +18 -0
- data/lib/exedit/editor.rb +41 -0
- data/lib/exedit/exedit.rb +58 -0
- data/lib/exedit/version.rb +4 -0
- data/spec/spec_helper.rb +81 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7a1a6fcb2bd37d081b4e72d5dba3d2c0ef8939e
|
4
|
+
data.tar.gz: d2f7701805093598fa7c68fb35e03a4cf26c61eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb110f468d58966ff349e6d6bcf5fd4a8d76223d2e588c284dc49203d195667d54317ba0c2d014fac92893c06a370953dd4fe7ede8e9054b404c1bd7599824c2
|
7
|
+
data.tar.gz: ba9879d1737d6a30024cb6eb5b08997b6d20eaf8a6a4e2d5104e2186a18f10453e045a3f87af23d6c68062982040634e1ffd320c8c008bed180c068671431db9
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.DS_Store*
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Joey Lorich
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Exedit
|
2
|
+
|
3
|
+
Easily jump to external editors from a ruby script for input. (Like git does with commit messages)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'exedit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
To open a file in the default external editor, simply call
|
18
|
+
|
19
|
+
result = Exedit.open ./path/to/file
|
20
|
+
|
21
|
+
The script will pause until the editor closes and the saved result will be read and returned.
|
22
|
+
|
23
|
+
If no file is specified, a tempfile will be generated and then destroyed immedately after the result is returned
|
24
|
+
|
25
|
+
result = Exedit.open
|
26
|
+
|
27
|
+
#####String editing
|
28
|
+
|
29
|
+
You can also edit strings in external functions by using
|
30
|
+
|
31
|
+
result = Exedit.edit "my string!"
|
32
|
+
|
33
|
+
#####Editors
|
34
|
+
|
35
|
+
Commands to launch vim, nano, pico, sublime, and textmate are included by default. To open in a specific editor simply specify it when optining
|
36
|
+
|
37
|
+
result = Exedit.open editor: :sublime
|
38
|
+
|
39
|
+
You can also manually pass in a command to launch an editor
|
40
|
+
|
41
|
+
result = Exedit.open command: 'subl -n -w'
|
42
|
+
|
43
|
+
#####Options
|
44
|
+
|
45
|
+
Configurable options are availabe, including what editors can be launched and the default editor.
|
46
|
+
|
47
|
+
Exedit.configure do |config|
|
48
|
+
config.editors[:cooleditor] = 'cooleditor -w'
|
49
|
+
config.default_editor = :cooleditor
|
50
|
+
end
|
51
|
+
|
52
|
+
The following would set a hypothetical `cooleditor` as the default editor, launched with a command of `cooleditor -w ./path/to/file`
|
53
|
+
|
54
|
+
|
55
|
+
##### Editor Availability
|
56
|
+
|
57
|
+
`Exedit.available_editors` will return all editors availble on the current system. The default configuration options also only include editors installed on the current system. If no `default_editor` is specified in the options, it will default to the first available editor on the system (typically vi)
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it ( https://github.com/jlorich/exedit/fork )
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/exedit.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'exedit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "exedit"
|
8
|
+
spec.version = Exedit::VERSION
|
9
|
+
spec.authors = ["Joey Lorich"]
|
10
|
+
spec.email = ["jospeh@lorich.me"]
|
11
|
+
spec.summary = %q{Easily jump to external editors for file input!}
|
12
|
+
spec.description = %q{Easily jump to external editors for file input!}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.3.2'
|
23
|
+
spec.add_development_dependency 'pry-byebug', '~> 1.3.3'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0'
|
25
|
+
spec.add_development_dependency 'clint_eastwood', '~> 0.0.1'
|
26
|
+
end
|
data/lib/exedit.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'exedit/exedit'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Exedit
|
2
|
+
# A system command checking class
|
3
|
+
class Command
|
4
|
+
# Gets the path to a system command, returns nil if none found
|
5
|
+
def self.which(cmd)
|
6
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
7
|
+
|
8
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
9
|
+
exts.each do |ext|
|
10
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
11
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Exedit
|
4
|
+
# An exedit external editor instance
|
5
|
+
class Editor
|
6
|
+
attr_accessor :edit_command
|
7
|
+
|
8
|
+
def initialize(edit_command, file_path = nil, content: nil)
|
9
|
+
@file_path = file_path
|
10
|
+
@edit_command = edit_command
|
11
|
+
@content = content
|
12
|
+
end
|
13
|
+
|
14
|
+
def open
|
15
|
+
(file.write(@content) && file.flush) if @content && !@file_path
|
16
|
+
|
17
|
+
system("#{edit_command} #{file.path}")
|
18
|
+
|
19
|
+
result = reload(file).read
|
20
|
+
|
21
|
+
# Remove the tempfile if it exists
|
22
|
+
tempfile.unlink if @tempfile
|
23
|
+
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def file
|
30
|
+
@file ||= @file_path ? File.new(@file_path) : tempfile
|
31
|
+
end
|
32
|
+
|
33
|
+
def tempfile
|
34
|
+
@tempfile ||= Tempfile.new('ex-edit')
|
35
|
+
end
|
36
|
+
|
37
|
+
def reload(file)
|
38
|
+
file.reopen(file.path)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'exedit/editor'
|
2
|
+
require 'exedit/command'
|
3
|
+
require 'dot_configure'
|
4
|
+
|
5
|
+
# A ruby external editor interface
|
6
|
+
module Exedit
|
7
|
+
extend DotConfigure
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :editor
|
11
|
+
|
12
|
+
# Opens a file (defaults to a tempfile which will be deleted) for editing in the external editor
|
13
|
+
def open(file = nil, editor: nil, command: nil)
|
14
|
+
Editor.new(edit_command(editor, command), file).open
|
15
|
+
end
|
16
|
+
|
17
|
+
# Edits the given content in a tempfile
|
18
|
+
def edit(content, editor: nil, command: nil)
|
19
|
+
Editor.new(edit_command(editor, command), content: content).open
|
20
|
+
end
|
21
|
+
|
22
|
+
# All editors available on the current system
|
23
|
+
def available_editors
|
24
|
+
if !defined? @options
|
25
|
+
base_editors.select { |_editor, command| Command.which(command.split(' ')[0]) }
|
26
|
+
else
|
27
|
+
options.editors.select { |_editor, command| Command.which(command.split(' ')[0]) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def edit_command(editor, command)
|
34
|
+
command || options.editors[editor || default_editor]
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_editor
|
38
|
+
options.default_editor || available_editors.keys.first
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_editors
|
42
|
+
{
|
43
|
+
vi: 'vi',
|
44
|
+
vim: 'vim',
|
45
|
+
nano: 'nano',
|
46
|
+
pico: 'pico',
|
47
|
+
sublime: 'subl -w -n',
|
48
|
+
textmate: 'mate -w'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_options
|
53
|
+
{
|
54
|
+
editors: base_editors.select { |key, _value| available_editors.include? key }
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'pry-byebug'
|
2
|
+
require 'exedit'
|
3
|
+
|
4
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
5
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
7
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, make a
|
13
|
+
# separate helper file that requires this one and then use it only in the specs
|
14
|
+
# that actually need it.
|
15
|
+
#
|
16
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
17
|
+
# users commonly want.
|
18
|
+
#
|
19
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# The settings below are suggested to provide a good initial experience
|
22
|
+
# with RSpec, but feel free to customize to your heart's content.
|
23
|
+
# These two settings work together to allow you to limit a spec run
|
24
|
+
# to individual examples or groups you care about by tagging them with
|
25
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
26
|
+
# get run.
|
27
|
+
config.filter_run :focus
|
28
|
+
config.run_all_when_everything_filtered = true
|
29
|
+
|
30
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
31
|
+
# file, and it's useful to allow more verbose output when running an
|
32
|
+
# individual spec file.
|
33
|
+
if config.files_to_run.one?
|
34
|
+
# Use the documentation formatter for detailed output,
|
35
|
+
# unless a formatter has already been configured
|
36
|
+
# (e.g. via a command-line flag).
|
37
|
+
config.default_formatter = 'doc'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Print the 10 slowest examples and example groups at the
|
41
|
+
# end of the spec run, to help surface which specs are running
|
42
|
+
# particularly slow.
|
43
|
+
config.profile_examples = 10
|
44
|
+
|
45
|
+
# Run specs in random order to surface order dependencies. If you find an
|
46
|
+
# order dependency and want to debug it, you can fix the order by providing
|
47
|
+
# the seed, which is printed after each run.
|
48
|
+
# --seed 1234
|
49
|
+
config.order = :random
|
50
|
+
|
51
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
52
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
53
|
+
# test failures related to randomization by passing the same `--seed` value
|
54
|
+
# as the one that triggered the failure.
|
55
|
+
Kernel.srand config.seed
|
56
|
+
|
57
|
+
# rspec-expectations config goes here. You can use an alternate
|
58
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
59
|
+
# assertions if you prefer.
|
60
|
+
config.expect_with :rspec do |expectations|
|
61
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
62
|
+
# For more details, see:
|
63
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
64
|
+
expectations.syntax = :expect
|
65
|
+
end
|
66
|
+
|
67
|
+
config.color = true
|
68
|
+
|
69
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
70
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
71
|
+
config.mock_with :rspec do |mocks|
|
72
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
73
|
+
# For more details, see:
|
74
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
75
|
+
mocks.syntax = :expect
|
76
|
+
|
77
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
78
|
+
# a real object. This is generally recommended.
|
79
|
+
mocks.verify_partial_doubles = true
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exedit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joey Lorich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.3.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.3.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: clint_eastwood
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.1
|
83
|
+
description: Easily jump to external editors for file input!
|
84
|
+
email:
|
85
|
+
- jospeh@lorich.me
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- exedit.gemspec
|
96
|
+
- lib/exedit.rb
|
97
|
+
- lib/exedit/command.rb
|
98
|
+
- lib/exedit/editor.rb
|
99
|
+
- lib/exedit/exedit.rb
|
100
|
+
- lib/exedit/version.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: ''
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.0.14
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Easily jump to external editors for file input!
|
126
|
+
test_files:
|
127
|
+
- spec/spec_helper.rb
|