Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect rush #19

Open
wants to merge 131 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
2a4e0b1
Some cleanup and retab
s-mage Feb 27, 2014
66645cf
Ignore .swp files
schfkt Feb 27, 2014
46bd804
Retab, hack to run bash commands without pain
s-mage Mar 2, 2014
cbd8021
Some bash-like aliases, xdg-open and locate
s-mage Mar 2, 2014
9144408
Add usage comment for open
s-mage Mar 2, 2014
d7ef5b6
Add open_with function to open files with any application you like
s-mage Mar 3, 2014
e4b32f3
Add multiline input support
s-mage Mar 3, 2014
7f2fbdc
Add pager to printing results, colorize less
s-mage Mar 8, 2014
9b31738
Fix autocomplete, make it work with constants
s-mage Mar 9, 2014
c293db9
Clean code a bit
s-mage Mar 16, 2014
f48b0a8
Specs now running. But not passed
s-mage Mar 16, 2014
d5a9256
Fix access inconsistence
s-mage Mar 22, 2014
15b249a
Fix access specs
s-mage Mar 22, 2014
ca31e95
All specs passed
s-mage Mar 22, 2014
0a5dfe4
Now you can tune your prompt
s-mage Mar 22, 2014
796dec7
Remove ctags file and add it go .gitignore
s-mage Mar 23, 2014
756744d
More accurate work with bash commands
s-mage Mar 30, 2014
26a1d8f
Add travis c support
s-mage Mar 31, 2014
68edff7
Add rake to dependencies
s-mage Mar 31, 2014
704a9f2
Update gemspec. Fix travis config
schfkt Mar 31, 2014
e06ce79
Add travis badge
schfkt Mar 31, 2014
2ca4cb4
Fix badge
schfkt Mar 31, 2014
5939d36
Remove jruby from travis
s-mage Apr 5, 2014
2668a9f
Add rubinius to travis
s-mage Apr 5, 2014
15732b2
Fix spec for rubinius
s-mage Apr 5, 2014
f762aca
Replace readline with coolline. Add syntax highlight
s-mage Apr 6, 2014
cfde57b
Remove swap file
s-mage Apr 6, 2014
8c13c4a
Fix gemspec
schfkt Apr 11, 2014
cc0bd96
Small improvements
s-mage Apr 19, 2014
885e025
Add installation instructions to the README
May 2, 2014
74f67df
add uninstall instructions also
May 2, 2014
884bc52
Added ruby-dev to requirements in readme
May 3, 2014
e3d0617
Add documentation and .gem file to .gitignore
May 3, 2014
12d6106
Update website and meta in the readme
May 3, 2014
46f5c5b
Merge pull request #2 from najamelan/hotfix/ignoreDocs
s-mage May 4, 2014
8f45aac
Merge pull request #3 from najamelan/hotfix/outdatedReadme
s-mage May 4, 2014
7e9f07e
Improve work with requirements. Remove circular dependency and some "…
s-mage May 4, 2014
57dab75
Add development group to Gemfile
s-mage May 4, 2014
b86f191
Use rspec2 instead of legacy rspec
May 4, 2014
a524444
Deprecated function in rspec2: stub!
May 4, 2014
a67550f
Deprecated methods in rspec2: mock
May 4, 2014
22c7214
Merge branch 'master' into hotfix/readmeInstallInstructions
May 5, 2014
ab81050
Add .bundle to .gitignore
May 5, 2014
8ad9dc7
Update the bundle dependencies to include rspec 2
May 5, 2014
c47741f
Try to work around travis bug travis-ci/travis-ci#2220
May 5, 2014
67f9d5b
Merge pull request #4 from najamelan/feature/rspec2
s-mage May 5, 2014
8e10ab6
Merge pull request #1 from najamelan/hotfix/readmeInstallInstructions
s-mage May 5, 2014
6201b96
Installation instruction for development
May 14, 2014
d925ef0
remove a double definition of exceptions
May 6, 2014
60e6d2f
Do not unshift ourselves on the $LOADPATH since we now use require_re…
May 6, 2014
b3e27f8
Merge pull request #6 from najamelan/hotfix/cleanup
s-mage May 15, 2014
1e8c6ac
Add vendor/bundle to gitignore
May 19, 2014
fb382eb
Simplify dev install instructions by using rake install.
May 19, 2014
59b4ce1
Merge pull request #5 from najamelan/hotfix/devInstallInstructions
s-mage May 21, 2014
05a92ae
Create Entry::chown and Entry::chown_R
May 22, 2014
164d7f9
Merge pull request #7 from najamelan/feature/chown
s-mage May 25, 2014
43738b5
Refactor pull request #7
s-mage May 25, 2014
c0ea256
Add owner accessor to file
s-mage Jun 1, 2014
9a570a1
remove a backup file
May 22, 2014
378f6ad
Merge pull request #8 from najamelan/hotfix/removeBackupFile
s-mage Jun 29, 2014
8f7d21c
Fix crashing on some cases of autocomplete
s-mage Aug 11, 2014
c1f4dc9
[refs #10] Remove mongrel, bring connection via net/ssh. Still no rus…
s-mage Sep 14, 2014
50f2daf
Remove .idea
s-mage Sep 14, 2014
83c02cb
Dir and config specs moved to expect syntax
s-mage Sep 14, 2014
f797d01
Search results and string ext specs moved to expect syntax
s-mage Sep 14, 2014
e6015e9
Add completion for executables
s-mage Oct 8, 2014
ea222cd
[refs #9] Rewrite autocomplete system
s-mage Oct 11, 2014
4935d53
Output should be pretty again
s-mage Oct 12, 2014
08cf1c1
Run executables without pain: my_file.firefox will open firefox
s-mage Oct 12, 2014
b1da22e
Update dependencies
s-mage Oct 12, 2014
3539dba
[refs #9] Tests for completion
s-mage Oct 12, 2014
c53eee2
[refs #10] Use sshfs for remote connections
s-mage Oct 12, 2014
91cc3de
Version bump to 0.7.0
s-mage Oct 12, 2014
a68c76e
Update readme; release gem rush2
s-mage Oct 12, 2014
bda86cc
Improve autocompletion with coolline settings
s-mage Oct 13, 2014
b3536fe
Version bump to 0.7.1
s-mage Oct 13, 2014
e14cfd8
Split shell initialization into several commands
s-mage Dec 24, 2014
85e6616
Update dependencies
s-mage Dec 25, 2014
99fd8b8
Move more specs to new format
s-mage Jan 1, 2015
c3f3d8d
Moving specs to new syntax -- box_spec
s-mage Jan 6, 2015
0024cb4
Update dependencies; rewrite some tests
s-mage Mar 6, 2015
cad4b42
[refs #13] Hash of keys in open_with and output_of
s-mage Mar 6, 2015
1c8eadd
[refs #13] Support -k and --key
s-mage Mar 6, 2015
c59797a
[refs #13] Update documentation; fix open_command
s-mage Mar 6, 2015
05c8457
Add edit command
s-mage Mar 28, 2015
805081e
Fix process spec and shell spec
s-mage Mar 28, 2015
4496b94
Fix file spec
s-mage Mar 28, 2015
d519357
Fix process spec
s-mage Mar 28, 2015
0fce14a
Remove remote and spec for it. Noone use it
s-mage Mar 28, 2015
05a1922
Fix entry spec
s-mage Mar 28, 2015
7f78c41
All specs passed!
s-mage Mar 28, 2015
7ca1a56
No deprecation warnings anymore
s-mage Mar 28, 2015
d97c426
Update dependencies; bump version
s-mage Mar 29, 2015
139d4a2
Small code style improvements
s-mage Apr 5, 2015
db0eeed
dry path manipulation & fix travis-ci
razum2um May 10, 2015
1d8c88b
test on 2.2
razum2um May 10, 2015
51ba57f
support Dir#size on OSX
razum2um May 10, 2015
60dac49
allow sudo in travis
razum2um May 10, 2015
3a05033
rbx support
razum2um May 10, 2015
1fe7e1b
support 1.9.3
razum2um May 10, 2015
475f9f1
support osx subprocess test
razum2um May 10, 2015
74fac8d
Merge pull request #14 from razum2um/master
s-mage May 11, 2015
53e33c7
Update dependencies
s-mage Jun 3, 2015
309b70e
Merge branch 'master' of github.com:s-mage/rush
s-mage Jun 3, 2015
09d57ef
Add optional environment variables to commands
s-mage Jul 12, 2015
54fe5f6
Document changes about env option
s-mage Jul 12, 2015
f07170a
better ls implementation
s-mage Aug 14, 2015
0cb6016
Print error backtrace only by request (wtf method)
s-mage Aug 16, 2015
c9940ac
Better paths completion
s-mage Oct 17, 2015
a2a8fa4
update travis config
s-mage Oct 17, 2015
030898d
update dependencies; remove redundant method
s-mage Oct 24, 2015
a4f3142
Remove redundant method
s-mage Oct 25, 2015
72ef132
change badge to drone.io one
s-mage Oct 25, 2015
cca5a93
update drone badge
s-mage Oct 25, 2015
cce8457
typo
s-mage Oct 25, 2015
7ebbda2
Add basic support to execute strings with executables
s-mage Nov 2, 2015
f1223f9
Add very basic support of pipes
s-mage Nov 26, 2015
3e5b18c
Dir contents is now includes hidden files
s-mage Jan 2, 2016
3a016ea
Quote paths before opening apps
s-mage Jan 2, 2016
1cfc380
Make locate case-insensitive
s-mage Feb 6, 2016
4c6828a
Fix tests; refactor open_command
s-mage Mar 5, 2016
9e62393
Bump version
s-mage Mar 5, 2016
26c3b43
Generate gemspec
s-mage Mar 5, 2016
17d05a2
Update dependencies
s-mage Mar 5, 2016
605614b
Add functionality for hard and symlinking files and directories
Jun 27, 2016
d5bdcd4
rename slink to symlink
Jun 27, 2016
71a1b94
Merge pull request #20 from najamelan/feature/symlink
s-mage Jul 1, 2016
a911f5b
Dont track ruby version
s-mage Feb 25, 2017
d1891d0
Version bump to 0.10.0
s-mage Jun 24, 2017
6ffb201
Updated dependencies; minor refactoring; version bump
s-mage Jun 24, 2017
c90920f
Updated gemspec
s-mage Jun 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rdoc
pkg
.rbenv-version
*.swp
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ task :default => :spec

######################################################

require 'rake/rdoctask'
require 'rdoc/task'

Rake::RDocTask.new do |t|
t.rdoc_dir = 'rdoc'
Expand Down
4 changes: 2 additions & 2 deletions bin/rush
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/rush'
require File.dirname(__FILE__) + '/../lib/rush/shell'
require_relative '../lib/rush'
require_relative '../lib/rush/shell'

shell = Rush::Shell.new

Expand Down
90 changes: 45 additions & 45 deletions lib/rush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,62 @@
# The top-level Rush module has some convenience methods for accessing the
# local box.
module Rush
# Access the root filesystem of the local box. Example:
#
# Rush['/etc/hosts'].contents
#
def self.[](key)
box[key]
end
# Access the root filesystem of the local box. Example:
#
# Rush['/etc/hosts'].contents
#
def self.[](key)
box[key]
end

# Create a dir object from the path of a provided file. Example:
#
# Rush.dir(__FILE__).files
#
def self.dir(filename)
box[::File.expand_path(::File.dirname(filename)) + '/']
end
# Create a dir object from the path of a provided file. Example:
#
# Rush.dir(__FILE__).files
#
def self.dir(filename)
box[::File.expand_path(::File.dirname(filename)) + '/']
end

# Create a dir object based on the shell's current working directory at the
# time the program was run. Example:
#
# Rush.launch_dir.files
#
def self.launch_dir
box[::Dir.pwd + '/']
end
# Create a dir object based on the shell's current working directory at the
# time the program was run. Example:
#
# Rush.launch_dir.files
#
def self.launch_dir
box[::Dir.pwd + '/']
end

# Run a bash command in the root of the local machine. Equivalent to
# Rush::Box.new.bash.
def self.bash(command, options={})
box.bash(command, options)
end
# Run a bash command in the root of the local machine. Equivalent to
# Rush::Box.new.bash.
def self.bash(command, options={})
box.bash(command, options)
end

# Pull the process list for the local machine. Example:
# Pull the process list for the local machine. Example:
#
# Rush.processes.filter(:cmdline => /ruby/)
#
def self.processes
box.processes
end
#
def self.processes
box.processes
end

# Get the process object for this program's PID. Example:
# Get the process object for this program's PID. Example:
#
# puts "I'm using #{Rush.my_process.mem} blocks of memory"
#
def self.my_process
box.processes.filter(:pid => ::Process.pid).first
end
#
def self.my_process
box.processes.filter(:pid => ::Process.pid).first
end

# Create a box object for localhost.
def self.box
@@box = Rush::Box.new
end
# Create a box object for localhost.
def self.box
@@box = Rush::Box.new
end

# Quote a path for use in backticks, say.
def self.quote(path)
path.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
# Quote a path for use in backticks, say.
def self.quote(path)
path.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
end

module Rush::Connection; end
Expand Down
242 changes: 116 additions & 126 deletions lib/rush/access.rb
Original file line number Diff line number Diff line change
@@ -1,130 +1,120 @@
# A class to hold permissions (read, write, execute) for files and dirs.
# See Rush::Entry#access= for information on the public-facing interface.
class Rush::Access
attr_accessor :user_can_read, :user_can_write, :user_can_execute
attr_accessor :group_can_read, :group_can_write, :group_can_execute
attr_accessor :other_can_read, :other_can_write, :other_can_execute

def self.roles
%w(user group other)
end

def self.permissions
%w(read write execute)
end

def parse(options)
options.each do |key, value|
next unless m = key.to_s.match(/(.*)_can$/)
key = m[1].to_sym
roles = extract_list('role', key, self.class.roles)
perms = extract_list('permission', value, self.class.permissions)
set_matrix(perms, roles)
end
self
end

def self.parse(options)
new.parse(options)
end

def apply(full_path)
FileUtils.chmod(octal_permissions, full_path)
rescue Errno::ENOENT
raise Rush::DoesNotExist, full_path
end

def to_hash
hash = {}
self.class.roles.each do |role|
self.class.permissions.each do |perm|
key = "#{role}_can_#{perm}".to_sym
hash[key] = send(key) ? 1 : 0
end
end
hash
end

def display_hash
hash = {}
to_hash.each do |key, value|
hash[key] = true if value == 1
end
hash
end

def from_hash(hash)
self.class.roles.each do |role|
self.class.permissions.each do |perm|
key = "#{role}_can_#{perm}"
send("#{key}=".to_sym, hash[key.to_sym].to_i == 1 ? true : false)
end
end
self
end

def self.from_hash(hash)
new.from_hash(hash)
end

def octal_permissions
perms = [ 0, 0, 0 ]
perms[0] += 4 if user_can_read
perms[0] += 2 if user_can_write
perms[0] += 1 if user_can_execute

perms[1] += 4 if group_can_read
perms[1] += 2 if group_can_write
perms[1] += 1 if group_can_execute

perms[2] += 4 if other_can_read
perms[2] += 2 if other_can_write
perms[2] += 1 if other_can_execute

eval("0" + perms.join)
end

def from_octal(mode)
perms = octal_integer_array(mode)

self.user_can_read = (perms[0] & 4) > 0 ? true : false
self.user_can_write = (perms[0] & 2) > 0 ? true : false
self.user_can_execute = (perms[0] & 1) > 0 ? true : false

self.group_can_read = (perms[1] & 4) > 0 ? true : false
self.group_can_write = (perms[1] & 2) > 0 ? true : false
self.group_can_execute = (perms[1] & 1) > 0 ? true : false

self.other_can_read = (perms[2] & 4) > 0 ? true : false
self.other_can_write = (perms[2] & 2) > 0 ? true : false
self.other_can_execute = (perms[2] & 1) > 0 ? true : false

self
end

def octal_integer_array(mode)
mode %= 01000 # filter out everything but the bottom three digits
mode = sprintf("%o", mode) # convert to string
mode.split("").map { |p| p.to_i } # and finally, array of integers
end

def set_matrix(perms, roles)
perms.each do |perm|
roles.each do |role|
meth = "#{role}_can_#{perm}=".to_sym
send(meth, true)
end
end
end

def extract_list(type, value, choices)
list = parts_from(value)
list.each do |value|
raise(Rush::BadAccessSpecifier, "Unrecognized #{type}: #{value}") unless choices.include? value
end
end

def parts_from(value)
value.to_s.split('_').reject { |r| r == 'and' }
end
ROLES = %w(user group other)
PERMISSIONS = %w(read write execute)
ACCESS_UNITS = ROLES.product(PERMISSIONS).
map { |r, p| "#{r}_can_#{p}".to_sym }

attr_accessor *ACCESS_UNITS

def self.roles
ROLES
end

def self.permissions
PERMISSIONS
end

def parse(options)
options.each do |key, value|
next unless m = key.to_s.match(/(.*)_can$/)
key = m[1].to_sym
roles = extract_list('role', key, self.class.roles)
perms = extract_list('permission', value, self.class.permissions)
set_matrix(perms, roles)
end
self
end

def self.parse(options)
new.parse(options)
end

def apply(full_path)
FileUtils.chmod(octal_permissions, full_path)
rescue Errno::ENOENT
raise Rush::DoesNotExist, full_path
end

def to_hash
ACCESS_UNITS.inject({}) do |hash, unit|
hash.merge(unit => send(unit) ? 1 : 0)
end
end

def display_hash
to_hash.select { |_, v| v == 1 }.
inject({}) { |r, (k, _)| r.merge k => true }
end

def from_hash(hash)
ACCESS_UNITS.each do |unit|
send("#{unit}=".to_sym, hash[unit].to_i == 1 ? true : false)
end
self
end

def self.from_hash(hash)
new.from_hash(hash)
end

def octal_permissions
perms = [ 0, 0, 0 ]
perms[0] += 4 if user_can_read
perms[0] += 2 if user_can_write
perms[0] += 1 if user_can_execute

perms[1] += 4 if group_can_read
perms[1] += 2 if group_can_write
perms[1] += 1 if group_can_execute

perms[2] += 4 if other_can_read
perms[2] += 2 if other_can_write
perms[2] += 1 if other_can_execute

eval("0" + perms.join)
end

def from_octal(mode)
perms = octal_integer_array(mode)

self.user_can_read = (perms[0] & 4) > 0 ? true : false
self.user_can_write = (perms[0] & 2) > 0 ? true : false
self.user_can_execute = (perms[0] & 1) > 0 ? true : false

self.group_can_read = (perms[1] & 4) > 0 ? true : false
self.group_can_write = (perms[1] & 2) > 0 ? true : false
self.group_can_execute = (perms[1] & 1) > 0 ? true : false

self.other_can_read = (perms[2] & 4) > 0 ? true : false
self.other_can_write = (perms[2] & 2) > 0 ? true : false
self.other_can_execute = (perms[2] & 1) > 0 ? true : false

self
end

def octal_integer_array(mode)
mode %= 01000 # filter out everything but the bottom three digits
mode = sprintf("%o", mode) # convert to string
mode.split("").map { |p| p.to_i } # and finally, array of integers
end

def set_matrix(perms, roles)
ROLES.product(PERMISSIONS).
select { |r, p| perms.include?(p) && roles.include?(r) }.
map { |r, p| "#{r}_can_#{p}=".to_sym }.
each { |unit| send unit, true }
end

def extract_list(type, value, choices)
list = parts_from(value)
list.each do |value|
raise(Rush::BadAccessSpecifier, "Unrecognized #{type}: #{value}") unless choices.include? value
end
end

def parts_from(value)
value.to_s.split('_').reject { |r| r == 'and' }
end
end
Loading