nrser-rash 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +104 -0
- data/.gitmodules +4 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/.yardopts +7 -0
- data/Gemfile +10 -0
- data/README.md +4 -0
- data/Rakefile +6 -0
- data/bash/source-profile.sh +17 -0
- data/dev/bin/.gitkeep +0 -0
- data/dev/bin/console +33 -0
- data/dev/bin/rake +3 -0
- data/dev/bin/rash +16 -0
- data/dev/bin/rspec +3 -0
- data/dev/ref/autocomplete.rb +62 -0
- data/dev/scratch/apps.AppleScript +14 -0
- data/dev/scratch/blocks.rb +232 -0
- data/dev/scratch/decorating_methods.rb +18 -0
- data/dev/scratch/functions.sh +80 -0
- data/dev/scratch/if.sh +16 -0
- data/dev/scratch/inc.rb +3 -0
- data/dev/scratch/inheriting_env/main.rb +44 -0
- data/dev/scratch/inheriting_env/sub.rb +9 -0
- data/dev/scratch/load_main.rb +5 -0
- data/dev/scratch/load_module.rb +19 -0
- data/dev/scratch/lsregister-dump.txt +30165 -0
- data/dev/scratch/main.rb +4 -0
- data/dev/scratch/optparse.rb +43 -0
- data/dev/scratch/overridding-cd.sh +53 -0
- data/dev/scratch/path.sh +22 -0
- data/dev/scratch/pirating_methods.rb +62 -0
- data/dev/scratch/profile.sh +624 -0
- data/dev/scratch/return.sh +5 -0
- data/dev/scratch/source_rvm.sh +11 -0
- data/dev/scratch/stub-names/project/test +3 -0
- data/exe/rash +4 -0
- data/lib/nrser/rash/cli/call.rb +137 -0
- data/lib/nrser/rash/cli/help.rb +29 -0
- data/lib/nrser/rash/cli/list.rb +36 -0
- data/lib/nrser/rash/cli/run.rb +54 -0
- data/lib/nrser/rash/cli.rb +21 -0
- data/lib/nrser/rash/config.rb +172 -0
- data/lib/nrser/rash/core_ext/object.rb +55 -0
- data/lib/nrser/rash/formatters.rb +105 -0
- data/lib/nrser/rash/functions.rb +154 -0
- data/lib/nrser/rash/helpers.rb +53 -0
- data/lib/nrser/rash/testing.rb +305 -0
- data/lib/nrser/rash/util.rb +260 -0
- data/lib/nrser/rash/version.rb +17 -0
- data/lib/nrser/rash.rb +40 -0
- data/nrser-rash.gemspec +48 -0
- data/tmp/.gitkeep +0 -0
- metadata +248 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d0f57a64fe559654975e0fc3d90ad753cd0dec7
|
4
|
+
data.tar.gz: e4109821d0a8d6f44b8462be4e1ed838554f2a8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31577bfde3938e07e52e9127be4a20258233f966f8e50d28698bdab042369741b7e1693a69355a268696331f03f229cc3180380045c01ca8ef52fa5069bdfae2
|
7
|
+
data.tar.gz: 261ebf0901fdc034ab7e5019ec4329a3259820a331ec9bba5bb5a57f93d3a854fa60c79ab59d01fe913276caf4298ec72b88ca5dca670af1321190bdfa77e8c5
|
data/.gitignore
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# BEGIN Ruby.gitignore
|
3
|
+
#
|
4
|
+
/*.gem
|
5
|
+
*.rbc
|
6
|
+
/.config
|
7
|
+
/coverage/
|
8
|
+
/InstalledFiles
|
9
|
+
/pkg/
|
10
|
+
/spec/reports/
|
11
|
+
/spec/examples.txt
|
12
|
+
/test/tmp/
|
13
|
+
/test/version_tmp/
|
14
|
+
/tmp/
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
|
21
|
+
## Documentation cache and generated files:
|
22
|
+
/.yardoc/
|
23
|
+
/_yardoc/
|
24
|
+
/doc/
|
25
|
+
/rdoc/
|
26
|
+
|
27
|
+
## Environment normalization:
|
28
|
+
/.bundle/
|
29
|
+
/vendor/bundle
|
30
|
+
/lib/bundler/man/
|
31
|
+
|
32
|
+
# for a library or gem, you might want to ignore these files since the code is
|
33
|
+
# intended to run in multiple environments; otherwise, check them in:
|
34
|
+
# Gemfile.lock
|
35
|
+
# .ruby-version
|
36
|
+
# .ruby-gemset
|
37
|
+
|
38
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
39
|
+
.rvmrc
|
40
|
+
#
|
41
|
+
# END Ruby.gitignore
|
42
|
+
##############################################################################
|
43
|
+
|
44
|
+
##############################################################################
|
45
|
+
# BEGIN Gem.gitignore
|
46
|
+
#
|
47
|
+
/Gemfile.lock
|
48
|
+
/.ruby-version
|
49
|
+
/.ruby-gemset
|
50
|
+
#
|
51
|
+
# END Gem.gitignore
|
52
|
+
##############################################################################
|
53
|
+
|
54
|
+
##############################################################################
|
55
|
+
# BEGIN Global/OSX.gitignore
|
56
|
+
#
|
57
|
+
.DS_Store
|
58
|
+
.AppleDouble
|
59
|
+
.LSOverride
|
60
|
+
|
61
|
+
# Icon must end with two
|
62
|
+
Icon
|
63
|
+
|
64
|
+
|
65
|
+
# Thumbnails
|
66
|
+
._*
|
67
|
+
|
68
|
+
# Files that might appear in the root of a volume
|
69
|
+
.DocumentRevisions-V100
|
70
|
+
.fseventsd
|
71
|
+
.Spotlight-V100
|
72
|
+
.TemporaryItems
|
73
|
+
.Trashes
|
74
|
+
.VolumeIcon.icns
|
75
|
+
|
76
|
+
# Directories potentially created on remote AFP share
|
77
|
+
.AppleDB
|
78
|
+
.AppleDesktop
|
79
|
+
Network Trash Folder
|
80
|
+
Temporary Items
|
81
|
+
.apdisk
|
82
|
+
#
|
83
|
+
# END Global/OSX.gitignore
|
84
|
+
##############################################################################
|
85
|
+
|
86
|
+
##############################################################################
|
87
|
+
# BEGIN QB.gitingore
|
88
|
+
#
|
89
|
+
# generated qb playbooks
|
90
|
+
.qb-playbook.yml
|
91
|
+
|
92
|
+
# ansible retry files
|
93
|
+
.qb-playbook.retry
|
94
|
+
#
|
95
|
+
# END QB.gitingore
|
96
|
+
##############################################################################
|
97
|
+
|
98
|
+
|
99
|
+
# Project
|
100
|
+
# ============================================================================
|
101
|
+
|
102
|
+
/tmp
|
103
|
+
!/doc/
|
104
|
+
/doc/site/
|
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Install my user functions' deps too
|
4
|
+
eval_gemfile File.join( ENV['ENV_SUPPORT_DIR'], 'rash', 'Gemfile' )
|
5
|
+
|
6
|
+
# Use dev versions
|
7
|
+
# gem 'nrser', path: './dev/packages/gems/nrser'
|
8
|
+
|
9
|
+
# Specify your gem's dependencies in rash.gemspec
|
10
|
+
gemspec
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# this file is sourced from `.bash_profile` to eval the rash profile
|
2
|
+
# source in the environment
|
3
|
+
|
4
|
+
# figure out what dir we're in
|
5
|
+
# from http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
|
6
|
+
SOURCE="${BASH_SOURCE[0]}"
|
7
|
+
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
8
|
+
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
9
|
+
SOURCE="$(readlink "$SOURCE")"
|
10
|
+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
11
|
+
done
|
12
|
+
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
13
|
+
|
14
|
+
# run the script
|
15
|
+
RASH_OUTPUT="$($DIR/../bin/rash profile)"
|
16
|
+
# TODO: should we check the exit code here?
|
17
|
+
eval "$RASH_OUTPUT"
|
data/dev/bin/.gitkeep
ADDED
File without changes
|
data/dev/bin/console
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
|
5
|
+
# Load `nrser` gem and use refinements if it's available
|
6
|
+
begin
|
7
|
+
require 'nrser'
|
8
|
+
rescue LoadError => error
|
9
|
+
puts "WARN -- Failed to load `nrser` gem."
|
10
|
+
puts "WARN -- Add it do your dependencies or edit #{ __FILE__ }"
|
11
|
+
else
|
12
|
+
using NRSER
|
13
|
+
using NRSER::Types
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'nrser/rash'
|
17
|
+
|
18
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
19
|
+
# with your gem easier. You can also use a different console, if you like.
|
20
|
+
|
21
|
+
# Load `pry` if it's available, falling back to `irb`
|
22
|
+
begin
|
23
|
+
require "pry"
|
24
|
+
rescue LoadError => error
|
25
|
+
puts "WARN -- Failed to load `pry` gem."
|
26
|
+
puts "WARN -- Add it do your dependencies or edit #{ __FILE__ }"
|
27
|
+
puts "INFO -- Starting `IRB`..."
|
28
|
+
|
29
|
+
require "irb"
|
30
|
+
IRB.start
|
31
|
+
else
|
32
|
+
Pry.start
|
33
|
+
end
|
data/dev/bin/rake
ADDED
data/dev/bin/rash
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##
|
3
|
+
# Run the local dev version
|
4
|
+
##
|
5
|
+
|
6
|
+
# Uncomment to override with a different `RASH_HOME` (which is where functions
|
7
|
+
# load from)
|
8
|
+
# ENV['RASH_HOME'] = File.join( ENV['RASH_HOME'], 'dev', 'v0.2' )
|
9
|
+
|
10
|
+
root = File.dirname(File.realpath(File.join(__FILE__, '..', '..')))
|
11
|
+
|
12
|
+
Dir.chdir root do
|
13
|
+
require 'bundler/setup'
|
14
|
+
end
|
15
|
+
|
16
|
+
load File.join(root, 'exe', 'rash')
|
data/dev/bin/rspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# NOTE 2018.02.22
|
4
|
+
# This was a start at implementing Bash autocomplete, obviously copied
|
5
|
+
# over from Boxen. Keep around for ref 'cause I really want autocomplete
|
6
|
+
# ASAP.
|
7
|
+
#
|
8
|
+
|
9
|
+
require_relative '../lib/rash'
|
10
|
+
|
11
|
+
module Rash; end
|
12
|
+
|
13
|
+
module Rash::Autocomplete
|
14
|
+
COMMANDS = ['profile', 'call', 'test', 'help']
|
15
|
+
|
16
|
+
# refresh options via: ruby -e 'puts `boxen -h 2>/dev/null`.scan(/\-+[a-z\?-]+/).inspect'
|
17
|
+
# OPTIONS = ["--debug", "--pretend", "--noop", "--report", "--env", "-h", "-?", "--help", "--disable-service", "--enable-service", "--restart-service", "--disable-services", "--enable-services", "--restart-services", "--list-services", "--homedir", "--logfile", "--login", "--no-fde", "--no-pull", "--no-issue", "--stealth", "--token", "--profile", "--future-parser", "--projects", "--srcdir", "--user", "--no-color"]
|
18
|
+
# SERVICE_OPTIONS = OPTIONS.select { |o| o.end_with?("-service") }
|
19
|
+
# DIR_OPTIONS = ["--logfile", "--homedir"]
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def functions
|
23
|
+
Rash.load_functions
|
24
|
+
Rash.function_names
|
25
|
+
end
|
26
|
+
|
27
|
+
def complete typed
|
28
|
+
# return ['a', 'b', 'c']
|
29
|
+
if part = after(typed, COMMANDS)
|
30
|
+
if after(typed, ['call'])
|
31
|
+
functions.select {|name|
|
32
|
+
name.downcase.start_with? part.downcase
|
33
|
+
}
|
34
|
+
else
|
35
|
+
['x']
|
36
|
+
end
|
37
|
+
# elsif after(typed, DIR_OPTIONS)
|
38
|
+
# []
|
39
|
+
else
|
40
|
+
COMMANDS.select { |o| o.start_with?(typed[/([a-z-]*)$/,1].to_s) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def after typed, kind
|
47
|
+
escaped = kind.map {|str| Regexp.escape str}
|
48
|
+
typed[/(#{escaped.join("|")})\s+([^\s]*)?$/, 2]
|
49
|
+
end
|
50
|
+
|
51
|
+
# keep in sync with boxen/service.rb
|
52
|
+
def available_services
|
53
|
+
Dir["/Library/LaunchDaemons/dev.*.plist"].map { |f| f[/dev\.(.*)\.plist/, 1] }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if $0 == __FILE__
|
59
|
+
puts Rash::Autocomplete.complete(ENV["COMP_LINE"])
|
60
|
+
end
|
61
|
+
|
62
|
+
# complete -o default -C "${GH}/nrser/rash/bin/autocomplete.rb" rash
|
@@ -0,0 +1,14 @@
|
|
1
|
+
-- from http://stackoverflow.com/questions/3444326/list-all-applications-output-as-text-file
|
2
|
+
-- seems to work, but takes 3.2s to run for some reason, which is an issue
|
3
|
+
property pLSRegisterPath : "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
|
4
|
+
|
5
|
+
set theAppPaths to every paragraph of (do shell script pLSRegisterPath & " -dump | grep --after-context 1 \"^bundle\" | grep --only-matching \"/.*\\.app\"")
|
6
|
+
|
7
|
+
set theNames to {}
|
8
|
+
repeat with thePath in theAppPaths
|
9
|
+
try
|
10
|
+
copy displayed name of (info for (thePath as POSIX file)) to end of theNames
|
11
|
+
end try
|
12
|
+
end repeat
|
13
|
+
-- choose from list theNames
|
14
|
+
return theNames
|
@@ -0,0 +1,232 @@
|
|
1
|
+
class Writer
|
2
|
+
def initialize(out)
|
3
|
+
@out = out
|
4
|
+
@level = 0
|
5
|
+
@indent = ' ' * 2
|
6
|
+
end
|
7
|
+
|
8
|
+
def indent(&b)
|
9
|
+
@level += 1
|
10
|
+
if b
|
11
|
+
yield
|
12
|
+
dedent
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def dedent
|
17
|
+
@level -= 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def puts(s)
|
21
|
+
@out.puts (@indent * @level) + s
|
22
|
+
end
|
23
|
+
|
24
|
+
def block(start, finish)
|
25
|
+
puts start if start
|
26
|
+
indent
|
27
|
+
yield
|
28
|
+
dedent
|
29
|
+
puts finish if finish
|
30
|
+
end
|
31
|
+
|
32
|
+
def finish_if_block(rtn)
|
33
|
+
if rtn.is_a?(Hash) && rtn.key?(:type)
|
34
|
+
if rtn[:type] == :else_if
|
35
|
+
puts "elif #{rtn[:cond]}\nthen"
|
36
|
+
indent
|
37
|
+
new_rtn = rtn[:block].call
|
38
|
+
dedent
|
39
|
+
finish_if_block new_rtn
|
40
|
+
elsif rtn[:type] == :else
|
41
|
+
puts "else"
|
42
|
+
indent
|
43
|
+
rtn[:block].call
|
44
|
+
dedent
|
45
|
+
puts 'fi'
|
46
|
+
end
|
47
|
+
else
|
48
|
+
puts 'fi'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def else_if_block(cond, &b)
|
53
|
+
{:type => :else_if, :cond => cond, :block => b}
|
54
|
+
end
|
55
|
+
|
56
|
+
def else_block(&b)
|
57
|
+
{:type => :else, :block => b}
|
58
|
+
end
|
59
|
+
|
60
|
+
def if_block(cond, &b)
|
61
|
+
puts "if #{cond}\nthen"
|
62
|
+
indent
|
63
|
+
rtn = yield
|
64
|
+
dedent
|
65
|
+
finish_if_block rtn
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
w = Writer.new($stdout)
|
70
|
+
w.if_block 'x=1' do
|
71
|
+
w.puts 'blah'
|
72
|
+
end
|
73
|
+
|
74
|
+
w.puts ''
|
75
|
+
|
76
|
+
# works, but kinda sucks to read
|
77
|
+
w.if_block 'x == 1' do
|
78
|
+
w.puts 'x is 1'
|
79
|
+
w.else_if_block 'x == 2' do
|
80
|
+
w.puts 'x is 2'
|
81
|
+
w.else_if_block 'x == 3' do
|
82
|
+
w.puts 'x is 3'
|
83
|
+
w.else_block do
|
84
|
+
w.puts 'fuck knows.'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# this would be better
|
91
|
+
# if false
|
92
|
+
# w.if_block 'x == 1' {
|
93
|
+
# w.puts 'x is 1'
|
94
|
+
# }.elsif_block 'x == 2' {
|
95
|
+
# w.puts 'x is 2'
|
96
|
+
# }.else_block {
|
97
|
+
# w.puts 'fuck knows.'
|
98
|
+
# }
|
99
|
+
# end
|
100
|
+
|
101
|
+
# but this would require either delaying the output somehow until we
|
102
|
+
# figured out if there was a subsquent call or having a terminator,
|
103
|
+
# which is an easy solution, but kinda leaky:
|
104
|
+
# if false
|
105
|
+
# w.if_block 'x == 1' {
|
106
|
+
# w.puts 'x is 1'
|
107
|
+
# }.elsif_block 'x == 2' {
|
108
|
+
# w.puts 'x is 2'
|
109
|
+
# }.else_block {
|
110
|
+
# w.puts 'fuck knows.'
|
111
|
+
# }.fi
|
112
|
+
# end
|
113
|
+
|
114
|
+
# hmmm, some sort of invoking call might fix it
|
115
|
+
# def test(x)
|
116
|
+
# puts x.inspect
|
117
|
+
# end
|
118
|
+
# w.if_block w.if_clause('x == 1') {
|
119
|
+
# w.puts 'x is 1'
|
120
|
+
# }.else_clause {
|
121
|
+
# w.puts 'who knows.'
|
122
|
+
# }
|
123
|
+
|
124
|
+
class Writer
|
125
|
+
|
126
|
+
class IfBlock
|
127
|
+
attr_accessor :if_b, :else_if_bs, :else_b
|
128
|
+
|
129
|
+
def initialize
|
130
|
+
@if_b = nil
|
131
|
+
@else_if_bs = []
|
132
|
+
@else_b = nil
|
133
|
+
end
|
134
|
+
|
135
|
+
def if(cond, &b)
|
136
|
+
@if_b = [cond, b]
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
def else_if(cond, &b)
|
141
|
+
@else_if_bs << [cond, b]
|
142
|
+
self
|
143
|
+
end
|
144
|
+
|
145
|
+
def else(&b)
|
146
|
+
@else_b = b
|
147
|
+
self
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def if_block_2
|
152
|
+
block = IfBlock.new
|
153
|
+
yield block
|
154
|
+
puts "if #{block.if_b[0]}\nthen"
|
155
|
+
indent do
|
156
|
+
block.if_b[1].call
|
157
|
+
end
|
158
|
+
block.else_if_bs.each do |else_if_b|
|
159
|
+
puts "elif #{else_if_b[0]}\nthen"
|
160
|
+
indent do
|
161
|
+
else_if_b[1].call
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if block.else_b
|
165
|
+
puts "else"
|
166
|
+
indent do
|
167
|
+
block.else_b.call
|
168
|
+
end
|
169
|
+
end
|
170
|
+
puts "fi"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# maybe this:
|
175
|
+
puts "\n\nhere:\n"
|
176
|
+
w.if_block_2 do |block|
|
177
|
+
block.if 'x == 1' do
|
178
|
+
w.puts 'x is 1'
|
179
|
+
end
|
180
|
+
block.else_if 'x == 2' do
|
181
|
+
w.puts 'x is 2'
|
182
|
+
end
|
183
|
+
block.else_if 'x == 3' do
|
184
|
+
w.puts 'x is 3'
|
185
|
+
end
|
186
|
+
block.else do
|
187
|
+
w.puts 'fuck knows'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# or this:
|
192
|
+
puts "\n\nthere:\n"
|
193
|
+
w.if_block_2 do |block|
|
194
|
+
block.if('x == 1') {
|
195
|
+
w.puts 'x is 1'
|
196
|
+
}.else_if('x == 2') {
|
197
|
+
w.puts 'x is 2'
|
198
|
+
}.else_if('x == 3') {
|
199
|
+
w.puts 'x is 3'
|
200
|
+
}.else {
|
201
|
+
w.puts 'fuck knows'
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
w.if_block_2 do
|
206
|
+
if_ 'x == 1' do
|
207
|
+
w.puts 'x is 1'
|
208
|
+
end
|
209
|
+
elsif_ 'x == 2' do
|
210
|
+
w.puts 'x is 2'
|
211
|
+
end
|
212
|
+
elsif_ 'x == 3' do
|
213
|
+
w.puts 'x is 3'
|
214
|
+
end
|
215
|
+
else_ do
|
216
|
+
w.puts 'fuck knows'
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class Writer
|
221
|
+
def function(name)
|
222
|
+
puts "#{ name } ()\n{"
|
223
|
+
indent do
|
224
|
+
yield
|
225
|
+
end
|
226
|
+
puts "}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
w.function "f" do
|
231
|
+
w.puts "echo 'BLAH'"
|
232
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# i want to programatically decorate methods
|
2
|
+
|
3
|
+
class A
|
4
|
+
def f(x, y)
|
5
|
+
puts "f called with #{x}, #{y}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class B < A
|
10
|
+
[:f].each do |sym|
|
11
|
+
define_method(sym) do
|
12
|
+
puts 'decorated'
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
B.new.f 1, 2
|
@@ -0,0 +1,80 @@
|
|
1
|
+
function test {
|
2
|
+
# `$@` is an array of all the args?
|
3
|
+
echo "$@";
|
4
|
+
}
|
5
|
+
|
6
|
+
# test 1 2 3
|
7
|
+
|
8
|
+
# definitions
|
9
|
+
# -----------
|
10
|
+
|
11
|
+
RUN_DEFS=1
|
12
|
+
if [[ "$RUN_DEFS" -ne "0" ]]; then
|
13
|
+
|
14
|
+
# both seem to work fine in bash and sh
|
15
|
+
#
|
16
|
+
# function keyword style:
|
17
|
+
function test1 {
|
18
|
+
echo "test1 called"
|
19
|
+
}
|
20
|
+
test1
|
21
|
+
|
22
|
+
# empty args style:
|
23
|
+
test2 () {
|
24
|
+
echo "test2 called"
|
25
|
+
}
|
26
|
+
test2
|
27
|
+
|
28
|
+
# you can add empty args to the keyword style:
|
29
|
+
function test3 () {
|
30
|
+
echo "test3 called"
|
31
|
+
}
|
32
|
+
test3
|
33
|
+
|
34
|
+
# but you must have the empty args without the keyword,
|
35
|
+
# this does not work in bash or sh:
|
36
|
+
# test4 {
|
37
|
+
# echo "test4 called"
|
38
|
+
# }
|
39
|
+
# test4
|
40
|
+
|
41
|
+
# i kinda like the function keyword style 'cause i don't think you can
|
42
|
+
# put argument names in the empty args list, so it's kinda confusing
|
43
|
+
#
|
44
|
+
# doesn't work:
|
45
|
+
# test5 (X, Y) {
|
46
|
+
# echo $X
|
47
|
+
# echo $Y
|
48
|
+
# }
|
49
|
+
# test5 "hey" "ho"
|
50
|
+
|
51
|
+
fi
|
52
|
+
|
53
|
+
# function names
|
54
|
+
# --------------
|
55
|
+
|
56
|
+
RUN_NAMES=0
|
57
|
+
if [[ "$RUN_NAMES" -ne "0" ]]; then
|
58
|
+
|
59
|
+
# dots in names work fine in bash, but fail in sh 'cause
|
60
|
+
# the '.' makes in an invalid identifier. i don't have internet right now,
|
61
|
+
# but i *think* that '_' was the only seperator legal in an sh function name
|
62
|
+
function names.1 {
|
63
|
+
echo "names 1 called"
|
64
|
+
}
|
65
|
+
names.1
|
66
|
+
|
67
|
+
names.2 () {
|
68
|
+
echo "names 2 called"
|
69
|
+
}
|
70
|
+
names.2
|
71
|
+
|
72
|
+
# in sh, would need to do something like
|
73
|
+
function names__3 {
|
74
|
+
echo "names 3 called"
|
75
|
+
}
|
76
|
+
names__3
|
77
|
+
|
78
|
+
# ugh
|
79
|
+
|
80
|
+
fi
|
data/dev/scratch/if.sh
ADDED
data/dev/scratch/inc.rb
ADDED