rash-command-shell 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rash +1 -1
- data/lib/rash.rb +10 -0
- data/lib/rash/ext/filesystem.rb +74 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f799801cf8b57a584f090320cbd63d7b2e54dbc0e7c66fbac9943d7b75e35417
|
4
|
+
data.tar.gz: 34b945f7da8b07813f405417c99d091466215b087fb709e71394ad3b551044a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baa2bc0af9d01199949370a1fbea1b4682962842bab8618cdbc2c0fe4a3f30352daa3c7661da1989a21ee82b589f937ddd702b5a7ab139ecd791827e8192bdd7
|
7
|
+
data.tar.gz: b05cc5985f22f293f5574057217c33641db8b409b50ecfb13861b332653c4d67e617ed19980abc50af0467934f41cb8e05d50ea51aa0ba1f9f806fb028645d6e
|
data/bin/rash
CHANGED
@@ -4,7 +4,7 @@ if ARGV.empty?
|
|
4
4
|
exec("irb", "-r", "rash", *ARGV)
|
5
5
|
elsif ARGV[0] =~ /(-)?-v(ersion)?/
|
6
6
|
puts "Rash (c) 2020 Kellen Watt"
|
7
|
-
puts "Version 0.4.
|
7
|
+
puts "Version 0.4.1" # I may forget to update this
|
8
8
|
elsif File.exists?(ARGV[0]) && !File.directory?(ARGV[0])
|
9
9
|
require "rash"
|
10
10
|
file = ARGV.shift
|
data/lib/rash.rb
CHANGED
@@ -12,6 +12,7 @@ class Environment
|
|
12
12
|
Dir.chdir(dir.nil? ? "~" : dir.to_s)
|
13
13
|
@working_directory = Dir.pwd
|
14
14
|
ENV["OLDPWD"] = old.to_s
|
15
|
+
ENV["PWD"] = Dir.pwd
|
15
16
|
Dir.pwd
|
16
17
|
end
|
17
18
|
|
@@ -78,6 +79,10 @@ class Environment
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
82
|
+
def name?(v)
|
83
|
+
v.kind_of?(String) || v.kind_of?(Symbol)
|
84
|
+
end
|
85
|
+
|
81
86
|
private
|
82
87
|
|
83
88
|
def common_init
|
@@ -192,6 +197,11 @@ def which(command)
|
|
192
197
|
nil
|
193
198
|
end
|
194
199
|
|
200
|
+
# This breaks some default IRB functionality
|
201
|
+
# def self.respond_to_missing?(m, *args)
|
202
|
+
#
|
203
|
+
# which(m.to_s) || ($env.alias?(m) && !$env.aliasing_disabled) || $env.local_method?(m) || super
|
204
|
+
# end
|
195
205
|
|
196
206
|
# Note that I defy convention and don't define `respond_to_missing?`. This
|
197
207
|
# is because doing so screws with irb.
|
data/lib/rash/ext/filesystem.rb
CHANGED
@@ -6,13 +6,13 @@ class Environment
|
|
6
6
|
def initialize
|
7
7
|
common_init
|
8
8
|
@working_directory = Directory.root("/")
|
9
|
-
traverse_filetree("/", Dir.pwd)
|
10
9
|
end
|
11
10
|
|
12
11
|
def chdir(dir = nil)
|
13
12
|
old = @working_directory
|
14
|
-
traverse_filetree(
|
13
|
+
traverse_filetree(@working_directory.to_s, (dir.nil? ? "~" : dir.to_s))
|
15
14
|
ENV["OLDPWD"] = old.to_s
|
15
|
+
ENV["PWD"] = Dir.pwd
|
16
16
|
Dir.pwd
|
17
17
|
end
|
18
18
|
|
@@ -38,6 +38,26 @@ class Environment
|
|
38
38
|
@working_directory.local_method(name).call(*args, &block)
|
39
39
|
end
|
40
40
|
|
41
|
+
def local_var(name, v = nil, locked: false)
|
42
|
+
res = nil
|
43
|
+
if v.nil?
|
44
|
+
res = @working_directory.local_variable(name)
|
45
|
+
else
|
46
|
+
@working_directory.set_local_variable(name, v)
|
47
|
+
res = v
|
48
|
+
end
|
49
|
+
@working_directory.lock_variable(name) if locked
|
50
|
+
res
|
51
|
+
end
|
52
|
+
|
53
|
+
def local_var?(name)
|
54
|
+
@working_directory.local_variable?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def local_vars
|
58
|
+
@working_directory.local_variables
|
59
|
+
end
|
60
|
+
|
41
61
|
private
|
42
62
|
|
43
63
|
# from and to are strings
|
@@ -83,6 +103,8 @@ class Environment
|
|
83
103
|
@children = []
|
84
104
|
@local_methods = parent&.unlocked_local_methods || {}
|
85
105
|
@locked_methods = []
|
106
|
+
@local_variables = {}
|
107
|
+
@locked_variables = []
|
86
108
|
end
|
87
109
|
|
88
110
|
def local_method(name)
|
@@ -107,6 +129,55 @@ class Environment
|
|
107
129
|
def local_method?(name)
|
108
130
|
@local_methods.key?(name.to_sym)
|
109
131
|
end
|
132
|
+
|
133
|
+
def local_variable(name)
|
134
|
+
name = name.to_sym
|
135
|
+
@local_variables[name] || @parent&.unlocked_local_variable(name)
|
136
|
+
end
|
137
|
+
|
138
|
+
def local_variable?(name)
|
139
|
+
@local_variables.include?(name.to_sym) || !!@parent&.unlocked_local_variable?(name.to_sym)
|
140
|
+
end
|
141
|
+
|
142
|
+
def local_variables
|
143
|
+
@local_variables.keys + (@parent&.unlocked_local_variables).to_a
|
144
|
+
end
|
145
|
+
|
146
|
+
def set_local_variable(name, value)
|
147
|
+
name = name.to_sym
|
148
|
+
if !@local_variables.key?(name) && @parent&.unlocked_local_variable?(name)
|
149
|
+
@parent&.set_local_variable(name, value)
|
150
|
+
else
|
151
|
+
@local_variables[name] = value
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def unlocked_local_variables
|
156
|
+
@local_variables.keys.filter{|k| !@locked_variables.include?(k)} + (@parent&.unlocked_local_variables).to_a
|
157
|
+
end
|
158
|
+
|
159
|
+
def unlocked_local_variable(name)
|
160
|
+
name = name.to_sym
|
161
|
+
@local_variables.filter{|k| !@locked_variables.include?(k)}[name] || @parent&.unlocked_local_variable(name)
|
162
|
+
end
|
163
|
+
|
164
|
+
def unlocked_local_variable?(name)
|
165
|
+
name = name.to_sym
|
166
|
+
@local_variables.filter{|k,_v| !@locked_variables.include?(k)}.key?(name) ||
|
167
|
+
!!@parent&.unlocked_local_variable?(name)
|
168
|
+
end
|
169
|
+
|
170
|
+
def lock_variable(name)
|
171
|
+
n = name.to_sym
|
172
|
+
raise NameError.new("#{name} is not a local variable", n) unless @local_variables.key?(n)
|
173
|
+
@locked_variables << n unless @locked_variables.include?(n)
|
174
|
+
n
|
175
|
+
end
|
176
|
+
|
177
|
+
def clear_local_variable(name)
|
178
|
+
@local_variables.delete(name.to_sym)
|
179
|
+
name.to_sym
|
180
|
+
end
|
110
181
|
|
111
182
|
def root?
|
112
183
|
parent.nil?
|
@@ -161,3 +232,4 @@ def self.method_missing(m, *args, &block)
|
|
161
232
|
end
|
162
233
|
|
163
234
|
$env = Environment.new
|
235
|
+
$env.chdir(Dir.pwd)
|