cmd_tools 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/bak ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # bak is an abbreviation of backup.
4
+ # Backup files and directories in the current directory into ./bak_since_ directory.
5
+
6
+ if ARGV.empty?
7
+ puts <<-EOS
8
+ #
9
+ $ bak file1 file2 ...
10
+ #
11
+ EOS
12
+
13
+ exit
14
+ end
15
+
16
+ require 'fileutils'
17
+ require 'find'
18
+
19
+ BAK_DIR_HEAD = "bak_since_"
20
+ BAK_DIR_REG = /(\A|\/)#{BAK_DIR_HEAD}\d{12}\z/
21
+ BAK_PREFIX = 'bak.'
22
+ CURRENT_TIME = Time.now.strftime("%y%m%d%H%M%S")
23
+ BAK_DIR\
24
+ = Dir.foreach('.')\
25
+ .select{|path| path =~ BAK_DIR_REG}\
26
+ .select{|path| File.directory?(path)}\
27
+ .first\
28
+ || BAK_DIR_HEAD + CURRENT_TIME
29
+ BAK_DIR_IN_BAK_DIR_REG = /\A#{BAK_DIR}\/.*#{BAK_DIR_HEAD}\d{12}\z/
30
+
31
+ FileUtils.mkdir_p(BAK_DIR)
32
+ (ARGV.map{|path| path.chomp('/')} - ['.', '..', BAK_DIR])\
33
+ .select{|path| File.exist?(path)}\
34
+ .each{|path|
35
+ dest = File.join(BAK_DIR, "#{BAK_PREFIX}#{path}.#{CURRENT_TIME}#{File.extname(path)}")
36
+ $stdout.puts "Back up #{path}"
37
+ FileUtils.cp_r(path, dest)
38
+
39
+ Find.find(dest){|path_in_dest|
40
+ if path_in_dest =~ BAK_DIR_IN_BAK_DIR_REG && File.directory?(path_in_dest)
41
+ $stdout.puts "Delete #{path_in_dest}? [y/N]"
42
+ if $stdin.gets.strip =~ /\A[yY]/
43
+ $stdout.puts "Deleting: #{path_in_dest}"
44
+ FileUtils.rm_rf(path_in_dest)
45
+ Find.prune
46
+ end
47
+ end
48
+ }
49
+ }
data/bin/tsh ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # tsh is an abbreviation of trash.
4
+ # Move files and directories to ~/.myTrash directory.
5
+ # Should be safer than direct rm.
6
+
7
+ if ARGV.empty?
8
+ puts <<-EOS
9
+ #
10
+ >tsh fileOrDir1 fileOrDir2 ...
11
+ #
12
+ EOS
13
+
14
+ exit
15
+ end
16
+
17
+ require 'fileutils'
18
+ MY_TRASH_DIR = File.join(ENV['HOME'], '.myTrash')
19
+ CURRENT_TIME = Time.now.strftime("%y%m%d%H%M%S.")
20
+ PREFIX = File.join(MY_TRASH_DIR, CURRENT_TIME)
21
+
22
+ FileUtils.mkdir_p(MY_TRASH_DIR)
23
+ puts (ARGV - %w(. ..))\
24
+ .select{|path| File.exist?(path)}\
25
+ .each{|path| FileUtils.mv(path, PREFIX + File.basename(path))}\
26
+ .join("\t")
data/cmd_tools.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ require 'ruby_patch'
2
+
3
+ gem_name = File.basename(__DIR__)
4
+ require "./lib/#{gem_name}/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.files = `git ls-files`.split
8
+ s.name = gem_name
9
+ s.summary = "Command line tools."
10
+ s.version = CmdTools::VERSION
11
+
12
+ s.add_development_dependency 'ruby_patch', '~> 0'
13
+ s.author = 'kshramt'
14
+ s.description = "Command line tools. tsh: mv to ~/.myTrash. bak: bakup."
15
+ s.executables << 'bak'
16
+ s.executables << 'tsh'
17
+ s.required_ruby_version = '>= 1.9.0'
18
+ end
@@ -0,0 +1,3 @@
1
+ module CmdTools
2
+ VERSION = '0.0.0'
3
+ end
data/lib/cmd_tools.rb ADDED
@@ -0,0 +1,3 @@
1
+ module CmdTools
2
+ require 'cmd_tools/version'
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmd_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kshramt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby_patch
16
+ requirement: &72363320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *72363320
25
+ description: ! 'Command line tools. tsh: mv to ~/.myTrash. bak: bakup.'
26
+ email:
27
+ executables:
28
+ - bak
29
+ - tsh
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - bin/bak
34
+ - bin/tsh
35
+ - cmd_tools.gemspec
36
+ - lib/cmd_tools.rb
37
+ - lib/cmd_tools/version.rb
38
+ homepage:
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: 1.9.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.11
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Command line tools.
62
+ test_files: []
63
+ has_rdoc: