aka2 0.1.9 → 0.1.10.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.config +9 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +61 -28
- data/aka +0 -0
- data/aka.gemspec +6 -17
- data/assets/yes.png +0 -0
- data/bin/console +0 -7
- data/changelog.md +13 -0
- data/install.sh +25 -0
- data/lib/.config +2 -2
- data/lib/aka.rb +236 -1376
- data/lib/aka/config.rb +166 -0
- data/lib/aka/constants.rb +8 -0
- data/lib/aka/core.rb +14 -0
- data/lib/aka/helpers.rb +775 -0
- data/lib/aka/post_message.rb +27 -0
- data/lib/aka/printing.rb +33 -0
- data/lib/aka/string.rb +72 -0
- data/lib/aka/version.rb +1 -1
- data/lib/aka2.rb +29 -0
- data/proj.aka +10 -0
- metadata +31 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f8af39e6917d3db6566784e531da2960dd6425c
|
4
|
+
data.tar.gz: afbf8902580d4834383102b3bd8b55e2ed3f7a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b7bed280b5324ca73a63bff27d478d8869457586b3e618329be96d7ad22b70a1985e572795d113e7334499162dd285afc5ae1d67b87ade5dbaf4b1b1b1ddb4
|
7
|
+
data.tar.gz: aad278dee063571eb04e441d97f9dbccd77ab6e8fd42eb1872fbb5c645d9e4920e0ef6381ad22dfed1407ac21777f35c7d9cfdfb9598dfa762f0e691f543f6f8
|
data/.config
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,53 +1,83 @@
|
|
1
|
-
#
|
1
|
+
# Aka
|
2
2
|
|
3
|
-
|
3
|
+
### The Shortcut Manager for your Everyday Project
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/aka2.svg)](https://badge.fury.io/rb/aka2)
|
6
|
+
|
7
|
+
aka loves and works with alias.
|
4
8
|
|
5
9
|
aka generate/edit/destroy/find permanent aliases with a single command.
|
6
10
|
|
7
|
-
|
11
|
+
aka requires ruby and is built for bash and zsh users.
|
12
|
+
|
13
|
+
| features | alias | aka |
|
14
|
+
| :-----------------------: |:----------------------------:| :-------------------:|
|
15
|
+
| Generate alias | ![Yes](assets/yes.png) | ![Yes](assets/yes.png) |
|
16
|
+
| Destroy alias | ![Yes](assets/yes.png) | ![Yes](assets/yes.png) |
|
17
|
+
| Find and show alias | ![Yes](assets/yes.png) | ![Yes](assets/yes.png) |
|
18
|
+
| Show last few added alias | - | ![Yes](assets/yes.png) |
|
19
|
+
| Edit alias | - | ![Yes](assets/yes.png) |
|
20
|
+
| Count alias | - | ![Yes](assets/yes.png) |
|
21
|
+
| Auto reload dot file | - | ![Yes](assets/yes.png) |
|
22
|
+
| Show usage | - | ![Yes](assets/yes.png) |
|
23
|
+
| Persistency | - | ![Yes](assets/yes.png) |
|
24
|
+
| Add your last command | - | ![Yes](assets/yes.png) |
|
25
|
+
| Export Alias | - | ![Yes](assets/yes.png) |
|
26
|
+
| Group your Aliases | - | ![Yes](assets/yes.png) |
|
27
|
+
| Add Alias to Project | - | ![Yes](assets/yes.png) |
|
8
28
|
|
9
29
|
## Installation
|
10
30
|
|
11
|
-
|
12
|
-
|
31
|
+
gem install aka2
|
32
|
+
aka setup
|
13
33
|
|
14
|
-
If you wish to
|
34
|
+
If you wish to setup aka again:
|
15
35
|
|
16
|
-
|
36
|
+
aka setup --reset
|
17
37
|
|
18
38
|
## Usage
|
19
39
|
|
20
|
-
To generate new
|
40
|
+
To generate new alias
|
41
|
+
|
42
|
+
aka generate hello="echo helloworld"
|
43
|
+
aka g hello="echo helloworld"
|
44
|
+
aka g hello="echo helloworld" --group basic
|
45
|
+
|
46
|
+
To destroy existing alias
|
47
|
+
|
48
|
+
aka destroy hello
|
49
|
+
aka d hello
|
21
50
|
|
22
|
-
|
23
|
-
$ aka g hello="echo helloworld"
|
51
|
+
To edit existing alias
|
24
52
|
|
25
|
-
|
53
|
+
aka edit hello
|
26
54
|
|
27
|
-
|
28
|
-
$ aka d hello
|
55
|
+
To edit alias name
|
29
56
|
|
30
|
-
|
57
|
+
aka edit hello --name
|
31
58
|
|
32
|
-
|
59
|
+
To find an alias
|
33
60
|
|
34
|
-
|
61
|
+
aka find hello
|
35
62
|
|
36
|
-
|
63
|
+
To list all system aliases
|
37
64
|
|
38
|
-
|
65
|
+
aka list
|
66
|
+
aka list 20
|
67
|
+
aka list --number
|
39
68
|
|
40
|
-
$ aka find hello
|
41
69
|
|
42
|
-
To
|
70
|
+
To export your alias into a proj.aka
|
43
71
|
|
44
|
-
|
45
|
-
$ aka list 20
|
46
|
-
$ aka list --number
|
72
|
+
aka export group_name
|
47
73
|
|
48
|
-
To list
|
74
|
+
To list project alias
|
49
75
|
|
50
|
-
|
76
|
+
aka proj
|
77
|
+
|
78
|
+
To list all commands of aka
|
79
|
+
|
80
|
+
aka help
|
51
81
|
|
52
82
|
## Requirement
|
53
83
|
|
@@ -55,9 +85,12 @@ Ruby
|
|
55
85
|
|
56
86
|
## Contributing
|
57
87
|
|
58
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ytbryan/aka
|
59
|
-
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ytbryan/aka
|
60
89
|
|
61
90
|
## License
|
62
91
|
|
63
|
-
|
92
|
+
Aka is released as an open source project under the license of [The MIT License (MIT)](http://www.opensource.org/licenses/MIT)
|
93
|
+
|
94
|
+
## Contact
|
95
|
+
|
96
|
+
[@ytbryan](http://www.twitter.com/ytbryan)
|
data/aka
ADDED
File without changes
|
data/aka.gemspec
CHANGED
@@ -2,34 +2,23 @@
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'aka/version'
|
5
|
+
require 'aka/post_message'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = "aka2"
|
8
9
|
spec.version = Aka::VERSION
|
9
|
-
spec.authors = ["Bryan Lim"
|
10
|
+
spec.authors = ["Bryan Lim"]
|
10
11
|
spec.email = ["ytbryan@gmail.com","gohengkeat89@gmail.com"]
|
11
|
-
|
12
|
-
spec.
|
13
|
-
spec.description = %q{aka generate/edit/destroy/find permanent aliases with a single command. }
|
12
|
+
spec.summary = %q{The Missing Shortcut Manager}
|
13
|
+
spec.description = %q{ A delightful way to manage and grow your aliases in your daily project. }
|
14
14
|
spec.homepage = "https://github.com/ytbryan/aka"
|
15
15
|
spec.license = "MIT"
|
16
|
-
|
17
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
#spec.bindir = "exe"
|
19
|
-
#spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
17
|
spec.executables = ["aka"]
|
21
18
|
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.required_ruby_version = ">= 2.
|
24
|
-
|
25
|
-
|
26
|
-
spec.add_runtime_dependency 'net-scp', '~> 1.2', '>= 1.2.1'
|
27
|
-
# spec.add_runtime_dependency 'open-uri'
|
28
|
-
spec.add_runtime_dependency 'colorize', '~> 0'
|
29
|
-
spec.add_runtime_dependency "safe_yaml", '~> 1.0', '>= 1.0.4'
|
19
|
+
spec.post_install_message = Log::MESSAGE
|
20
|
+
spec.required_ruby_version = ">= 2.0.0"
|
30
21
|
spec.add_runtime_dependency 'thor' , '~> 0.19.1'
|
31
|
-
# spec.add_runtime_dependency 'fileutils'
|
32
|
-
|
33
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
34
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
24
|
spec.add_development_dependency "minitest", "~> 5.7"
|
data/assets/yes.png
ADDED
Binary file
|
data/bin/console
CHANGED
@@ -3,12 +3,5 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "aka"
|
5
5
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
6
|
require "irb"
|
14
7
|
IRB.start
|
data/changelog.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## v0.1.10
|
2
|
+
* Introducing system alias, project alias and groups
|
3
|
+
* Added [aka proj --load] to export certain alias group into a project directory
|
4
|
+
* Added [aka proj --save ] to generate specific aka file
|
5
|
+
* Added [aka proj] to show all project alias
|
6
|
+
* Added [aka groups] to list all groups in the system
|
7
|
+
* Added .profile as setup options. Thanks to fgperianez
|
8
|
+
* Edited test_aka.rb
|
9
|
+
* Refactor the aka code
|
10
|
+
* Remove some dependencies and set required ruby back to 2.0.0.
|
11
|
+
* Change default list to 20 aliases
|
12
|
+
* Start using aka in your projects :)
|
13
|
+
|
1
14
|
## v0.1.9
|
2
15
|
* Added -g option to add grouping to alias
|
3
16
|
* Added -g option to find grouping based on group name
|
data/install.sh
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
3
|
+
sudo apt-get install git
|
4
|
+
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
5
|
+
#mac os x
|
6
|
+
brew install git
|
7
|
+
fi
|
8
|
+
|
9
|
+
#clone rbenv
|
10
|
+
git clone https://github.com/sstephenson/rbenv.git
|
11
|
+
|
12
|
+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
13
|
+
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
|
14
|
+
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
|
15
|
+
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
16
|
+
#mac os x
|
17
|
+
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
18
|
+
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
19
|
+
echo 'Mac OSX'
|
20
|
+
fi
|
21
|
+
|
22
|
+
#install ruby
|
23
|
+
rbenv install 2.2.3
|
24
|
+
|
25
|
+
gem install bundler rails
|
data/lib/.config
CHANGED
data/lib/aka.rb
CHANGED
@@ -1,1488 +1,348 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require
|
1
|
+
require 'aka/version'
|
2
|
+
require 'aka/constants'
|
3
|
+
require 'aka/helpers'
|
4
|
+
require 'aka/printing'
|
5
|
+
require 'aka/core'
|
6
|
+
require 'aka/string'
|
7
|
+
require 'aka/config'
|
8
|
+
|
9
|
+
require 'yaml'
|
6
10
|
require 'thor'
|
11
|
+
require 'shellwords'
|
7
12
|
require 'fileutils'
|
8
13
|
|
9
14
|
module Aka
|
10
15
|
class Base < Thor
|
11
16
|
check_unknown_options!
|
12
|
-
package_name
|
17
|
+
package_name 'aka'
|
13
18
|
default_task :list
|
14
|
-
map
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
desc "where", "locate your dotfile"
|
29
|
-
def where
|
30
|
-
puts readYML("#{Dir.pwd}/.aka/.config")["dotfile"]
|
31
|
-
end
|
32
|
-
|
19
|
+
map 'g' => :generate,
|
20
|
+
'd' => :destroy,
|
21
|
+
'f' => :find,
|
22
|
+
'u' => :usage,
|
23
|
+
'l' => :list,
|
24
|
+
'e' => :edit,
|
25
|
+
'c' => :clean,
|
26
|
+
'h' => :help,
|
27
|
+
'v' => :version
|
28
|
+
|
29
|
+
# desc :open, 'open my dotfile for development'
|
30
|
+
# def open
|
31
|
+
# system("atom #{Aka.readYML("#{CONFIG_PATH}")['dotfile']}")
|
32
|
+
# end
|
33
33
|
#
|
34
|
-
#
|
34
|
+
# desc :testing, 'testing'
|
35
|
+
# def testing(_name, _number)
|
36
|
+
# inp = $stdin.read
|
37
|
+
# puts inp
|
38
|
+
# end
|
35
39
|
#
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
arr.first, #username
|
51
|
-
options.from, #local_path
|
52
|
-
options.to, #remote_path
|
53
|
-
:ssh => {:port => arr[2],
|
54
|
-
:password => password})
|
55
|
-
rescue Exception => e
|
56
|
-
puts "\n#{e}"
|
57
|
-
success = false
|
58
|
-
end
|
59
|
-
|
60
|
-
puts "\nDone." if success
|
61
|
-
else
|
62
|
-
puts "Cannot find #{options.from}"
|
63
|
-
end
|
64
|
-
else
|
65
|
-
puts "Some options are missing:"
|
66
|
-
puts "--of -> #{options.of}"
|
67
|
-
puts "--to -> #{options.to}"
|
68
|
-
puts "--from -> #{options.from}"
|
69
|
-
puts "aka up --of some_string --to some_string --from some_string"
|
70
|
-
end
|
71
|
-
end
|
40
|
+
# desc :test, 'this is where we test our code'
|
41
|
+
# def test
|
42
|
+
# output = []
|
43
|
+
# r, io = IO.pipe
|
44
|
+
# fork do
|
45
|
+
# # system (%(zsh -c 'source ~/.zshrc; aka generate something=\"echo well well\" --no'), out: io, err: :out)
|
46
|
+
# system("zsh -c 'source ~/.zshrc; aka generate something=\"echo well well\" --no; ${=aliases[something]}'", out: io, err: :out)
|
47
|
+
# # system("ruby", "-e 3.times{|i| p i; sleep 1}", out: io, err: :out)
|
48
|
+
# end
|
49
|
+
# io.close
|
50
|
+
# r.each_line { |l| puts l; output << l.chomp }
|
51
|
+
# p output
|
52
|
+
# puts 'boo'
|
53
|
+
# end
|
72
54
|
|
73
55
|
#
|
74
|
-
#
|
56
|
+
# PROJ
|
75
57
|
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
def upload
|
82
|
-
if options.from && options.to && options.login
|
83
|
-
password = get_password()
|
58
|
+
desc :proj, 'list the project alias (short alias: p)'
|
59
|
+
method_option :group, type: :boolean, aliases: '-g'
|
60
|
+
method_option :load, type: :string, aliases: '-l'
|
61
|
+
method_option :save, type: :string, aliases: '-s'
|
62
|
+
method_option :force, type: :boolean, aliases: '-f'
|
84
63
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
rescue Exception => e
|
96
|
-
puts "\n#{e}"
|
97
|
-
success = false
|
98
|
-
end
|
99
|
-
|
100
|
-
puts "\nDone." if success
|
64
|
+
def proj(arg = nil)
|
65
|
+
if options[:load]
|
66
|
+
Aka.export(arg, options[:load], options[:force])
|
67
|
+
elsif options[:save]
|
68
|
+
Aka.import(options[:save])
|
69
|
+
else
|
70
|
+
if options[:group] && File.exist?('proj.aka')
|
71
|
+
Aka.list_all_groups_in_proj_aka
|
72
|
+
elsif options[:group] && !File.exist?('proj.aka')
|
73
|
+
Aka.error_statement('The proj.aka is missing. Please run [aka proj --load <name_of_group>] to generate proj.aka file')
|
101
74
|
else
|
102
|
-
|
75
|
+
if File.exist?('proj.aka')
|
76
|
+
if content = File.open('proj.aka').read
|
77
|
+
Aka.print_title('Project Alias')
|
78
|
+
content_array = Aka.product_content_array(content)
|
79
|
+
answer_count = Aka.print_the_aliases(content_array)
|
80
|
+
Aka.print_helpful_statement(answer_count)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
Aka.error_statement('The proj.aka is missing. Please run [aka proj --load <name_of_group>] to generate proj.aka file')
|
84
|
+
end
|
103
85
|
end
|
104
|
-
|
105
|
-
puts "Some options are missing:"
|
106
|
-
puts "--of -> #{options.of}"
|
107
|
-
puts "--to -> #{options.to}"
|
108
|
-
puts "--from -> #{options.from}"
|
109
|
-
puts "aka up --of some_string --to some_string --from some_string"
|
110
|
-
end
|
86
|
+
end # end of when
|
111
87
|
end
|
112
88
|
|
113
|
-
|
89
|
+
#
|
114
90
|
# GENERATE
|
115
|
-
|
116
|
-
desc
|
117
|
-
method_option :last, :
|
118
|
-
method_option :group, :
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
91
|
+
#
|
92
|
+
desc :generate, 'generate an alias (short alias: g)'
|
93
|
+
method_option :last, type: :boolean, aliases: '-l', desc: ''
|
94
|
+
method_option :group, type: :string, aliases: '-g', desc: '', default: 'default'
|
95
|
+
method_option :no, type: :boolean, aliases: '-n', desc: '--no means do not reload'
|
96
|
+
method_option :empty, type: :boolean, aliases: '-e', desc: 'do not print anything'
|
97
|
+
def generate(args)
|
98
|
+
result = FALSE
|
99
|
+
if options[:last] && args
|
100
|
+
result = Aka.add_with_group(Aka.add_last_command(Aka.parseARGS(args)))
|
124
101
|
else
|
125
|
-
|
126
|
-
result = add_with_group(parseARGS(args), options.group) if args
|
127
|
-
if options.proj? && result == true
|
128
|
-
FileUtils.touch("#{Dir.pwd}/.aka")
|
129
|
-
add_to_proj(args)
|
130
|
-
end
|
102
|
+
result = Aka.add_with_group(Aka.parseARGS(args), options[:group])
|
131
103
|
end
|
132
|
-
reload_dot_file if result ==
|
104
|
+
Aka.reload_dot_file if result == TRUE && !options[:no]
|
105
|
+
TRUE
|
133
106
|
end
|
134
107
|
|
135
108
|
#
|
136
109
|
# DESTROY
|
137
110
|
#
|
138
|
-
desc
|
139
|
-
method_options :
|
111
|
+
desc :destroy, 'destroy an alias (short alias: d)'
|
112
|
+
method_options force: :boolean
|
113
|
+
method_option :no, type: :boolean, aliases: '-n', desc: '--no means do not reload'
|
114
|
+
method_option :nounalias, type: :boolean, aliases: '-u', desc: '--nounalias means do not remove the alias from current shell'
|
140
115
|
def destroy(*args)
|
141
|
-
args.each_with_index do |value,
|
142
|
-
result = remove(value)
|
143
|
-
unalias_the(value) if !options
|
144
|
-
reload_dot_file if result ==
|
116
|
+
args.each_with_index do |value, _index|
|
117
|
+
result = Aka.remove(value)
|
118
|
+
Aka.unalias_the(value) if !options[:nounalias] && result == TRUE
|
119
|
+
Aka.reload_dot_file if result == TRUE && !options[:no]
|
145
120
|
end
|
121
|
+
TRUE
|
146
122
|
end
|
147
123
|
|
148
124
|
#
|
149
125
|
# first step: set config file
|
150
126
|
#
|
151
|
-
desc
|
152
|
-
method_options :
|
127
|
+
desc :setup, 'Gem - Setup aka'
|
128
|
+
method_options reset: :boolean
|
153
129
|
def setup
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
puts "#{configDir} is removed"
|
130
|
+
if options[:reset] && File.exist?("#{CONFIG_PATH}")
|
131
|
+
Aka.remove_autosource
|
132
|
+
FileUtils.rm_r("#{CONFIG_PATH}")
|
133
|
+
puts "#{CONFIG_PATH} is removed"
|
159
134
|
end
|
160
135
|
|
161
|
-
if File.exist?("#{
|
162
|
-
puts ".aka config file is exist in #{
|
163
|
-
puts
|
136
|
+
if File.exist?("#{CONFIG_PATH}")
|
137
|
+
puts ".aka config file is exist in #{CONFIG_PATH}"
|
138
|
+
puts 'Please run [aka setup --reset] to remove aka file and setup again'
|
164
139
|
else
|
165
|
-
setup_config # create and setup .config file
|
166
|
-
setup_aka # put value in .config file
|
167
|
-
puts
|
168
|
-
setup_autosource # create, link source file
|
169
|
-
puts "Congratulation, aka is setup in #{
|
140
|
+
Aka.setup_config # create and setup .config file
|
141
|
+
Aka.setup_aka # put value in .config file
|
142
|
+
puts 'setting up autosource'
|
143
|
+
Aka.setup_autosource # create, link source file
|
144
|
+
puts "Congratulation, aka is setup in #{CONFIG_PATH}"
|
170
145
|
end
|
171
146
|
end
|
172
147
|
|
173
148
|
#
|
174
149
|
# FIND
|
175
150
|
#
|
176
|
-
desc
|
177
|
-
method_options :
|
178
|
-
method_option :group, :
|
179
|
-
def find
|
180
|
-
if options
|
181
|
-
search_alias_with_group_name(options
|
151
|
+
desc :find, 'find an alias (short alias: f)'
|
152
|
+
method_options force: :boolean
|
153
|
+
method_option :group, type: :string, aliases: '-g', desc: ''
|
154
|
+
def find(*args)
|
155
|
+
if options[:group]
|
156
|
+
Aka.search_alias_with_group_name(options[:group])
|
182
157
|
else
|
183
|
-
args.each_with_index do |value,
|
184
|
-
search_alias_return_alias_tokens(value)
|
158
|
+
args.each_with_index do |value, _index|
|
159
|
+
Aka.search_alias_return_alias_tokens(value)
|
185
160
|
end
|
186
161
|
end
|
162
|
+
TRUE
|
187
163
|
end
|
188
164
|
|
189
165
|
#
|
190
166
|
# EDIT
|
191
167
|
#
|
192
|
-
desc
|
193
|
-
method_options :
|
194
|
-
method_options :
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
168
|
+
desc :edit, 'edit an alias(short alias: e)'
|
169
|
+
method_options force: :boolean
|
170
|
+
method_options name: :boolean #--name
|
171
|
+
method_option :group, type: :string, aliases: '-g', desc: ''
|
172
|
+
def edit(args)
|
173
|
+
if options[:group]
|
174
|
+
Aka.change_alias_group_name_with(Aka.parseARGS(args), options[:group])
|
175
|
+
else
|
176
|
+
if args
|
177
|
+
values = args.split('=')
|
178
|
+
if values.size > 1
|
179
|
+
truth, _alias = Aka.search_alias_return_alias_tokens(args)
|
180
|
+
if truth == TRUE
|
181
|
+
if options[:name]
|
182
|
+
# Aka.remove(_alias) #remove that alias
|
183
|
+
Aka.edit_alias_name(values[1], _alias) # edit that alias
|
184
|
+
Aka.reload_dot_file unless options[:noreload]
|
185
|
+
else
|
186
|
+
# Aka.remove(_alias) #remove that alias
|
187
|
+
Aka.edit_alias_command(values[1], _alias) # edit that alias
|
188
|
+
Aka.reload_dot_file unless options[:noreload]
|
189
|
+
end
|
205
190
|
else
|
206
|
-
|
207
|
-
edit_alias_command(values[1], _alias) #edit that alias
|
208
|
-
reload_dot_file() if !options.noreload
|
191
|
+
Aka.error_statement("Alias '#{args}' cannot be found.")
|
209
192
|
end
|
210
193
|
else
|
211
|
-
puts "
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
194
|
+
puts "this is passed in #{args}"
|
195
|
+
truth, _alias, command, group = Aka.search_alias_return_alias_tokens_with_group(args)
|
196
|
+
if truth == TRUE
|
197
|
+
if options[:name]
|
198
|
+
input = ask "Enter a new alias for command '#{command}'?\n"
|
199
|
+
if yes? 'Please confirm the new alias? (y/N)'
|
200
|
+
Aka.remove(_alias) # remove that alias
|
201
|
+
Aka.edit_alias_name_with_group(input, command, group) # edit that alias
|
202
|
+
Aka.reload_dot_file unless options[:noreload]
|
203
|
+
end
|
204
|
+
else
|
205
|
+
input = ask "Enter a new command for alias '#{args}'?\n"
|
206
|
+
if yes? 'Please confirm the new command? (y/N)'
|
207
|
+
Aka.remove(_alias) # remove that alias
|
208
|
+
Aka.edit_alias_command_with_group(input, _alias, group) # edit that alias
|
209
|
+
Aka.reload_dot_file unless options[:noreload]
|
210
|
+
end
|
222
211
|
end
|
223
212
|
else
|
224
|
-
|
225
|
-
if yes? "Please confirm the new command? (y/N)"
|
226
|
-
remove(_alias) #remove that alias
|
227
|
-
edit_alias_command(input, _alias) #edit that alias
|
228
|
-
reload_dot_file() if !options.noreload
|
229
|
-
end
|
213
|
+
Aka.error_statement("Alias '#{args}' cannot be found")
|
230
214
|
end
|
231
|
-
else
|
232
|
-
puts "Alias '#{args}' cannot be found".red
|
233
215
|
end
|
234
|
-
end
|
235
|
-
|
236
|
-
end #if args
|
216
|
+
end # if args
|
217
|
+
end # end else no group option
|
237
218
|
end
|
238
219
|
|
239
220
|
#
|
240
221
|
# LIST OUT - ryan - remove numbering
|
241
222
|
#
|
242
|
-
desc
|
243
|
-
method_options :
|
244
|
-
method_options :
|
245
|
-
|
246
|
-
|
247
|
-
|
223
|
+
desc :list, 'list alias (short alias: l)'
|
224
|
+
method_options force: :boolean
|
225
|
+
method_options number: :boolean
|
226
|
+
method_option :no, type: :boolean, aliases: '-n', desc: '--no means do not reload'
|
227
|
+
method_option :group, type: :boolean, aliases: '-g', desc: ''
|
228
|
+
def list(args = nil)
|
229
|
+
Aka.print_title('System Alias')
|
230
|
+
if !args.nil?
|
231
|
+
Aka.showlast(options[:number], args.to_i, options[:group]) # user input
|
248
232
|
else
|
249
|
-
value = readYML("#{
|
233
|
+
value = Aka.readYML("#{CONFIG_PATH}")['list']
|
250
234
|
if value.class == Fixnum
|
251
|
-
showlast(options
|
235
|
+
Aka.showlast(options[:number], value.to_i, options[:group])
|
252
236
|
else
|
253
|
-
puts "List value is not defined in #{
|
254
|
-
showlast(options
|
237
|
+
puts "List value is not defined in #{CONFIG_PATH}"
|
238
|
+
Aka.showlast(options[:number], 50, options[:group])
|
255
239
|
end
|
256
240
|
end
|
257
|
-
|
258
|
-
|
259
|
-
puts "A total of #{count()} aliases,#{count_export} exports and #{count_function} functions from #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}"
|
260
|
-
puts "\nUse 'aka -h' to see all the useful commands.\n\n"
|
261
|
-
reload_dot_file
|
241
|
+
Aka.print_all_helpful_statement
|
242
|
+
Aka.reload_dot_file unless options[:no]
|
262
243
|
end
|
263
244
|
|
264
245
|
#
|
265
246
|
# USAGE - ryan - remove numbering in front
|
266
247
|
#
|
267
|
-
desc
|
268
|
-
|
269
|
-
# method_options :clear, :type => :boolean, :aliases => '-c', :desc => 'clear the dot history file'
|
270
|
-
def usage(args=nil)
|
248
|
+
desc 'usage [number]', 'show commands usage based on history'
|
249
|
+
def usage(args = nil)
|
271
250
|
if args
|
272
|
-
if options
|
273
|
-
showUsage(args.to_i,
|
251
|
+
if options[:least] && args
|
252
|
+
Aka.showUsage(args.to_i, TRUE)
|
274
253
|
else
|
275
|
-
showUsage(args.to_i)
|
254
|
+
Aka.showUsage(args.to_i)
|
276
255
|
end
|
277
256
|
else
|
278
|
-
if options
|
279
|
-
value = readYML("#{
|
280
|
-
showlast(value.to_i,
|
257
|
+
if options[:least]
|
258
|
+
value = Aka.readYML("#{CONFIG_PATH}")['usage']
|
259
|
+
Aka.showlast(value.to_i, TRUE) # this is unsafe
|
281
260
|
else
|
282
|
-
value = readYML("#{
|
283
|
-
|
261
|
+
value = Aka.readYML("#{CONFIG_PATH}")['usage']
|
262
|
+
Aka.howlast(value.to_i) # this is unsafe
|
284
263
|
end
|
285
264
|
end
|
286
265
|
|
287
|
-
if options[:clear]
|
288
|
-
puts "clear the dot history file"
|
289
|
-
end
|
266
|
+
puts 'clear the dot history file' if options[:clear]
|
290
267
|
end
|
291
268
|
|
292
269
|
#
|
293
270
|
# INIT
|
294
271
|
#
|
295
|
-
desc
|
296
|
-
method_options :
|
297
|
-
method_options :
|
298
|
-
method_options :
|
299
|
-
method_options :
|
300
|
-
method_options :
|
301
|
-
method_options :
|
302
|
-
method_options :
|
303
|
-
method_options :
|
304
|
-
method_options :
|
305
|
-
method_options :
|
306
|
-
method_options :
|
307
|
-
method_options :
|
272
|
+
desc :init, 'setup aka'
|
273
|
+
method_options dotfile: :string
|
274
|
+
method_options history: :string
|
275
|
+
method_options install: :string
|
276
|
+
method_options profile: :string
|
277
|
+
method_options remote: :string
|
278
|
+
method_options config: :boolean
|
279
|
+
method_options bashrc: :boolean
|
280
|
+
method_options usage: :numeric
|
281
|
+
method_options zshrc: :boolean
|
282
|
+
method_options bash: :boolean
|
283
|
+
method_options home: :string
|
284
|
+
method_options list: :numeric
|
308
285
|
|
309
286
|
def init
|
310
|
-
if options
|
311
|
-
setup
|
287
|
+
if options[:count] && options[:count] < 1
|
288
|
+
Aka.setup
|
312
289
|
else
|
313
|
-
setZSHRC if options[:zshrc]
|
314
|
-
setBASHRC if options[:bashrc]
|
315
|
-
setBASH if options[:bash]
|
290
|
+
Aka.setZSHRC if options[:zshrc]
|
291
|
+
Aka.setBASHRC if options[:bashrc]
|
292
|
+
Aka.setBASH if options[:bash]
|
316
293
|
|
317
|
-
showConfig if options[:config]
|
318
|
-
setPath(options[:dotfile],
|
319
|
-
setPath(options[:history],
|
320
|
-
setPath(options[:home],
|
321
|
-
setPath(options[:install],
|
322
|
-
setPath(options[:profile],
|
323
|
-
setPath(options[:list],
|
324
|
-
setPath(options[:usage],
|
325
|
-
setPath(options[:remote],
|
294
|
+
Aka.showConfig if options[:config]
|
295
|
+
Aka.setPath(options[:dotfile], 'dotfile') if options[:dotfile]
|
296
|
+
Aka.setPath(options[:history], 'history') if options[:history]
|
297
|
+
Aka.setPath(options[:home], 'home') if options[:home]
|
298
|
+
Aka.setPath(options[:install], 'install') if options[:install]
|
299
|
+
Aka.setPath(options[:profile], 'profile') if options[:profile]
|
300
|
+
Aka.setPath(options[:list], 'list') if options[:list]
|
301
|
+
Aka.setPath(options[:usage], 'usage') if options[:usage]
|
302
|
+
Aka.setPath(options[:remote], 'remote') if options[:remote]
|
326
303
|
end
|
327
304
|
end
|
328
305
|
|
329
306
|
#
|
330
307
|
# CLEAN
|
331
308
|
#
|
332
|
-
desc
|
309
|
+
desc :clean, 'perform cleanup on your dot file'
|
333
310
|
def clean
|
334
|
-
cleanup
|
311
|
+
Aka.cleanup
|
335
312
|
end
|
336
313
|
|
337
314
|
#
|
338
|
-
#
|
315
|
+
# Config
|
339
316
|
#
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
# set path
|
344
|
-
def setPath(path, value)
|
345
|
-
data = readYML("#{Dir.home}/.aka/.config")
|
346
|
-
if data.has_key?(value) == true
|
347
|
-
old_path = data[value]
|
348
|
-
data[value] = path
|
349
|
-
writeYML("#{Dir.home}/.aka/.config", data)
|
350
|
-
puts "#{value} -> #{path}"
|
351
|
-
else
|
352
|
-
puts "Error: ".red + "--#{value} does not exist in #{Dir.home}/.aka/.config "
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
# reload
|
357
|
-
def reload
|
358
|
-
system "source #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}"
|
359
|
-
end
|
360
|
-
|
361
|
-
# read YML
|
362
|
-
def readYML path
|
363
|
-
if File.exists? path
|
364
|
-
return YAML.load_file(path)
|
365
|
-
else
|
366
|
-
puts "#{Dir.home}/.aka/.config does not exist. Type `aka setup` to setup the config file".red
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
# write YML
|
371
|
-
def writeYML path, theyml
|
372
|
-
File.open(path, 'w') {|f| f.write theyml.to_yaml } #Store
|
373
|
-
end
|
374
|
-
|
375
|
-
# write_with
|
376
|
-
def write_with array
|
377
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
378
|
-
|
379
|
-
File.open(str, 'w') { |file|
|
380
|
-
array.each do |line|
|
381
|
-
file.write(line)
|
382
|
-
end
|
383
|
-
}
|
384
|
-
end
|
385
|
-
|
386
|
-
# write_with_newline
|
387
|
-
def write_with_newline array
|
388
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
389
|
-
|
390
|
-
File.open(str, 'w') { |file|
|
391
|
-
array.each do |line|
|
392
|
-
file.write(line + "\n")
|
393
|
-
end
|
394
|
-
}
|
395
|
-
end
|
396
|
-
|
397
|
-
# write
|
398
|
-
def write str, path
|
399
|
-
File.open(path, 'w') { |file| file.write(str) }
|
400
|
-
end
|
401
|
-
|
402
|
-
# append
|
403
|
-
def append str, path
|
404
|
-
File.open(path, 'a') { |file| file.write(str) }
|
405
|
-
end
|
406
|
-
|
407
|
-
#append_with_newline
|
408
|
-
def append_with_newline str, path
|
409
|
-
File.open(path, 'a') { |file| file.write(str + "\n") }
|
410
|
-
end
|
411
|
-
|
412
|
-
# reload_dot_file
|
413
|
-
def reload_dot_file
|
414
|
-
if isOhMyZsh == true
|
415
|
-
system("exec zsh")
|
416
|
-
else
|
417
|
-
system("kill -SIGUSR1 #{Process.ppid}")
|
418
|
-
end
|
419
|
-
end
|
420
|
-
|
421
|
-
# history write
|
422
|
-
def historywrite
|
423
|
-
if isOhMyZsh == true
|
424
|
-
system("exec zsh")
|
425
|
-
else
|
426
|
-
system "kill -SIGUSR2 #{Process.ppid}"
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
# unalias
|
431
|
-
def unalias_the value
|
432
|
-
if isOhMyZsh == true
|
433
|
-
system("exec zsh")
|
434
|
-
else
|
435
|
-
system "echo '#{value}' > ~/sigusr1-args;"
|
436
|
-
system "kill -SIGUSR2 #{Process.ppid}"
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
#split domain user
|
441
|
-
def split_domain_user fulldomain
|
442
|
-
username = fulldomain.split("@").first
|
443
|
-
domain = fulldomain.split("@")[1]
|
444
|
-
return [username, domain]
|
445
|
-
end
|
446
|
-
|
447
|
-
# split
|
448
|
-
def split fulldomain
|
449
|
-
username = fulldomain.split("@").first
|
450
|
-
domain = fulldomain.split("@")[1].split(":").first
|
451
|
-
port = fulldomain.split("@")[1].split(":")[1]
|
452
|
-
return [username, domain, port]
|
453
|
-
end
|
454
|
-
|
455
|
-
def add_with_group input, name_of_group
|
456
|
-
if input && search_alias_return_alias_tokens(input).first == false && not_empty_alias(input) == false
|
457
|
-
array = input.split("=")
|
458
|
-
group_name = "# => #{name_of_group}"
|
459
|
-
full_command = "alias #{array.first}='#{array[1]}' #{group_name}".gsub("\n","") #remove new line in command
|
460
|
-
print_out_command = "aka g #{array.first}='#{array[1]}'"
|
461
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
462
|
-
|
463
|
-
File.open(str, 'a') { |file| file.write("\n" +full_command) }
|
464
|
-
# puts "#{print_out_command} is added to #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}"
|
465
|
-
puts "Created: ".green + "#{print_out_command} " + "in #{name_of_group} group."
|
466
|
-
|
467
|
-
return true
|
468
|
-
else
|
469
|
-
puts "The alias is already present. Use 'aka -h' to see all the useful commands."
|
470
|
-
return false
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
# add
|
475
|
-
def add input
|
476
|
-
if input && search_alias_return_alias_tokens(input).first == false && not_empty_alias(input) == false
|
477
|
-
array = input.split("=")
|
478
|
-
full_command = "alias #{array.first}='#{array[1]}'".gsub("\n","") #remove new line in command
|
479
|
-
print_out_command = "aka g #{array.first}='#{array[1]}'"
|
480
|
-
|
481
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
482
|
-
|
483
|
-
File.open(str, 'a') { |file| file.write("\n" +full_command) }
|
484
|
-
# puts "#{print_out_command} is added to #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}"
|
485
|
-
puts "Created: ".green + "#{print_out_command}"
|
486
|
-
|
487
|
-
return true
|
488
|
-
else
|
489
|
-
puts "The alias is already present. Use 'aka -h' to see all the useful commands."
|
490
|
-
return false
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
# not empty alias
|
495
|
-
def not_empty_alias input
|
496
|
-
array = input.split("=")
|
497
|
-
return true if array.count < 2
|
498
|
-
return array[1].strip == ""
|
499
|
-
end
|
500
|
-
|
501
|
-
#list
|
502
|
-
def search_alias_with_group_name name
|
503
|
-
if name == "group"
|
504
|
-
name = "default"
|
505
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
506
|
-
|
507
|
-
if content = File.open(str).read
|
508
|
-
content.gsub!(/\r\n?/, "\n")
|
509
|
-
content_array = content.split("\n")
|
510
|
-
content_array.each_with_index { |line, index|
|
511
|
-
value = line.split(" ")
|
512
|
-
containsCommand = line.split('=') #containsCommand[1]
|
513
|
-
if value.length > 1 && value.first == "alias"
|
514
|
-
answer = value[1].split("=") #contains the alias
|
515
|
-
group_name = line.scan(/# => ([a-zA-z]*)/).first if line.scan(/# => ([a-zA-z]*)/)
|
516
|
-
if group_name != nil && group_name.first == name
|
517
|
-
containsCommand[1].slice!(0) && containsCommand[1].slice!(containsCommand[1].length-1) if containsCommand[1] != nil && containsCommand[1][0] == "'" && containsCommand[1][containsCommand[1].length-1] == "'"
|
518
|
-
puts "aka g " + "#{answer.first}".red + "=#{containsCommand[1]}"
|
519
|
-
end
|
520
|
-
end
|
521
|
-
}
|
522
|
-
end
|
523
|
-
else
|
524
|
-
|
525
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
526
|
-
if content = File.open(str).read
|
527
|
-
content.gsub!(/\r\n?/, "\n")
|
528
|
-
content_array = content.split("\n")
|
529
|
-
content_array.each_with_index { |line, index|
|
530
|
-
value = line.split(" ")
|
531
|
-
containsCommand = line.split('=') #containsCommand[1]
|
532
|
-
if value.length > 1 && value.first == "alias"
|
533
|
-
answer = value[1].split("=") #contains the alias
|
534
|
-
group_name = line.scan(/# => ([a-zA-z]*)/).first if line.scan(/# => ([a-zA-z]*)/)
|
535
|
-
if group_name != nil && group_name.first == name
|
536
|
-
containsCommand[1].slice!(0) && containsCommand[1].slice!(containsCommand[1].length-1) if containsCommand[1] != nil && containsCommand[1][0] == "'" && containsCommand[1][containsCommand[1].length-1] == "'"
|
537
|
-
puts "aka g " + "#{answer.first}".red + "=#{containsCommand[1]}"
|
538
|
-
end
|
539
|
-
end
|
540
|
-
}
|
541
|
-
end
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
# show alias
|
546
|
-
def search_alias_return_alias_tokens argument
|
547
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
548
|
-
# alias something="echo something"
|
549
|
-
if content = File.open(str).read
|
550
|
-
content.gsub!(/\r\n?/, "\n")
|
551
|
-
content_array = content.split("\n")
|
552
|
-
content_array.each_with_index { |line, index|
|
553
|
-
value = line.split(" ")
|
554
|
-
# puts "value -> #{value}"
|
555
|
-
containsCommand = line.split('=') #containsCommand[1]
|
556
|
-
if value.length > 1 && value.first == "alias"
|
557
|
-
# answer = value[1].split("=")
|
558
|
-
answer = value[1].split("=") #contains the alias
|
559
|
-
|
560
|
-
# puts "answer -> #{answer}"
|
561
|
-
if found?(answer.first, argument.split("=").first, line) == true
|
562
|
-
this_alias = answer.first
|
563
|
-
answer.slice!(0) #rmove the first
|
564
|
-
# puts "before ->#{containsCommand[1]}"
|
565
|
-
containsCommand[1].slice!(0) && containsCommand[1].slice!(containsCommand[1].length-1) if containsCommand[1] != nil && containsCommand[1][0] == "'" && containsCommand[1][containsCommand[1].length-1] == "'"
|
566
|
-
# puts "before 2 ->#{containsCommand[1]}"
|
567
|
-
|
568
|
-
# puts "join ->#{containsCommand[1]}"
|
569
|
-
return [true, this_alias, containsCommand[1]]
|
570
|
-
end
|
571
|
-
end
|
572
|
-
}
|
573
|
-
else
|
574
|
-
puts "#{@pwd} cannot be found.".red
|
575
|
-
return [false, nil, nil]
|
576
|
-
end
|
577
|
-
return [false, nil, nil]
|
578
|
-
|
579
|
-
end
|
580
|
-
|
581
|
-
# remove
|
582
|
-
def remove input
|
583
|
-
|
584
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
585
|
-
|
586
|
-
if content=File.open(str).read
|
587
|
-
content.gsub!(/\r\n?/, "\n")
|
588
|
-
content_array= content.split("\n")
|
589
|
-
content_array.each_with_index { |line, index|
|
590
|
-
value = line.split(" ")
|
591
|
-
if value.length > 1 && value.first == "alias"
|
592
|
-
answer = value[1].split("=")
|
593
|
-
if answer.first == input
|
594
|
-
content_array.delete_at(index) && write_with_newline(content_array)
|
595
|
-
print_out_command = "aka g #{input}=#{line.split("=")[1]}"
|
596
|
-
# puts "removed: #{print_out_command} is removed from #{str}".red
|
597
|
-
|
598
|
-
puts "Removed: ".red + "#{print_out_command}"
|
599
|
-
|
600
|
-
return true
|
601
|
-
end
|
602
|
-
end
|
603
|
-
}
|
604
|
-
|
605
|
-
puts "#{input} cannot be found.".red
|
606
|
-
else
|
607
|
-
puts "#{@pwd} cannot be found.".red
|
608
|
-
return false
|
609
|
-
end
|
610
|
-
end
|
611
|
-
|
612
|
-
# remove autosource in dotfile
|
613
|
-
def remove_autosource
|
614
|
-
|
615
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
616
|
-
|
617
|
-
if content=File.open(str).read
|
618
|
-
content.gsub!(/\r\n?/, "\n")
|
619
|
-
content_array= content.split("\n")
|
620
|
-
content_array.each_with_index { |line, index|
|
621
|
-
if line == "source \"/home/ryan/.aka/autosource\""
|
622
|
-
content_array.delete_at(index) && write_with_newline(content_array)
|
623
|
-
# puts "---> removed: source \"/home/ryan/.aka/autosource\""
|
624
|
-
puts "Removed: ".red + "source \"/home/ryan/.aka/autosource\""
|
625
|
-
|
626
|
-
return true
|
627
|
-
end
|
628
|
-
}
|
629
|
-
|
630
|
-
else
|
631
|
-
puts "---> autosource cannot be found in dotfile.".red
|
632
|
-
return false
|
633
|
-
end
|
634
|
-
end
|
635
|
-
|
636
|
-
# history
|
637
|
-
def history
|
638
|
-
|
639
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["history"])
|
640
|
-
|
641
|
-
if content = File.open(str).read
|
642
|
-
puts ".bash_history is available"
|
643
|
-
count=0
|
644
|
-
content.gsub!(/\r\n?/, "\n")
|
645
|
-
content_array = content.split("\n")
|
646
|
-
content_array.each_with_index { |line, index|
|
647
|
-
array = line.split(" ")
|
648
|
-
if array.first == "alias"
|
649
|
-
count += 1
|
650
|
-
end
|
651
|
-
puts "#{index+1} #{line}"
|
652
|
-
}
|
653
|
-
puts "There are #{count} lines of history."
|
654
|
-
else
|
655
|
-
puts ".bash_history is not available".red
|
656
|
-
end
|
657
|
-
end
|
658
|
-
|
659
|
-
# check version
|
660
|
-
def version
|
661
|
-
puts ""
|
662
|
-
puts "aka #{program(:version)} - #{program(:last_update)}"
|
663
|
-
puts "#{program(:author)} - #{program(:contact)}"
|
664
|
-
puts "https://github.com/ytbryan/aka"
|
665
|
-
end
|
666
|
-
|
667
|
-
# check found
|
668
|
-
def found? answer, argument, line
|
669
|
-
if answer == argument
|
670
|
-
# puts line.red + " - aka add #{argument}"
|
671
|
-
# puts line.red
|
672
|
-
puts "Exist: ".green + " aka g #{argument}=#{line.split('=')[1]}"
|
673
|
-
return true
|
674
|
-
else
|
675
|
-
return false
|
676
|
-
end
|
677
|
-
end
|
678
|
-
|
679
|
-
def edit_alias_command newcommand, this_alias
|
680
|
-
puts "Edited: ".yellow + "aka g #{this_alias}='#{newcommand}'"
|
681
|
-
return append("alias " + this_alias + "='" + newcommand + "'", readYML("#{Dir.home}/.aka/.config")["dotfile"] )
|
682
|
-
end
|
683
|
-
|
684
|
-
# edit alias
|
685
|
-
def edit_alias_name newalias, thiscommand
|
686
|
-
puts "Edited: ". yellow + "aka g #{newalias}='#{thiscommand}'"
|
687
|
-
return append("alias " + newalias + "='" + thiscommand + "'", readYML("#{Dir.home}/.aka/.config")["dotfile"] )
|
688
|
-
end
|
689
|
-
|
690
|
-
# count function
|
691
|
-
def count_function
|
692
|
-
function_count = 0
|
693
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
694
|
-
if content=File.open(str).read
|
695
|
-
content.gsub!(/\r\n?/, "\n")
|
696
|
-
content_array= content.split("\n")
|
697
|
-
content_array.each_with_index { |line, index|
|
698
|
-
value = line.split(" ")
|
699
|
-
if value.length > 1 && value.first == "function"
|
700
|
-
answer = value[1].split("=")
|
701
|
-
function_count += 1
|
702
|
-
end
|
703
|
-
}
|
704
|
-
return function_count
|
705
|
-
end
|
706
|
-
end
|
707
|
-
|
708
|
-
#count export
|
709
|
-
def count_export
|
710
|
-
export_count = 0
|
711
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
712
|
-
if content=File.open(str).read
|
713
|
-
content.gsub!(/\r\n?/, "\n")
|
714
|
-
content_array= content.split("\n")
|
715
|
-
content_array.each_with_index { |line, index|
|
716
|
-
value = line.split(" ")
|
717
|
-
if value.length > 1 && value.first == "export"
|
718
|
-
answer = value[1].split("=")
|
719
|
-
export_count += 1
|
720
|
-
end
|
721
|
-
}
|
722
|
-
return export_count
|
723
|
-
end
|
724
|
-
|
725
|
-
end
|
726
|
-
|
727
|
-
# count
|
728
|
-
def count
|
729
|
-
alias_count = 0
|
730
|
-
|
731
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
732
|
-
|
733
|
-
if content=File.open(str).read
|
734
|
-
content.gsub!(/\r\n?/, "\n")
|
735
|
-
content_array= content.split("\n")
|
736
|
-
content_array.each_with_index { |line, index|
|
737
|
-
value = line.split(" ")
|
738
|
-
if value.length > 1 && value.first == "alias"
|
739
|
-
answer = value[1].split("=")
|
740
|
-
alias_count += 1
|
741
|
-
end
|
742
|
-
}
|
743
|
-
return alias_count
|
744
|
-
end
|
745
|
-
end
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
# setup_aka by ryan - set value in config file
|
750
|
-
def setup_aka
|
751
|
-
userBash = []
|
752
|
-
# 1. check for each type of file without setting anything.
|
753
|
-
if File.exist?("#{Dir.home}/.zshrc") #if zshrc exist
|
754
|
-
userBash.push(".zshrc")
|
755
|
-
end
|
756
|
-
if File.exist?("#{Dir.home}/.bashrc") #if bashrc exist
|
757
|
-
userBash.push(".bashrc")
|
758
|
-
end
|
759
|
-
if File.exist?("#{Dir.home}/.bash_profile") #if bash_profile exist
|
760
|
-
userBash.push(".bash_profile")
|
761
|
-
end
|
762
|
-
|
763
|
-
#2. count the number of types
|
764
|
-
|
765
|
-
#3 if number of types is 1, proceed to set it
|
766
|
-
if userBash.count == 1
|
767
|
-
set_to_dotfile(userBash.first)
|
768
|
-
|
769
|
-
elsif userBash.count > 1
|
770
|
-
#4 if the number of types is more than 1, proceed to ask which one does the users want to uses.
|
771
|
-
userBash.each_with_index do |choice,i|
|
772
|
-
puts "#{i+1}. Setup in #{Dir.home}/#{choice}"
|
773
|
-
end
|
774
|
-
choice = ask "Please choose which location you wish to setup? (Choose a number and enter)\n"
|
775
|
-
|
776
|
-
#5 once you receive input, then you set it according to input
|
777
|
-
case choice
|
778
|
-
when "1"
|
779
|
-
set_to_dotfile(userBash[0]) if userBash[0]
|
780
|
-
when "2"
|
781
|
-
if userBash[1] then set_to_dotfile(userBash[1]) else abort "No file choosen" end
|
782
|
-
when "3"
|
783
|
-
if userBash[2] then set_to_dotfile(userBash[2]) else abort "No file choosen" end
|
784
|
-
else
|
785
|
-
puts "Invalid input, Please enter the number between 1 and #{userBash.count}. Please try again"
|
786
|
-
abort "No file choosen"
|
787
|
-
end
|
788
|
-
end #if userBash > 1
|
789
|
-
|
790
|
-
# if File.exist?("#{Dir.home}/.zshrc") #if zshec exist
|
791
|
-
# setZSHRC2
|
792
|
-
# elsif File.exist?("#{Dir.home}/.bashrc") #if bashrc exist
|
793
|
-
# setBASHRC2
|
794
|
-
# elsif File.exist?("#{Dir.home}/.bash_profile") #if bash_profile exist
|
795
|
-
# setBASH2
|
796
|
-
# else
|
797
|
-
# puts "Aka2 only supports zshrc, bashrc and bash_profile"
|
798
|
-
# puts "Please contact http://github.com/ytbryan for more info."
|
799
|
-
# end
|
800
|
-
end
|
801
|
-
|
802
|
-
def set_to_dotfile(filename)
|
803
|
-
if filename == ".zshrc"
|
804
|
-
setZSHRC2
|
805
|
-
elsif filename == ".bashrc"
|
806
|
-
setBASHRC2
|
807
|
-
elsif filename == ".bash_profile"
|
808
|
-
setBASH2
|
809
|
-
end
|
317
|
+
desc :config, 'show config'
|
318
|
+
def config
|
319
|
+
Aka.showConfig
|
810
320
|
end
|
811
321
|
|
812
|
-
|
813
|
-
# setup_autosource by ryan - create source file
|
814
|
-
def setup_autosource
|
815
|
-
configDir = "#{Dir.home}/.aka"
|
816
|
-
|
817
|
-
if File.exist?("#{configDir}/.config")
|
818
|
-
out_file = File.new("#{configDir}/autosource", "w")
|
819
|
-
out_file.puts("export HISTSIZE=10000")
|
820
|
-
out_file.puts("sigusr2() { unalias $1;}")
|
821
|
-
out_file.puts("sigusr1() { source #{readYML("#{configDir}/.config")["dotfile"]}; history -a; echo 'reloaded dot file'; }")
|
822
|
-
out_file.puts("trap sigusr1 SIGUSR1")
|
823
|
-
out_file.puts("trap 'sigusr2 $(cat ~/sigusr1-args)' SIGUSR2")
|
824
|
-
out_file.close
|
825
|
-
autosource = "\nsource \"#{configDir}/autosource\""
|
826
|
-
append(autosource, readYML("#{configDir}/.config")['profile'])
|
827
|
-
puts "Done. Please restart this shell.".red
|
828
|
-
else
|
829
|
-
puts "Directory #{configDir}/.config doesn't exist"
|
830
|
-
end
|
831
|
-
end
|
832
|
-
|
833
|
-
# create and setup config file
|
834
|
-
def setup_config
|
835
|
-
configDir = "#{Dir.home}/.aka"
|
836
|
-
if File.exist?("#{configDir}/.config")
|
837
|
-
puts "Directory #{configDir}/.config exist"
|
838
|
-
else
|
839
|
-
FileUtils::mkdir_p("#{configDir}")
|
840
|
-
# FileUtils.cp("./lib/.config", "#{configDir}")
|
841
|
-
out_file = File.new("#{configDir}/.config", "w")
|
842
|
-
out_file.puts("---")
|
843
|
-
out_file.puts("dotfile: \"/home/user/.bashrc\"")
|
844
|
-
out_file.puts("history: \"/home/user/.bash_history\"")
|
845
|
-
out_file.puts("home: \"/home/user/.aka\"")
|
846
|
-
out_file.puts("install: \"/usr/local/bin\"")
|
847
|
-
out_file.puts("profile: \"/home/user/.bashrc\"")
|
848
|
-
out_file.puts("list: 50")
|
849
|
-
out_file.puts("usage: 50")
|
850
|
-
out_file.puts("remote: 12.12.12.21")
|
851
|
-
out_file.close
|
852
|
-
end
|
853
|
-
end
|
854
|
-
|
855
|
-
# write to location
|
856
|
-
def write_to_location location, address
|
857
|
-
if aka_directory_exists?
|
858
|
-
write(location, address)
|
859
|
-
else
|
860
|
-
puts ".aka not found.".red
|
861
|
-
end
|
862
|
-
end
|
863
|
-
|
864
|
-
# read location
|
865
|
-
def read location
|
866
|
-
answer = dot_location_exists?(location)
|
867
|
-
if answer == true && content = File.open(location).read
|
868
|
-
return content
|
869
|
-
end
|
870
|
-
return ""
|
871
|
-
end
|
872
|
-
|
873
|
-
# dot location exist
|
874
|
-
def dot_location_exists? address
|
875
|
-
return File.exist? address
|
876
|
-
end
|
877
|
-
|
878
|
-
# aka directory exist ?
|
879
|
-
def aka_directory_exists?
|
880
|
-
return File.directory?("#{Dir.home}/.aka")
|
881
|
-
end
|
882
|
-
|
883
|
-
# check config file
|
884
|
-
def checkConfigFile str
|
885
|
-
path = "#{Dir.home}/.bash_profile"
|
886
|
-
if str == ""
|
887
|
-
puts "Error: ".red + "Type `aka init --dotfile #{path}` to set the path to your dotfile. \nReplace .bash_profile with .bashrc or .zshrc if you are not using bash."
|
888
|
-
exit()
|
889
|
-
end
|
890
|
-
|
891
|
-
if !File.exists?(str)
|
892
|
-
puts "Error: ".red + "Type `aka init --dotfile #{path}` to set the path of your dotfile. \nReplace .bash_profile with .bashrc or .zshrc if you are not using bash."
|
893
|
-
exit()
|
894
|
-
end
|
895
|
-
|
896
|
-
return str
|
897
|
-
end
|
898
|
-
|
899
|
-
# show last
|
900
|
-
def showlast_old howmany=10
|
901
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
902
|
-
|
903
|
-
if content = File.open(str).read
|
904
|
-
content.gsub!(/\r\n?/, "\n")
|
905
|
-
content_array = content.split("\n")
|
906
|
-
#why not just call the last five lines? Because i can't be sure that they are aliases
|
907
|
-
total_aliases = []
|
908
|
-
content_array.each_with_index { |line, index|
|
909
|
-
value = line.split(" ")
|
910
|
-
if value.length > 1 && value.first == "alias"
|
911
|
-
total_aliases.push(line)
|
912
|
-
end
|
913
|
-
}
|
914
|
-
puts ""
|
915
|
-
if total_aliases.count > howmany
|
916
|
-
total_aliases.last(howmany).each_with_index do |line, index|
|
917
|
-
splitted= line.split('=')
|
918
|
-
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
919
|
-
# puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
920
|
-
# puts "#{total_aliases.count - howmany + index+1}. " + splitted[0] + "=" + splitted[1].red
|
921
|
-
end
|
922
|
-
else
|
923
|
-
total_aliases.last(howmany).each_with_index do |line, index|
|
924
|
-
splitted= line.split('=')
|
925
|
-
# puts "#{index+1}. " + splitted[0] + "=" + splitted[1].red
|
926
|
-
puts "#{index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
927
|
-
# puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
928
|
-
end
|
929
|
-
end
|
930
|
-
puts ""
|
931
|
-
end
|
932
|
-
end
|
933
|
-
|
934
|
-
def show_last_with_group(list_number=false, howmany=10, group)
|
935
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
936
|
-
|
937
|
-
if content = File.open(str).read
|
938
|
-
content.gsub!(/\r\n?/, "\n")
|
939
|
-
content_array = content.split("\n")
|
940
|
-
|
941
|
-
total_aliases = []
|
942
|
-
content_array.each_with_index { |line, index|
|
943
|
-
value = line.split(" ")
|
944
|
-
if value.length > 1 && value.first == "alias"
|
945
|
-
total_aliases.push(line)
|
946
|
-
end
|
947
|
-
}
|
948
|
-
puts ""
|
949
|
-
if total_aliases.count > howmany
|
950
|
-
total_aliases.last(howmany).each_with_index do |line, index|
|
951
|
-
splitted= line.split('=')
|
952
|
-
if list_number
|
953
|
-
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
954
|
-
# puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
955
|
-
else
|
956
|
-
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
957
|
-
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
958
|
-
end
|
959
|
-
# puts "#{total_aliases.count - howmany + index+1}. " + splitted[0] + "=" + splitted[1].red
|
960
|
-
end
|
961
|
-
else
|
962
|
-
total_aliases.last(howmany).each_with_index do |line, index|
|
963
|
-
splitted= line.split('=')
|
964
|
-
# puts "#{index+1}. " + splitted[0] + "=" + splitted[1].red
|
965
|
-
if list_number
|
966
|
-
puts "#{index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
967
|
-
# puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
968
|
-
else
|
969
|
-
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
970
|
-
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
971
|
-
end
|
972
|
-
end
|
973
|
-
end
|
974
|
-
puts ""
|
975
|
-
end
|
976
|
-
end
|
977
|
-
|
978
|
-
# show last2 - ryan - remove number
|
979
|
-
def showlast(list_number=false,howmany=10)
|
980
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
981
|
-
|
982
|
-
if content = File.open(str).read
|
983
|
-
content.gsub!(/\r\n?/, "\n")
|
984
|
-
content_array = content.split("\n")
|
985
|
-
#why not just call the last five lines? Because i can't be sure that they are aliases
|
986
|
-
total_aliases = []
|
987
|
-
content_array.each_with_index { |line, index|
|
988
|
-
value = line.split(" ")
|
989
|
-
if value.length > 1 && value.first == "alias"
|
990
|
-
total_aliases.push(line)
|
991
|
-
end
|
992
|
-
}
|
993
|
-
puts ""
|
994
|
-
if total_aliases.count > howmany
|
995
|
-
total_aliases.last(howmany).each_with_index do |line, index|
|
996
|
-
splitted= line.split('=')
|
997
|
-
if list_number
|
998
|
-
puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
999
|
-
# puts "#{total_aliases.count - howmany + index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
1000
|
-
else
|
1001
|
-
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
1002
|
-
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
1003
|
-
end
|
1004
|
-
# puts "#{total_aliases.count - howmany + index+1}. " + splitted[0] + "=" + splitted[1].red
|
1005
|
-
end
|
1006
|
-
else
|
1007
|
-
total_aliases.last(howmany).each_with_index do |line, index|
|
1008
|
-
splitted= line.split('=')
|
1009
|
-
# puts "#{index+1}. " + splitted[0] + "=" + splitted[1].red
|
1010
|
-
if list_number
|
1011
|
-
puts "#{index+1}. aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
1012
|
-
# puts "#{index+1}. aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
1013
|
-
else
|
1014
|
-
puts "aka g " + splitted[0].split(" ")[1].red + "=" + splitted[1]
|
1015
|
-
# puts "aka g " + splitted[0].split(" ")[1] + "=" + splitted[1].red
|
1016
|
-
end
|
1017
|
-
end
|
1018
|
-
end
|
1019
|
-
puts ""
|
1020
|
-
end
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
# show usage
|
1024
|
-
def showUsage howmany=10, least=false
|
1025
|
-
|
1026
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["history"])
|
1027
|
-
|
1028
|
-
value = reload_dot_file()
|
1029
|
-
#get all aliases
|
1030
|
-
if content = File.open(str).read
|
1031
|
-
content.gsub!(/\r\n?/, "\n")
|
1032
|
-
content_array = content.split("\n")
|
1033
|
-
total_aliases = []
|
1034
|
-
content_array.each_with_index { |line, index|
|
1035
|
-
value = line.split(" ")
|
1036
|
-
total_aliases.push(value.first)
|
1037
|
-
}
|
1038
|
-
count_aliases(total_aliases, howmany, least)
|
1039
|
-
end
|
1040
|
-
end
|
1041
|
-
|
1042
|
-
# count aliases
|
1043
|
-
def count_aliases array, howmany, least=false
|
1044
|
-
name_array,count_array = [], []
|
1045
|
-
#find the unique value
|
1046
|
-
array.each_with_index { |value, index|
|
1047
|
-
if name_array.include?(value) == false
|
1048
|
-
name_array.push(value)
|
1049
|
-
end
|
1050
|
-
}
|
1051
|
-
#count the value
|
1052
|
-
name_array.each { |unique_value|
|
1053
|
-
count = 0
|
1054
|
-
array.each { |value|
|
1055
|
-
if (unique_value == value)
|
1056
|
-
count+=1
|
1057
|
-
end
|
1058
|
-
}
|
1059
|
-
count_array.push(count)
|
1060
|
-
}
|
1061
|
-
|
1062
|
-
sorted_count_array, sorted_name_array = sort(count_array, name_array)
|
1063
|
-
|
1064
|
-
#display the least used aliases
|
1065
|
-
if least == true
|
1066
|
-
if sorted_count_array.count == sorted_name_array.count
|
1067
|
-
puts ""
|
1068
|
-
sorted_name_array.last(howmany).each_with_index { |value, index|
|
1069
|
-
percent = ((sorted_count_array[sorted_name_array.last(howmany).size + index]).round(2)/array.size.round(2))*100
|
1070
|
-
str = "#{sorted_name_array.size-sorted_name_array.last(howmany).size+index+1}. #{value}"
|
1071
|
-
puts "#{str} #{showSpace(str)} #{showBar(percent)}"
|
1072
|
-
}
|
1073
|
-
puts ""
|
1074
|
-
else
|
1075
|
-
puts "Something went wrong: count_array.count = #{sorted_count_array.count}\n
|
1076
|
-
name_array.count = #{sorted_name_array.count}. Please check your .bash_history.".pretty
|
1077
|
-
end
|
1078
|
-
else
|
1079
|
-
# #print out
|
1080
|
-
if sorted_count_array.count == sorted_name_array.count
|
1081
|
-
puts ""
|
1082
|
-
sorted_name_array.first(howmany).each_with_index { |value, index|
|
1083
|
-
percent = ((sorted_count_array[index]).round(2)/array.size.round(2))*100
|
1084
|
-
str = "#{index+1}. #{value}"
|
1085
|
-
puts "#{str} #{showSpace(str)} #{showBar(percent)}"
|
1086
|
-
}
|
1087
|
-
puts ""
|
1088
|
-
else
|
1089
|
-
puts "Something went wrong: count_array.count = #{sorted_count_array.count}\n
|
1090
|
-
name_array.count = #{sorted_name_array.count}. Please check your .bash_history.".pretty
|
1091
|
-
end
|
1092
|
-
end
|
1093
|
-
puts "There's a total of #{array.size} lines in #{readYML("#{Dir.home}/.aka/.config")["history"]}."
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
# sort
|
1097
|
-
def sort(countarray, namearray) #highest first. decscending.
|
1098
|
-
temp = 0, temp2 = ""
|
1099
|
-
countarray.each_with_index { |count, index|
|
1100
|
-
countarray[0..countarray.size-index].each_with_index { |x, thisindex| #always one less than total
|
1101
|
-
|
1102
|
-
if index < countarray.size-1 && thisindex < countarray.size-1
|
1103
|
-
if countarray[thisindex] < countarray[thisindex+1] #if this count is less than next count
|
1104
|
-
temp = countarray[thisindex]
|
1105
|
-
countarray[thisindex] = countarray[thisindex+1]
|
1106
|
-
countarray[thisindex+1] = temp
|
1107
|
-
|
1108
|
-
temp2 = namearray[thisindex]
|
1109
|
-
namearray[thisindex] = namearray[thisindex+1]
|
1110
|
-
namearray[thisindex+1] = temp2
|
1111
|
-
end
|
1112
|
-
end
|
1113
|
-
|
1114
|
-
}
|
1115
|
-
}#outer loop
|
1116
|
-
return countarray, namearray
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
# get history file
|
1120
|
-
def get_latest_history_file
|
1121
|
-
system("history -a")
|
1122
|
-
end
|
1123
|
-
|
1124
|
-
# clean up
|
1125
|
-
def cleanup
|
1126
|
-
|
1127
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["dotfile"])
|
1128
|
-
|
1129
|
-
if content = File.open(str).read
|
1130
|
-
content.gsub!(/\r\n?/, "\n")
|
1131
|
-
content_array = content.split("\n")
|
1132
|
-
check = false
|
1133
|
-
while check == false
|
1134
|
-
check = true
|
1135
|
-
content_array.each_with_index { |line, index|
|
1136
|
-
if line == "" || line == "\n"
|
1137
|
-
content_array.delete_at(index)
|
1138
|
-
check = false
|
1139
|
-
end
|
1140
|
-
}
|
1141
|
-
end
|
1142
|
-
write_with_newline(content_array)
|
1143
|
-
end
|
1144
|
-
end
|
1145
|
-
|
1146
|
-
################################################
|
1147
|
-
## Getting these babies ready for beauty contest
|
1148
|
-
################################################
|
1149
|
-
|
1150
|
-
def showSpace word
|
1151
|
-
space = ""
|
1152
|
-
val = 20 - word.size
|
1153
|
-
val = 20 if val < 0
|
1154
|
-
val.times do
|
1155
|
-
space += " "
|
1156
|
-
end
|
1157
|
-
return space
|
1158
|
-
end
|
1159
|
-
|
1160
|
-
def showBar percent
|
1161
|
-
result = ""
|
1162
|
-
val = percent/100 * 50
|
1163
|
-
val = 2 if val > 1 && val < 2
|
1164
|
-
val = 1 if val.round <= 1 #for visibiity, show two bars if it's just one
|
1165
|
-
val.round.times do
|
1166
|
-
result += "+"
|
1167
|
-
end
|
1168
|
-
|
1169
|
-
remaining = 50 - val.round
|
1170
|
-
remaining.times do
|
1171
|
-
result += "-".red
|
1172
|
-
end
|
1173
|
-
|
1174
|
-
return result + " #{percent.round(2)}%"
|
1175
|
-
end
|
1176
|
-
|
1177
|
-
def add_to_proj fullalias
|
1178
|
-
values = fullalias.split("=")
|
1179
|
-
yml = readYML("#{Dir.pwd}/.aka")
|
1180
|
-
if yml == false
|
1181
|
-
write_new_proj_aka_file fullalias
|
1182
|
-
else
|
1183
|
-
yml["proj"]["title"] = "this is title"
|
1184
|
-
yml["proj"]["summary"] = "this is summary"
|
1185
|
-
yml["proj"]["aka"][values.first] = values[1]
|
1186
|
-
writeYML("#{Dir.pwd}/.aka", yml)
|
1187
|
-
end
|
1188
|
-
end
|
1189
|
-
|
1190
|
-
def write_new_proj_aka_file fullalias
|
1191
|
-
values = fullalias.split("=")
|
1192
|
-
|
1193
|
-
theyml = {"proj" => {
|
1194
|
-
"title" => "",
|
1195
|
-
"summary" => "",
|
1196
|
-
"aliases" => {
|
1197
|
-
"firstvalue" => ""
|
1198
|
-
}}}
|
1199
|
-
|
1200
|
-
writeYML("#{Dir.pwd}/.aka", theyml)
|
1201
|
-
end
|
1202
|
-
|
1203
|
-
def createShortcut(proj)
|
1204
|
-
answer = ""
|
1205
|
-
proj["shortcuts"].to_a.each_with_index do |each,index|
|
1206
|
-
answer += "#{each["name"]}
|
1207
|
-
- #{each["command"]}
|
1208
|
-
".pretty
|
1209
|
-
answer += "\n"
|
1210
|
-
end
|
1211
|
-
return answer
|
1212
|
-
end
|
1213
|
-
|
1214
|
-
def add_last_command name
|
1215
|
-
command= find_last_command()
|
1216
|
-
return str = name + "=" + "#{command}"
|
1217
|
-
end
|
1218
|
-
|
1219
|
-
def find_last_command
|
1220
|
-
str = checkConfigFile(readYML("#{Dir.home}/.aka/.config")["history"])
|
1221
|
-
#i think if you do history -w, you can retrieve the latest command
|
1222
|
-
if content = File.open(str).read
|
1223
|
-
count=0
|
1224
|
-
content.gsub!(/\r\n?/, "\n")
|
1225
|
-
content_array = content.split("\n")
|
1226
|
-
return content_array[content_array.count - 1]
|
1227
|
-
end
|
1228
|
-
end
|
1229
|
-
|
1230
|
-
def parseARGS str
|
1231
|
-
array = str.split(" ")
|
1232
|
-
array.each_with_index do |line, value|
|
1233
|
-
array[value] = line.gsub('#{pwd}', Shellwords.escape(Dir.pwd))
|
1234
|
-
end
|
1235
|
-
return array.join(" ")
|
1236
|
-
end
|
1237
|
-
|
1238
|
-
def add_pwd_to_the_command
|
1239
|
-
#detect #{pwd}
|
1240
|
-
#get the pwd and replace the the pwd
|
1241
|
-
end
|
1242
|
-
|
1243
|
-
def showConfig
|
1244
|
-
thing = YAML.load_file("#{Dir.home}/.aka/.config")
|
1245
|
-
puts ""
|
1246
|
-
thing.each do |company,details|
|
1247
|
-
puts "#{company} -> " + "#{details}".red
|
1248
|
-
end
|
1249
|
-
end
|
1250
|
-
|
1251
|
-
def setZSHRC
|
1252
|
-
setPath("#{Dir.home}/.zshrc","dotfile")
|
1253
|
-
setPath("#{Dir.home}/.zsh_history","history")
|
1254
|
-
setPath("/etc/zprofile","profile")
|
1255
|
-
end
|
1256
|
-
|
1257
|
-
def setBASHRC
|
1258
|
-
setPath("#{Dir.home}/.bashrc","dotfile")
|
1259
|
-
setPath("#{Dir.home}/.bash_history","history")
|
1260
|
-
setPath("/etc/profile","profile")
|
1261
|
-
end
|
1262
|
-
|
1263
|
-
def setBASH
|
1264
|
-
setPath("#{Dir.home}/.bash_profile","dotfile")
|
1265
|
-
setPath("#{Dir.home}/.bash_history","history")
|
1266
|
-
setPath("/etc/profile","profile")
|
1267
|
-
end
|
1268
|
-
|
1269
|
-
def setZSHRC2 #ryan - set the right dotfile and profile
|
1270
|
-
setPath("#{Dir.home}/.zshrc","dotfile")
|
1271
|
-
setPath("#{Dir.home}/.zsh_history","history")
|
1272
|
-
setPath("#{Dir.home}/.zshrc","profile")
|
1273
|
-
setPath("#{Dir.home}/.aka","home")
|
1274
|
-
end
|
1275
|
-
|
1276
|
-
def setBASHRC2 #ryan - set the right dotfile and profile
|
1277
|
-
setPath("#{Dir.home}/.bashrc","dotfile")
|
1278
|
-
setPath("#{Dir.home}/.bash_history","history")
|
1279
|
-
setPath("#{Dir.home}/.bashrc","profile")
|
1280
|
-
setPath("#{Dir.home}/.aka","home")
|
1281
|
-
end
|
1282
|
-
|
1283
|
-
def setBASH2 #ryan - set the right dotfile and profile
|
1284
|
-
setPath("#{Dir.home}/.bash_profile","dotfile")
|
1285
|
-
setPath("#{Dir.home}/.bash_history","history")
|
1286
|
-
setPath("/etc/profile","profile")
|
1287
|
-
setPath("#{Dir.home}/.aka","home")
|
1288
|
-
end
|
1289
|
-
|
1290
|
-
def get_password
|
1291
|
-
ask("Enter Password: ", :echo => false)
|
1292
|
-
end
|
1293
|
-
|
1294
|
-
def isOhMyZsh
|
1295
|
-
if readYML("#{Dir.home}/.aka/.config")["dotfile"] == "#{Dir.home}/.zshrc"
|
1296
|
-
return true
|
1297
|
-
else
|
1298
|
-
return false
|
1299
|
-
end
|
1300
|
-
end
|
1301
|
-
|
1302
|
-
end
|
1303
|
-
|
1304
|
-
|
1305
|
-
end
|
1306
|
-
|
1307
|
-
class String
|
1308
|
-
def pretty
|
1309
|
-
return self.gsub("\s\t\r\f", ' ').squeeze(' ')
|
1310
|
-
end
|
1311
|
-
|
1312
|
-
def is_i?
|
1313
|
-
!!(self =~ /\A[-+]?[0-9]+\z/)
|
1314
|
-
end
|
1315
|
-
end
|
1316
|
-
|
1317
|
-
__END__
|
1318
|
-
|
1319
|
-
#
|
1320
|
-
# LIST OUT
|
1321
|
-
#
|
1322
|
-
# desc "list_old", "list alias (short alias: l)"
|
1323
|
-
# method_options :force => :boolean
|
1324
|
-
# def list_old(args=nil)
|
1325
|
-
# if args != nil
|
1326
|
-
# showlast_old(args.to_i)
|
1327
|
-
# else
|
1328
|
-
# value = readYML("#{Dir.home}/.aka/.config")["list"]
|
1329
|
-
# showlast_old(value.to_i) #this is unsafe
|
1330
|
-
# end
|
1331
|
-
#
|
1332
|
-
# #total of #{} exports #functions
|
1333
|
-
# puts "A total of #{count()} aliases,#{count_export} exports and #{count_function} functions from #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}"
|
1334
|
-
# reload_dot_file
|
1335
|
-
# end
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
# command :config do |c|
|
1340
|
-
# c.action do |args, options|
|
1341
|
-
# # theyml = Hash.new
|
1342
|
-
# # theyml["location"] = "~/.aka/.location"
|
1343
|
-
# # theyml["global"] = "/Users/ytbryan/.bash_profile"
|
1344
|
-
# # theyml["groups"] = "~/.aka/groups"
|
1345
|
-
# # theyml["remote"] = "255, admin, 12.12.12.233"
|
1346
|
-
# # theyml["path"] = "~/.aka"
|
1347
|
-
# # writeYML("#{Dir.home}/.aka/.config", theyml)
|
1348
|
-
# FileUtils.touch(readYML("#{Dir.home}/.aka/.config")["location"])
|
1349
|
-
# end
|
1350
|
-
# end
|
1351
322
|
#
|
1352
|
-
#
|
1353
|
-
# c.action do |args, options|
|
1354
|
-
# puts "readYML('#{Dir.home}/.aka/.config')['location'] ->#{readYML("#{Dir.home}/.aka/.config")["location"].class} -> #{readYML("#{Dir.home}/.aka/.config")["location"]}"
|
1355
|
-
# puts "readYML("#{Dir.home}/.aka/.config")["location"] -> #{ readYML("#{Dir.home}/.aka/.config")["location"].class} -> #{ readYML("#{Dir.home}/.aka/.config")["location"]}"
|
1356
|
-
# puts "#{program(:path_to_location).class} -> #{program(:path_to_location)}"
|
1357
|
-
# end
|
1358
|
-
# end
|
323
|
+
# Groups
|
1359
324
|
#
|
325
|
+
desc :groups, 'list all the groups'
|
326
|
+
def groups
|
327
|
+
Aka.list_all_groups
|
328
|
+
end
|
1360
329
|
|
1361
|
-
###########################
|
1362
|
-
### DEVELOPMENT
|
1363
|
-
###########################
|
1364
|
-
|
1365
|
-
# command :build do |c|
|
1366
|
-
# c.syntax = 'aka build [options]'
|
1367
|
-
# c.summary = 'build the VERSION file and run tests'
|
1368
|
-
# c.action do |args, options|
|
1369
|
-
# write(program(:version), './VERSION')
|
1370
|
-
# puts "VERSION #{program(:version)} created at #{Time.now.strftime("%I:%M%p, %A, %d %b %Y")}"
|
1371
|
-
# end
|
1372
|
-
# end
|
1373
|
-
|
1374
|
-
# command :install do |c|
|
1375
|
-
# c.syntax = 'aka copy [options]'
|
1376
|
-
# c.summary = 'copy a local copy of aka to /usr/local/bin'
|
1377
|
-
# c.action do |args, options|
|
1378
|
-
# result = system("sudo cp aka /usr/local/bin")
|
1379
|
-
# puts "Installed aka #{program(:version)} into /usr/local/bin (#{Time.now.strftime("%I:%M%p,%a,%d %b %Y")}).".red if result == true
|
1380
|
-
# puts "" if result == true
|
1381
|
-
# end
|
1382
|
-
# end
|
1383
|
-
#
|
1384
|
-
# command :uninstall do |c|
|
1385
|
-
# c.syntax = 'aka uninstall [options]'
|
1386
|
-
# c.summary = 'uninstall aka'
|
1387
|
-
# c.action do |args, options|
|
1388
|
-
# input = ask "Confirm that you want to uninstall aka? (y/N)"
|
1389
|
-
# system("sudo rm -rf ~/.aka; sudo rm -rf /usr/local/bin/aka;") if input == "y"
|
1390
|
-
# end
|
1391
|
-
# end
|
1392
|
-
|
1393
|
-
#
|
1394
|
-
# SETUP_old
|
1395
|
-
#
|
1396
|
-
# desc "setup_old", "setup aka"
|
1397
|
-
# method_options :force => :boolean
|
1398
|
-
# def setup_old
|
1399
|
-
# setup_aka_old
|
1400
|
-
# end
|
1401
|
-
|
1402
|
-
#
|
1403
|
-
# USAGE
|
1404
330
|
#
|
1405
|
-
#
|
1406
|
-
# # method_options :least, :type => :boolean, :aliases => '-l', :desc => 'show the least used commands'
|
1407
|
-
# # method_options :clear, :type => :boolean, :aliases => '-c', :desc => 'clear the dot history file'
|
1408
|
-
# def usage_old(args=nil)
|
1409
|
-
# if args
|
1410
|
-
# if options.least
|
1411
|
-
# showUsage(args.to_i, true) if args
|
1412
|
-
# else
|
1413
|
-
# showUsage(args.to_i) if args
|
1414
|
-
# end
|
1415
|
-
# else
|
1416
|
-
# if options.least
|
1417
|
-
# value = readYML("#{Dir.home}/.aka/.config")["usage"]
|
1418
|
-
# showlast_old(value.to_i, true) #this is unsafe
|
1419
|
-
# else
|
1420
|
-
# value = readYML("#{Dir.home}/.aka/.config")["usage"]
|
1421
|
-
# showlast_old(value.to_i) #this is unsafe
|
1422
|
-
# end
|
1423
|
-
# end
|
331
|
+
# Where is your dotfile
|
1424
332
|
#
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
333
|
+
desc :where, 'locate your dotfile'
|
334
|
+
def where
|
335
|
+
puts Aka.readYML("#{CONFIG_PATH}")['dotfile']
|
336
|
+
end
|
1430
337
|
|
1431
338
|
#
|
1432
|
-
#
|
339
|
+
# show version
|
1433
340
|
#
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
# if File.exist? "/usr/local/bin/aka"
|
1439
|
-
# if yes? "aka exists. Do you want to replace it? (yN)"
|
1440
|
-
# FileUtils.rm("/usr/local/bin/aka")
|
1441
|
-
# system("ln -s #{Dir.pwd}/aka /usr/local/bin/aka")
|
1442
|
-
# puts "aka replaced."
|
1443
|
-
# end
|
1444
|
-
# else
|
1445
|
-
# result = system("ln -s #{Dir.pwd}/aka /usr/local/bin/aka")
|
1446
|
-
# puts "aka installed."
|
1447
|
-
# end
|
1448
|
-
# else
|
1449
|
-
# puts "Cannot find aka.".red
|
1450
|
-
# end
|
1451
|
-
# end
|
341
|
+
desc :version, 'show version'
|
342
|
+
def version
|
343
|
+
puts Aka::VERSION
|
344
|
+
end
|
1452
345
|
|
1453
346
|
|
1454
|
-
|
1455
|
-
#
|
1456
|
-
# append_with_newline("export HISTSIZE=10000","/etc/profile")
|
1457
|
-
# trap = "sigusr2() { unalias $1;}
|
1458
|
-
# sigusr1() { source #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}; history -a; echo 'reloaded dot file'; }
|
1459
|
-
# trap sigusr1 SIGUSR1
|
1460
|
-
# trap 'sigusr2 $(cat ~/sigusr1-args)' SIGUSR2\n".pretty
|
1461
|
-
# append(trap, readYML("#{Dir.home}/.aka/.config")['profile'])
|
1462
|
-
# puts "Done. Please restart this shell.".red
|
1463
|
-
# end
|
1464
|
-
#
|
1465
|
-
# # setup_aka_old2 by ryan - check bash file first
|
1466
|
-
# def setup_aka_old2
|
1467
|
-
# if File.exist?("#{Dir.home}/.zshrc") #if zshec exist
|
1468
|
-
# setZSHRC2
|
1469
|
-
# append_with_newline("\nexport HISTSIZE=10000","#{Dir.home}/.zshrc")
|
1470
|
-
# elsif
|
1471
|
-
# File.exist?("#{Dir.home}/.bashrc") #if bashrc exist
|
1472
|
-
# setBASHRC2
|
1473
|
-
# append_with_newline("\nexport HISTSIZE=10000","#{Dir.home}/.bashrc")
|
1474
|
-
# elsif File.exist?("#{Dir.home}/.bash_profile") #if bash_profile exist
|
1475
|
-
# setBASH2
|
1476
|
-
# append_with_newline("\nexport HISTSIZE=10000","#{Dir.home}/.bash_profile")
|
1477
|
-
# else
|
1478
|
-
# puts "Currently aka2 just support zshrc, bashrc and bash_profile"
|
1479
|
-
# puts "Pleaes contact aka2 creator for more info."
|
1480
|
-
# end
|
1481
|
-
#
|
1482
|
-
# trap = "sigusr2() { unalias $1;}
|
1483
|
-
# sigusr1() { source #{readYML("#{Dir.home}/.aka/.config")["dotfile"]}; history -a; echo 'reloaded dot file'; }
|
1484
|
-
# trap sigusr1 SIGUSR1
|
1485
|
-
# trap 'sigusr2 $(cat ~/sigusr1-args)' SIGUSR2\n".pretty
|
1486
|
-
# append(trap, readYML("#{Dir.home}/.aka/.config")['profile'])
|
1487
|
-
# puts "Done. Please restart this shell.".red
|
1488
|
-
# end
|
347
|
+
end # that's all
|
348
|
+
end # last end
|