nrser-rash 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +104 -0
  3. data/.gitmodules +4 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +4 -0
  6. data/.yardopts +7 -0
  7. data/Gemfile +10 -0
  8. data/README.md +4 -0
  9. data/Rakefile +6 -0
  10. data/bash/source-profile.sh +17 -0
  11. data/dev/bin/.gitkeep +0 -0
  12. data/dev/bin/console +33 -0
  13. data/dev/bin/rake +3 -0
  14. data/dev/bin/rash +16 -0
  15. data/dev/bin/rspec +3 -0
  16. data/dev/ref/autocomplete.rb +62 -0
  17. data/dev/scratch/apps.AppleScript +14 -0
  18. data/dev/scratch/blocks.rb +232 -0
  19. data/dev/scratch/decorating_methods.rb +18 -0
  20. data/dev/scratch/functions.sh +80 -0
  21. data/dev/scratch/if.sh +16 -0
  22. data/dev/scratch/inc.rb +3 -0
  23. data/dev/scratch/inheriting_env/main.rb +44 -0
  24. data/dev/scratch/inheriting_env/sub.rb +9 -0
  25. data/dev/scratch/load_main.rb +5 -0
  26. data/dev/scratch/load_module.rb +19 -0
  27. data/dev/scratch/lsregister-dump.txt +30165 -0
  28. data/dev/scratch/main.rb +4 -0
  29. data/dev/scratch/optparse.rb +43 -0
  30. data/dev/scratch/overridding-cd.sh +53 -0
  31. data/dev/scratch/path.sh +22 -0
  32. data/dev/scratch/pirating_methods.rb +62 -0
  33. data/dev/scratch/profile.sh +624 -0
  34. data/dev/scratch/return.sh +5 -0
  35. data/dev/scratch/source_rvm.sh +11 -0
  36. data/dev/scratch/stub-names/project/test +3 -0
  37. data/exe/rash +4 -0
  38. data/lib/nrser/rash/cli/call.rb +137 -0
  39. data/lib/nrser/rash/cli/help.rb +29 -0
  40. data/lib/nrser/rash/cli/list.rb +36 -0
  41. data/lib/nrser/rash/cli/run.rb +54 -0
  42. data/lib/nrser/rash/cli.rb +21 -0
  43. data/lib/nrser/rash/config.rb +172 -0
  44. data/lib/nrser/rash/core_ext/object.rb +55 -0
  45. data/lib/nrser/rash/formatters.rb +105 -0
  46. data/lib/nrser/rash/functions.rb +154 -0
  47. data/lib/nrser/rash/helpers.rb +53 -0
  48. data/lib/nrser/rash/testing.rb +305 -0
  49. data/lib/nrser/rash/util.rb +260 -0
  50. data/lib/nrser/rash/version.rb +17 -0
  51. data/lib/nrser/rash.rb +40 -0
  52. data/nrser-rash.gemspec +48 -0
  53. data/tmp/.gitkeep +0 -0
  54. metadata +248 -0
