please-command-alias-manager 0.0.0-universal-darwin-10
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/please +125 -0
- metadata +65 -0
data/bin/please
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
yamldir = (ENV["PLEASEDIR"]) ? ENV["PLEASEDIR"] : "/usr/local/.please"
|
5
|
+
yamlfile = yamldir + "/please.yml"
|
6
|
+
|
7
|
+
if ARGV.length == 0
|
8
|
+
puts "Please specify an alias or add a new one. --help for help."
|
9
|
+
Process.exit
|
10
|
+
end
|
11
|
+
|
12
|
+
#ensure files presence
|
13
|
+
begin
|
14
|
+
if !FileTest::directory?(yamldir)
|
15
|
+
Dir::mkdir(yamldir)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#load file
|
20
|
+
begin
|
21
|
+
aliasmap = YAML.load_file yamlfile
|
22
|
+
rescue
|
23
|
+
aliasmap = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
if (!aliasmap)
|
27
|
+
aliasmap = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
#collect arguments
|
31
|
+
arguments = []
|
32
|
+
ARGV.each do|a|
|
33
|
+
arguments.push(a)
|
34
|
+
#puts arguments[arguments.length - 1];
|
35
|
+
end
|
36
|
+
|
37
|
+
if (arguments[0] === '--help')
|
38
|
+
puts "\n"
|
39
|
+
puts "Please - an alias manager by David LeMieux\n\n"
|
40
|
+
puts "Commands:\n"
|
41
|
+
puts " --add 'new alias' 'aliased command' 'working dir'(optional)\n"
|
42
|
+
puts " --del 'new alias'"
|
43
|
+
puts " --list to see list of aliases\n"
|
44
|
+
puts "\n"
|
45
|
+
puts "You can store your please aliases in a custom directory by exporting PLEASEDIR\n"
|
46
|
+
puts "\n"
|
47
|
+
Process.exit
|
48
|
+
elsif (arguments[0] === '--list')
|
49
|
+
aliasmap = aliasmap.sort {|a,b| a[0]<=>b[0]}
|
50
|
+
aliasmap.each {|key, value|
|
51
|
+
puts ">" + key.rjust(30) + " = " + value["command"]
|
52
|
+
}
|
53
|
+
Process.exit
|
54
|
+
elsif (arguments[0] === '--add')
|
55
|
+
if (!arguments[1] || !arguments[2])
|
56
|
+
puts "Not enough arguments."
|
57
|
+
Process.exit
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
newcommand = {"command"=>arguments[2],"dir"=>(arguments[3]||"")}
|
62
|
+
aliasmap[arguments[1]] = newcommand
|
63
|
+
File.open(yamlfile, "w") {|f| f.write((aliasmap.to_yaml()))}
|
64
|
+
rescue
|
65
|
+
puts "Error adding alias to file."
|
66
|
+
end
|
67
|
+
|
68
|
+
Process.exit
|
69
|
+
elsif (arguments[0] === '--del')
|
70
|
+
if (!arguments[1])
|
71
|
+
puts "Not enough arguments."
|
72
|
+
Process.exit
|
73
|
+
end
|
74
|
+
|
75
|
+
begin
|
76
|
+
aliasmap.delete(arguments[1])
|
77
|
+
File.open(yamlfile, "w") {|f| f.write((aliasmap.to_yaml()))}
|
78
|
+
rescue
|
79
|
+
puts "Error deleting alias from file."
|
80
|
+
end
|
81
|
+
|
82
|
+
Process.exit
|
83
|
+
end
|
84
|
+
|
85
|
+
begin
|
86
|
+
aliname = ""
|
87
|
+
|
88
|
+
arguments.each_with_index do|arg, index|
|
89
|
+
aliname << arg
|
90
|
+
if (index < arguments.length - 1)
|
91
|
+
aliname << " "
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# puts aliname
|
96
|
+
ali = aliasmap[aliname]
|
97
|
+
|
98
|
+
if (ali == nil)
|
99
|
+
puts "No alias found."
|
100
|
+
Process.exit
|
101
|
+
end
|
102
|
+
|
103
|
+
if (ali["dir"] && ali["dir"] != "")
|
104
|
+
Dir.chdir(ali["dir"])
|
105
|
+
end
|
106
|
+
|
107
|
+
alicmd = ali["command"]
|
108
|
+
# puts "Command to run #{alicmd}"
|
109
|
+
|
110
|
+
#TODO loop over "tokens" in alicmd and ask for inputs
|
111
|
+
inputs = alicmd.scan(/\{([^\}]+)\}/)
|
112
|
+
inputs.each{|e|
|
113
|
+
printf "#{e[0]}: "
|
114
|
+
input = $stdin.gets.chomp
|
115
|
+
alicmd = alicmd.gsub(/\{#{e[0]}\}/, input)
|
116
|
+
}
|
117
|
+
|
118
|
+
#puts "Final command #{alicmd}"
|
119
|
+
|
120
|
+
exec( alicmd )
|
121
|
+
|
122
|
+
rescue StandardError => error
|
123
|
+
puts "Error executing alias."
|
124
|
+
puts error
|
125
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: please-command-alias-manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: universal-darwin-10
|
12
|
+
authors:
|
13
|
+
- David LeMieux
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-30 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Use please to manage complex aliases and other repeatedely used terminal commands. please can normal aliases or aliases with arguments.
|
22
|
+
email: lemieuxster@gmai.com
|
23
|
+
executables:
|
24
|
+
- please
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- bin/please
|
31
|
+
homepage: http://github.com/lemieuxster/please
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.15
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: A polite alias manager.
|
64
|
+
test_files: []
|
65
|
+
|