utils 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Rakefile +68 -0
  2. data/VERSION +1 -0
  3. data/bin/chroot-exec +12 -0
  4. data/bin/chroot-libs +18 -0
  5. data/bin/classify +37 -0
  6. data/bin/discover +137 -0
  7. data/bin/edit +74 -0
  8. data/bin/errf +32 -0
  9. data/bin/git-empty +8 -0
  10. data/bin/myex +90 -0
  11. data/bin/number_files +26 -0
  12. data/bin/same_files +37 -0
  13. data/bin/search +205 -0
  14. data/bin/sedit +3 -0
  15. data/bin/sshscreen +68 -0
  16. data/bin/term +21 -0
  17. data/bin/unquarantine_apps +8 -0
  18. data/bin/untest +17 -0
  19. data/bin/utils-install-config +10 -0
  20. data/bin/vacuum_firefox_sqlite +22 -0
  21. data/bin/xmp +74 -0
  22. data/lib/utils.rb +8 -0
  23. data/lib/utils/config.rb +23 -0
  24. data/lib/utils/config/gdb/asm +179 -0
  25. data/lib/utils/config/gdb/ruby +528 -0
  26. data/lib/utils/config/gdbinit +8 -0
  27. data/lib/utils/config/irbrc +455 -0
  28. data/lib/utils/config/rdebugrc +2 -0
  29. data/lib/utils/config/screenrc +143 -0
  30. data/lib/utils/config/vim/autoload/Align.vim +1029 -0
  31. data/lib/utils/config/vim/autoload/AlignMaps.vim +330 -0
  32. data/lib/utils/config/vim/autoload/rails.vim +4744 -0
  33. data/lib/utils/config/vim/autoload/rubycomplete.vim +801 -0
  34. data/lib/utils/config/vim/autoload/sqlcomplete.vim +741 -0
  35. data/lib/utils/config/vim/autoload/vimball.vim +750 -0
  36. data/lib/utils/config/vim/colors/flori.vim +113 -0
  37. data/lib/utils/config/vim/compiler/eruby.vim +40 -0
  38. data/lib/utils/config/vim/compiler/ruby.vim +67 -0
  39. data/lib/utils/config/vim/compiler/rubyunit.vim +34 -0
  40. data/lib/utils/config/vim/ftdetect/ragel.vim +2 -0
  41. data/lib/utils/config/vim/ftdetect/ruby.vim +17 -0
  42. data/lib/utils/config/vim/ftplugin/eruby.vim +100 -0
  43. data/lib/utils/config/vim/ftplugin/ruby.vim +260 -0
  44. data/lib/utils/config/vim/ftplugin/xml.vim +941 -0
  45. data/lib/utils/config/vim/indent/IndentAnything_html.vim +35 -0
  46. data/lib/utils/config/vim/indent/eruby.vim +77 -0
  47. data/lib/utils/config/vim/indent/javascript.vim +116 -0
  48. data/lib/utils/config/vim/indent/ruby.vim +377 -0
  49. data/lib/utils/config/vim/plugin/AlignMapsPlugin.vim +242 -0
  50. data/lib/utils/config/vim/plugin/AlignPlugin.vim +41 -0
  51. data/lib/utils/config/vim/plugin/Decho.vim +592 -0
  52. data/lib/utils/config/vim/plugin/IndentAnything.vim +675 -0
  53. data/lib/utils/config/vim/plugin/bufexplorer.vim +1144 -0
  54. data/lib/utils/config/vim/plugin/cecutil.vim +482 -0
  55. data/lib/utils/config/vim/plugin/fugitive.vim +1703 -0
  56. data/lib/utils/config/vim/plugin/lusty-explorer.vim +1509 -0
  57. data/lib/utils/config/vim/plugin/rails.vim +340 -0
  58. data/lib/utils/config/vim/plugin/rubyextra.vim +193 -0
  59. data/lib/utils/config/vim/plugin/surround.vim +628 -0
  60. data/lib/utils/config/vim/plugin/taglist.vim +4546 -0
  61. data/lib/utils/config/vim/plugin/test/IndentAnything/test.js +131 -0
  62. data/lib/utils/config/vim/plugin/vimballPlugin.vim +40 -0
  63. data/lib/utils/config/vim/syntax/Decho.vim +101 -0
  64. data/lib/utils/config/vim/syntax/eruby.vim +73 -0
  65. data/lib/utils/config/vim/syntax/javascript.vim +246 -0
  66. data/lib/utils/config/vim/syntax/ragel.vim +165 -0
  67. data/lib/utils/config/vim/syntax/ruby.vim +367 -0
  68. data/lib/utils/config/vimrc +461 -0
  69. data/lib/utils/file.rb +49 -0
  70. data/lib/utils/find.rb +54 -0
  71. data/lib/utils/md5.rb +23 -0
  72. data/lib/utils/patterns.rb +34 -0
  73. data/lib/utils/version.rb +8 -0
  74. data/utils.gemspec +33 -0
  75. metadata +183 -0
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ begin
2
+ require 'rake/gempackagetask'
3
+ rescue LoadError
4
+ end
5
+ require 'rake/clean'
6
+ require 'rbconfig'
7
+ include Config
8
+
9
+ PKG_NAME = 'utils'
10
+ PKG_VERSION = File.read('VERSION').chomp
11
+ PKG_FILES = Dir['**/*']#FileList['**/*'].exclude(/(CVS|\.svn|pkg|.git*)/)
12
+ PKG_FILES.reject! { |f| f =~ /\Apkg/ }
13
+
14
+ if defined? Gem
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = PKG_NAME
17
+ s.version = PKG_VERSION
18
+ s.summary = "Some useful command line utilities"
19
+ s.description = "This ruby gem provides some useful command line utilities"
20
+
21
+ s.files = PKG_FILES
22
+
23
+ s.require_path = 'lib'
24
+
25
+ s.bindir = "bin"
26
+ s.executables.concat Dir['bin/*'].map { |f| File.basename(f) }
27
+ s.add_dependency 'spruz'
28
+ s.add_dependency 'term-ansicolor'
29
+
30
+ s.author = "Florian Frank"
31
+ s.email = "flori@ping.de"
32
+ s.homepage = "http://flori.github.com/utils"
33
+ end
34
+
35
+ task :gemspec do
36
+ File.open('utils.gemspec', 'w') do |output|
37
+ output.write spec.to_ruby
38
+ end
39
+ end
40
+
41
+ Rake::GemPackageTask.new(spec) do |pkg|
42
+ pkg.need_tar = true
43
+ pkg.package_files += PKG_FILES
44
+ end
45
+ end
46
+
47
+ desc m = "Writing version information for #{PKG_VERSION}"
48
+ task :version do
49
+ puts m
50
+ File.open(File.join('lib', PKG_NAME, 'version.rb'), 'w') do |v|
51
+ v.puts <<EOT
52
+ module Utils
53
+ # Utils version
54
+ VERSION = '#{PKG_VERSION}'
55
+ VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
56
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
57
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
58
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
59
+ end
60
+ EOT
61
+ end
62
+ end
63
+
64
+ desc "Default task: write version and test"
65
+ task :default => [ :version, :test ]
66
+
67
+ desc "Prepare a release"
68
+ task :release => [ :clean, :version, :gemspec, :package ]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/bin/chroot-exec ADDED
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+ DIR=$1
3
+ test -z "$DIR" && exit 1
4
+ PRG=$2
5
+ test -z "$PRG" && PRG=/bin/bash
6
+ mount -t proc none $DIR/proc
7
+ mount -o bind /dev $DIR/dev
8
+ [ -e "$DIR/etc/resolv.conf" ] && cp -vLf "$DIR/etc/resolv.conf" "$DIR/etc/resolv.conf.bak"
9
+ cp -vLf /etc/resolv.conf "$DIR/etc/resolv.conf"
10
+ chroot $DIR $PRG
11
+ umount $DIR/proc
12
+ umount $DIR/dev
data/bin/chroot-libs ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ include FileUtils::Verbose
5
+
6
+ msg = "Usage: #$0 EXECUTABLE DIR [LIB ..]"
7
+ executable = ARGV.shift or fail msg
8
+ dir = ARGV.shift or fail msg
9
+ dir = File.expand_path dir
10
+ mkdir_p dir
11
+
12
+ executable = `which #{executable}`.chomp
13
+ libs = `ldd #{executable}`.gsub(/^(?:.*?\s+=>\s+|\s+)(.*?)\(.*/, '\1').grep(/\S/).map { |x| x.strip }
14
+ libs.concat ARGV
15
+ cd dir
16
+ for l in libs
17
+ cp l, File.basename(l)
18
+ end
data/bin/classify ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spruz/go'
4
+ include Spruz::GO
5
+
6
+ class ::String
7
+ def camelize(first_letter_in_uppercase = true)
8
+ if first_letter_in_uppercase
9
+ gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
10
+ else
11
+ self[0].chr.downcase + camelize(self)[1..-1]
12
+ end
13
+ end
14
+
15
+ def underscore
16
+ word = dup
17
+ word.gsub!(/::/, '/')
18
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
19
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
20
+ word.tr!("-", "_")
21
+ word.downcase!
22
+ word
23
+ end
24
+ end
25
+
26
+ opts = go 'bd'
27
+
28
+ string = ARGV.shift or fail "need a class/filepath/filename"
29
+
30
+ if opts['d']
31
+ string = string.sub(/.*::/, '') if opts['b']
32
+ print string.underscore + '.rb'
33
+ else
34
+ string = File.basename(string) if opts['b']
35
+ string = string.gsub(/#{Regexp.quote(File.extname(string))}\Z/, '')
36
+ print string.camelize
37
+ end
data/bin/discover ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'utils'
4
+ include Utils::Patterns
5
+ require 'term/ansicolor'
6
+ require 'spruz/xt'
7
+
8
+ class ::String
9
+ include Term::ANSIColor
10
+ end
11
+
12
+ class ::File
13
+ include Utils::FileXt
14
+ end
15
+
16
+ class Finder
17
+ include Utils::Find
18
+
19
+ def initialize(opts = {})
20
+ @args = opts[:args] || {}
21
+ @roots = opts[:roots] || []
22
+ pattern_opts = opts.subhash(:pattern) | {
23
+ :cset => @args['a'],
24
+ :icase => @args['i'],
25
+ }
26
+ @pattern = @args['r'] ?
27
+ RegexpPattern.new(pattern_opts) :
28
+ FuzzyPattern.new(pattern_opts)
29
+ @directory = @args['d']
30
+ @only_directory = @args['D']
31
+ @pathes = []
32
+ end
33
+
34
+ attr_reader :pathes
35
+
36
+ def attempt_match?(path)
37
+ stat = File.stat(path)
38
+ stat.symlink? and stat = File.lstat(path)
39
+ if @only_directory
40
+ stat.directory?
41
+ elsif @directory
42
+ stat.directory? || stat.file? && (stat.size == 0 || File.ascii?(path))
43
+ else
44
+ stat.file? && (stat.size == 0 || File.ascii?(path))
45
+ end
46
+ rescue SystemCallError => e
47
+ warn "Caught #{e.class}: #{e}"
48
+ nil
49
+ end
50
+
51
+ def search
52
+ pathes = []
53
+ find(*@roots) { |file| pathes << file }
54
+ pathes.flatten!
55
+ pathes.uniq!
56
+ pathes.map! { |p| a = File.split(p) ; a.unshift(p) ; a }
57
+ pathes = pathes.map! do |path, dir, file|
58
+ if do_match = attempt_match?(path) and $DEBUG
59
+ warn "Attempt match of #{path.inspect}"
60
+ end
61
+ if do_match and match = @pattern.match(file)
62
+ if FuzzyPattern === @pattern
63
+ current = 0
64
+ bold_file = ''
65
+ score, e = 0, 0
66
+ for i in 1...(match.size)
67
+ match[i] or next
68
+ b = match.begin(i)
69
+ bold_file << file[current...b]
70
+ bold_file << file[b, 1].bold
71
+ score += (b - e)
72
+ e = match.end(i)
73
+ current = b + 1
74
+ end
75
+ bold_file << match.post_match
76
+ [ score, file.size, path, File.join(dir, bold_file) ]
77
+ else
78
+ bold_file = file[0...match.begin(0)] <<
79
+ file[match.begin(0)...match.end(0)].bold <<
80
+ file[match.end(0)..-1]
81
+ [ 0, file.size, path, File.join(dir, bold_file) ]
82
+ end
83
+ end
84
+ end
85
+ pathes.compact!
86
+ @pathes, output = pathes.sort.transpose.values_at(-2, -1)
87
+ if !@args['e'] && output && !output.empty?
88
+ puts output
89
+ end
90
+ self
91
+ end
92
+ end
93
+
94
+ include Spruz::GO
95
+
96
+ def edit_files(pathes)
97
+ system "edit #{pathes.map { |x| "'#{x}'" } * ' '}"
98
+ end
99
+
100
+ def usage
101
+ puts <<-EOT
102
+ Usage: #{File.basename($0)} [OPTS] PATTERN [PATHES]
103
+
104
+ PATTERN is a pattern expression which is find the files. PATHES are the
105
+ directory and file pathes that are searched.
106
+
107
+ Options are
108
+
109
+ -r interpret PATTERN argument as regex not fuzzy
110
+ -d discover directorіes as well
111
+ -D discover only directories
112
+ -c disable color output
113
+ -i use case insensitive matches
114
+ -e open the matching files with edit command
115
+ -a CSET use only character set CSET from PATTERN
116
+ -h display this help
117
+
118
+ EOT
119
+ exit 1
120
+ end
121
+
122
+ args = go 'a:rdDcieh'
123
+ args['h'] and usage
124
+ pattern = ARGV.shift or usage
125
+ roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) }
126
+
127
+ Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args['c']
128
+ STDOUT.sync = true
129
+
130
+ finder = Finder.new(
131
+ :pattern => pattern,
132
+ :args => args,
133
+ :roots => roots
134
+ ).search
135
+ if args['e']
136
+ edit_files finder.pathes
137
+ end
data/bin/edit ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tempfile'
4
+
5
+ def cmd(*parts)
6
+ command = parts.inject([]) do |a, p|
7
+ case
8
+ when p == nil, p == []
9
+ a
10
+ when p.respond_to?(:to_ary)
11
+ a.concat p.to_ary
12
+ else
13
+ a << p.to_s
14
+ end
15
+ end
16
+ $DEBUG and warn command * ' '
17
+ command
18
+ end
19
+
20
+ case `uname -s`
21
+ when /\Adarwin/i
22
+ vim = if File.directory?('/Applications/Installed')
23
+ '/Applications/Installed/MacVim.app/Contents/MacOS/Vim'
24
+ elsif File.directory?('/Applications')
25
+ '/Applications/MacVim.app/Contents/MacOS/Vim'
26
+ else
27
+ fail "cannot find MacVim.app"
28
+ end
29
+ else
30
+ vim = 'gvim'
31
+ geometry = [ '-geometry', '80x59' ]
32
+ end
33
+ servername = [ '--servername', "G#{ENV['USER'].upcase}" ]
34
+
35
+ argv = ARGV.dup
36
+ if argv.empty?
37
+ if !STDIN.tty?
38
+ file = File.new(File.join(Dir.tmpdir, "edit_tmp.#$$"), 'w')
39
+ until STDIN.eof?
40
+ buffer = STDIN.read(8192)
41
+ file.write buffer
42
+ end
43
+ file.close
44
+ argv << file.path
45
+ elsif `#{vim} -g --serverlist`.split.member?(servername)
46
+ system *cmd(vim, '-g', geometry, servername, '--remote', "stupid_trick#{rand}")
47
+ sleep 1
48
+ exec *cmd(vim, '-g', geometry, servername, '--remote-send', '<ESC>:bw<CR>')
49
+ else
50
+ exec *cmd(vim, '-g', geometry, servername)
51
+ end
52
+ end
53
+ unless argv.empty?
54
+ lineno_re = /^\s*([^:]+):(\d+)/
55
+ if argv.first =~ lineno_re
56
+ for a in argv
57
+ if a =~ lineno_re
58
+ system *cmd(vim, '-g', geometry, servername, '--remote', $1)
59
+ sleep 1
60
+ system *cmd(vim, '-g', geometry, servername, '--remote-send', "<ESC>:#$2<CR>")
61
+ else
62
+ system *cmd(vim, '-g', geometry, servername, '--remote', a)
63
+ end
64
+ if a != argv.last
65
+ STDOUT.print "Press enter to edit the next file."
66
+ STDOUT.flush
67
+ STDIN.gets
68
+ end
69
+ end
70
+ else
71
+ exec *cmd(vim, '-g', geometry, servername, '--remote', *argv)
72
+ end
73
+ end
74
+ exit 0
data/bin/errf ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'term/ansicolor'
4
+
5
+ class String
6
+ include Term::ANSIColor
7
+ end
8
+
9
+ file = ARGV.shift
10
+ name = ARGV.shift
11
+ ENV['RUBYOPT'] = "#{ENV['RUBYOPT']} -Iext:lib:test:tests"
12
+
13
+ STDOUT.sync = true
14
+ begin
15
+ output =
16
+ if name
17
+ IO.popen("testrb -p '' -n #{name} #{file}", 'r')
18
+ else
19
+ IO.popen("testrb -p '' #{file}", 'r')
20
+ end
21
+ until output.eof?
22
+ line = output.readline.uncolored
23
+ new_line = line.chomp
24
+ if new_line.sub!(%r(^(?:\s|[\/\[])*([^:]+):(\d+):(.*))) { "#$1:#$2:#$3" }
25
+ puts new_line
26
+ else
27
+ puts line
28
+ end
29
+ end
30
+ ensure
31
+ output and output.close
32
+ end
data/bin/git-empty ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+
3
+ NAME=$1
4
+ test "$NAME" || exit 1
5
+
6
+ git symbolic-ref HEAD refs/heads/$NAME
7
+ rm .git/index
8
+ git clean -fdx
data/bin/myex ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spruz'
4
+ include Spruz::GO
5
+
6
+ def usage
7
+ puts <<EOT
8
+ Usage: #{File.basename($0)} list|create|truncate|insert|replace [OPTION] [TABLES]
9
+
10
+ Commands are
11
+ - list: display all tables in the backup
12
+
13
+ - create: display all create table statements in the backup. If TABLES
14
+ are given, display only those statements.
15
+ -d if this OPTION is given, first drop the table (if it exists)
16
+ before creation.
17
+
18
+ - truncate: all tables or the given TABLES, if they exist.
19
+
20
+ - insert: extract insert statemnts from the backup. If TABLES are given,
21
+ extract only those statements for these TABLES.
22
+ -t if this OPTION is given, truncate the table, before starting
23
+ to insert.
24
+
25
+ - replace: extract insert statemnts from the backup, and convert them
26
+ into replace statements. If TABLES are given, extract only
27
+ those statements for these TABLES.
28
+ EOT
29
+ exit 1
30
+ end
31
+
32
+ def bell(n = 1, s = 1)
33
+ n.times do
34
+ STDERR.print "\a\b"
35
+ sleep s
36
+ end
37
+ end
38
+
39
+ cmd = ARGV.shift or usage
40
+ opts = go('dtD')
41
+
42
+ STDOUT.sync = true
43
+ case cmd
44
+ when 'list'
45
+ STDIN.grep(/^CREATE TABLE `([^`]+)` \(/) { puts $1 }
46
+ when 'create'
47
+ STDIN.grep(/^CREATE TABLE `([^`]+)` \(/) do |stmt|
48
+ table = $1
49
+ next unless ARGV.empty? or ARGV.member?(table)
50
+ if opts['d']
51
+ puts "DROP TABLE IF EXISTS `#{table}`;"
52
+ warn "Dropped table #{table}."
53
+ end
54
+ line = stmt
55
+ puts line
56
+ until line =~ /;$/
57
+ line = STDIN.readline
58
+ puts line
59
+ end
60
+ warn "Created table #{table}."
61
+ end
62
+ when 'truncate'
63
+ STDIN.grep(/^CREATE TABLE `([^`]+)` \(/) do |stmt|
64
+ table = $1
65
+ next unless ARGV.empty? or ARGV.member?(table)
66
+ puts "TRUNCATE TABLE `#{table}`;"
67
+ warn "Truncated table #{table}."
68
+ end
69
+ when 'insert'
70
+ truncated = {}
71
+ STDIN.grep(/^INSERT INTO `(#{ARGV.empty? ? '[^`]+' : ARGV * '|'})`/) do |stmt|
72
+ table = $1
73
+ if opts['t'] and not truncated.key?(table)
74
+ puts "TRUNCATE TABLE `#{table}`;"
75
+ truncated[table] = true
76
+ warn "Truncated table #{table}."
77
+ end
78
+ puts stmt
79
+ warn "Inserted into table #{table}."
80
+ end
81
+ when 'replace'
82
+ STDIN.grep(/^INSERT INTO `(#{ARGV.empty? ? '[^`]+' : ARGV * '|'})`/) do |stmt|
83
+ table = $1
84
+ puts stmt.sub(/^INSERT INTO `(?:[^`]+)`/, "REPLACE INTO `#{table}`")
85
+ warn "Replaced into table #{table}."
86
+ end
87
+ else
88
+ usage
89
+ end
90
+ bell 3