Class: Kward::Kwshrc
- Inherits:
-
Object
- Object
- Kward::Kwshrc
- Defined in:
- lib/kward/shell/kwshrc.rb
Overview
Parses the declarative subset of a shell startup file used by kwsh.
Only aliases, exports, and source directives are handled. Other shell syntax is intentionally ignored until kwsh supports scripting.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- VARIABLE_NAME =
/\A[A-Za-z_][A-Za-z0-9_]*\z/- VARIABLE_PATTERN =
/[A-Za-z_][A-Za-z0-9_]*/
Class Method Summary collapse
- .read(paths, env: ENV.to_h) ⇒ Object
- .read_file(path, env: ENV.to_h) ⇒ Object
- .resolve_path(path, cwd:, env: ENV.to_h) ⇒ Object
Instance Method Summary collapse
-
#initialize(env: ENV.to_h) ⇒ Kwshrc
constructor
A new instance of Kwshrc.
- #read(paths) ⇒ Object
- #read_path(path) ⇒ Object
Constructor Details
#initialize(env: ENV.to_h) ⇒ Kwshrc
Returns a new instance of Kwshrc.
33 34 35 36 37 38 |
# File 'lib/kward/shell/kwshrc.rb', line 33 def initialize(env: ENV.to_h) @environment = env.to_h.transform_keys(&:to_s).transform_values(&:to_s) @exports = {} @aliases = {} @loading = [] end |
Class Method Details
.read(paths, env: ENV.to_h) ⇒ Object
17 18 19 |
# File 'lib/kward/shell/kwshrc.rb', line 17 def self.read(paths, env: ENV.to_h) new(env: env).read(paths) end |
.read_file(path, env: ENV.to_h) ⇒ Object
21 22 23 24 |
# File 'lib/kward/shell/kwshrc.rb', line 21 def self.read_file(path, env: ENV.to_h) parser = new(env: env) parser.read_path(path) end |
.resolve_path(path, cwd:, env: ENV.to_h) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/kward/shell/kwshrc.rb', line 26 def self.resolve_path(path, cwd:, env: ENV.to_h) parser = new(env: env) = parser.send(:expand_variables, path.to_s) = .sub(/\A~(?=\/|\z)/, Dir.home) File.(, cwd) end |
Instance Method Details
#read(paths) ⇒ Object
40 41 42 43 |
# File 'lib/kward/shell/kwshrc.rb', line 40 def read(paths) Array(paths).each { |path| read_file(path, required: false) } configuration end |
#read_path(path) ⇒ Object
45 46 47 48 |
# File 'lib/kward/shell/kwshrc.rb', line 45 def read_path(path) read_file(path, required: true) configuration end |