bath 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/bath +12 -55
- data/lib/initialize.rb +74 -0
- metadata +2 -1
data/bin/bath
CHANGED
@@ -1,63 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'pathname'
|
4
|
+
library = Pathname.new(__FILE__).realpath.dirname.parent.join("lib").to_s
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(library)
|
7
|
+
|
8
|
+
require 'initialize'
|
9
|
+
|
3
10
|
if ARGV[1].to_s.empty?
|
4
|
-
|
5
|
-
exit 0
|
11
|
+
Bath.help
|
6
12
|
end
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
case ARGV.first when 'link', 'add'
|
11
|
-
file = ARGV[1]
|
12
|
-
|
13
|
-
if !File.exist?(file)
|
14
|
-
puts "Unfortunately, #{file} was not found."
|
15
|
-
exit 0
|
16
|
-
end
|
17
|
-
|
18
|
-
if !File.directory?(bin)
|
19
|
-
puts "#{bin} does not exist!"
|
20
|
-
puts "creating #{bin}..."
|
21
|
-
system "mkdir -p #{bin}"
|
22
|
-
end
|
23
|
-
|
24
|
-
if File.extname(file).empty?
|
25
|
-
if File.symlink?(bin + file)
|
26
|
-
puts "Unfortunately, #{bin + file} already exists."
|
27
|
-
exit 0
|
28
|
-
end
|
29
|
-
|
30
|
-
name = bin + file
|
31
|
-
|
32
|
-
puts "Symlinking #{file} to #{name}..."
|
33
|
-
File.symlink(File.expand_path(file), name)
|
34
|
-
system "chmod +x #{name}"
|
35
|
-
else
|
36
|
-
name = file.split(File.extname(file))
|
37
|
-
name = bin + name.first
|
38
|
-
|
39
|
-
if File.symlink?(name)
|
40
|
-
puts "Unfortunately, #{name} already exists."
|
41
|
-
exit 0
|
42
|
-
end
|
43
|
-
|
44
|
-
puts "Symlinking #{file} to #{name}..."
|
45
|
-
File.symlink(File.expand_path(file), name)
|
46
|
-
system "chmod +x #{name}"
|
47
|
-
end
|
48
|
-
|
49
|
-
warn "/usr/local/bin is not in your PATH." unless ENV['PATH'].split(':').include? '/usr/local/bin'
|
14
|
+
case ARGV.first when 'link', 'add'
|
15
|
+
Bath.link(ARGV)
|
50
16
|
when 'ulink', 'unlink', 'rm', 'remove'
|
51
|
-
|
52
|
-
|
53
|
-
if !File.exist?(bin + file)
|
54
|
-
puts "Unfortunately, #{bin + file} was not found."
|
55
|
-
exit 0
|
56
|
-
end
|
57
|
-
|
58
|
-
puts "Removing #{file} from #{bin}"
|
59
|
-
system "rm #{bin + file}"
|
60
|
-
|
17
|
+
Bath.ulink(ARGV)
|
61
18
|
else
|
62
|
-
|
19
|
+
Bath.help
|
63
20
|
end
|
data/lib/initialize.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
BIN = "/usr/local/bin/"
|
2
|
+
PATH = "/usr/local/bin"
|
3
|
+
|
4
|
+
class Bath
|
5
|
+
def self.link(argv)
|
6
|
+
file = ARGV[1]
|
7
|
+
|
8
|
+
if !File.exist?(file)
|
9
|
+
puts "Unfortunately, #{file} was not found."
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
if !File.directory?(BIN)
|
14
|
+
puts "#{BIN} does not exist!"
|
15
|
+
puts "creating #{BIN}"
|
16
|
+
system "mkdir -p #{BIN}"
|
17
|
+
end
|
18
|
+
|
19
|
+
if File.extname(file).empty?
|
20
|
+
if File.symlink?(BIN + file)
|
21
|
+
puts "Unfortunately, #{BIN + file} already exists."
|
22
|
+
exit 0
|
23
|
+
end
|
24
|
+
|
25
|
+
name = BIN + file
|
26
|
+
|
27
|
+
puts "Symlinking #{file} to #{name}..."
|
28
|
+
File.symlink(File.expand_path(file), name)
|
29
|
+
system "chmod +x #{name}"
|
30
|
+
else
|
31
|
+
name = file.split(File.extname(file))
|
32
|
+
name = BIN + name.first
|
33
|
+
|
34
|
+
if File.symlink?(name)
|
35
|
+
puts "Unfortunately, #{name} already exists."
|
36
|
+
exit 0
|
37
|
+
end
|
38
|
+
|
39
|
+
puts "Symlinking #{file} to #{name}..."
|
40
|
+
File.symlink(File.expand_path(file), name)
|
41
|
+
system "chmod +x #{name}"
|
42
|
+
end
|
43
|
+
|
44
|
+
warn "#{PATH} is not in your PATH." unless ENV['PATH'].split(':').include? PATH
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.ulink(argv)
|
48
|
+
file = ARGV[1]
|
49
|
+
|
50
|
+
if !File.exist?(BIN + file)
|
51
|
+
puts "Unfortunately, #{BIN + file} was not found."
|
52
|
+
exit 0
|
53
|
+
end
|
54
|
+
|
55
|
+
puts "Removing #{file} from #{BIN}"
|
56
|
+
system "rm #{BIN + file}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.help
|
60
|
+
helpstring = <<-EOS
|
61
|
+
|
62
|
+
Using bath is pretty easy. In fact, there are only two options!
|
63
|
+
|
64
|
+
bath link <file>
|
65
|
+
bath ulink <linkname>
|
66
|
+
|
67
|
+
Get linking!
|
68
|
+
|
69
|
+
EOS
|
70
|
+
|
71
|
+
puts helpstring
|
72
|
+
exit 0
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,6 +18,7 @@ executables:
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- lib/initialize.rb
|
21
22
|
- bin/bath
|
22
23
|
homepage: https://github.com/dejay/bath
|
23
24
|
licenses: []
|