@@ -0,0 +1,4 @@
1
+ # load 'inc.rb', true
2
+ require './inc.rb'
3
+
4
+ f 'blah'
@@ -0,0 +1,43 @@
1
+ # play with optparse
2
+
3
+ # A script that will pretend to resize a number of images
4
+ require 'optparse'
5
+
6
+ # This hash will hold all of the options
7
+ # parsed from the command-line by
8
+ # OptionParser.
9
+ options = {}
10
+
11
+ optparse = OptionParser.new do |opts|
12
+
13
+ # Define the options, and what they do
14
+ options[:verbose] = false
15
+ opts.on( '-v', '--verbose', 'Output more information' ) do
16
+ options[:verbose] = true
17
+ end
18
+
19
+ options[:quick] = false
20
+ opts.on( '-q', '--quick', 'Perform the task quickly' ) do
21
+ options[:quick] = true
22
+ end
23
+
24
+ options[:logfile] = nil
25
+ opts.on( '-l', '--logfile FILE', 'Write log to FILE' ) do |file|
26
+ options[:logfile] = file
27
+ end
28
+ end
29
+
30
+ puts ARGV.inspect
31
+
32
+ # Parse the command-line. Remember there are two forms
33
+ # of the parse method. The 'parse' method simply parses
34
+ # ARGV, while the 'parse!' method parses ARGV and removes
35
+ # any options found there, as well as any parameters for
36
+ # the options. What's left is the list of files to resize.
37
+ optparse.parse!
38
+
39
+ puts "Being verbose" if options[:verbose]
40
+ puts "Being quick" if options[:quick]
41
+ puts "Logging to file #{options[:logfile]}" if options[:logfile]
42
+
43
+ p ARGV
@@ -0,0 +1,53 @@
1
+ # want to override `cd` so that it will try and change to a local github repo
2
+ # iff regular `cd` fails...
3
+
4
+ function alias_function {
5
+ local ORIG_FUNC=$(declare -f $1)
6
+ local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
7
+ eval "$NEWNAME_FUNC"
8
+ }
9
+
10
+ function is_function {
11
+ local TYPE=$(type "$1")
12
+ if [[ "$TYPE" =~ "is a function" ]]; then
13
+ return 0
14
+ else
15
+ return 1
16
+ fi
17
+ }
18
+
19
+ is_function "cd"
20
+ if [ $? -ne 0 ]; then
21
+ alias_function "cd" "old_cd"
22
+ else
23
+ function old_cd {
24
+ builtin cd "$@"
25
+ }
26
+ fi
27
+
28
+ function cd {
29
+ # first, try to execute the `cd`
30
+ old_cd "$@"
31
+ local RTN="$?"
32
+ if [[ $RTN != 0 ]]; then
33
+ echo "looking for a project..." 1>&2
34
+ if rash call 'Project.resolve_repo' "$1"; then
35
+ old_cd `rash call 'Project.dir' $1`
36
+ return $?
37
+ fi
38
+ fi
39
+ return $RTN
40
+ # echo "cd'ing into '$1'"
41
+ # # see if it looks like `$1` will be a directory we can change to from
42
+ # # here, which takes precendence
43
+ # if [ ! -d $1 ]; then
44
+ # # it doesn't look like it's a dir, so try to
45
+ # rash call 'Project.cd' "$1" --RASH_PRINT_ERRORS=0
46
+ # if [ $? -ne 0 ]; then
47
+ # echo "using old_cd"
48
+ # old_cd "$1"
49
+ # else
50
+ # echo "using Project.cd"
51
+ # Project.cd "$1"
52
+ # fi
53
+ }
@@ -0,0 +1,22 @@
1
+ function split {
2
+ local IFS=:
3
+ local array
4
+ set -f
5
+ array=( $@ )
6
+ set +f
7
+ printf '%s\n' "${array[@]}"
8
+ }
9
+
10
+ # split $PATH
11
+
12
+ function path_prepend {
13
+ export PATH="$1:$PATH"
14
+ }
15
+
16
+ function path_append {
17
+ export PATH="$PATH:$1"
18
+ }
19
+
20
+ path_prepend "blah"
21
+
22
+ echo $PATH
@@ -0,0 +1,62 @@
1
+ # define a module with a class method
2
+ module M
3
+ def self.f
4
+ puts 'success!'
5
+ end
6
+
7
+ def self.h
8
+ puts 'and again!'
9
+ end
10
+ end
11
+
12
+ # this allows it be invoked via
13
+ M.f
14
+
15
+ # but now we want to make it available globally
16
+ #
17
+ # [1]: http://softwarebyjosh.com/2012/01/21/Pirating-Ruby-Methods-For-Fun-And-Profit.html
18
+ # [2]: http://stackoverflow.com/questions/4390329/how-do-we-copy-singleton-methods-between-different-ruby-classes
19
+ # [3]: http://stackoverflow.com/questions/3782026/how-do-i-dynamically-define-a-method-as-private
20
+
21
+ main = self
22
+ # pirate = main.class.new.extend(M)
23
+ M.singleton_methods.each do |name|
24
+ # main.class.send(:define_method, name, &M.method(name))
25
+ Object.instance_eval do
26
+ define_method name, &M.method(name)
27
+ private name
28
+ end
29
+ # M.method(name).unbind.bind(main)
30
+ end
31
+
32
+ # now, will this work?
33
+ f
34
+ # after much fiddling, it seems so
35
+
36
+ # however, we should not be able to invoke f on an `Object` instance
37
+ begin
38
+ Object.new.f
39
+ rescue NoMethodError => e
40
+ puts "success! failed to call `Object.new.f` with: #{ e }"
41
+ end
42
+
43
+ # this matches behavoir when defining on the top-level
44
+ def g
45
+ puts 'blah'
46
+ end
47
+ begin
48
+ Object.new.g
49
+ rescue NoMethodError => e
50
+ puts "success! failed to call `Object.new.g` with: #{ e }"
51
+ end
52
+
53
+ # note that we can use this to fuck up methods on `Object`:
54
+ def to_s
55
+ "hey!"
56
+ end
57
+ class C; end
58
+ begin
59
+ C.new.to_s
60
+ rescue NoMethodError => e
61
+ puts "fuck, we broke `Object.to_s`"
62
+ end