chid 0.1.6 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +27 -0
  5. data/CONTRIBUTING.md +78 -0
  6. data/Gemfile.lock +34 -34
  7. data/README.md +135 -89
  8. data/bin/chid +2 -25
  9. data/chid.gemspec +0 -6
  10. data/lib/chid.rb +0 -66
  11. data/lib/chid/chid_config.rb +6 -83
  12. data/lib/chid/command.rb +1 -1
  13. data/lib/chid/commands/alias/create.rb +53 -0
  14. data/lib/chid/commands/config.rb +48 -0
  15. data/lib/chid/commands/currency/convert.rb +50 -0
  16. data/lib/chid/commands/currency/list.rb +34 -0
  17. data/lib/chid/commands/currency/now.rb +47 -0
  18. data/lib/chid/commands/gitflow/commit.rb +0 -1
  19. data/lib/chid/commands/github.rb +40 -0
  20. data/lib/chid/commands/init.rb +1 -2
  21. data/lib/chid/commands/install.rb +1 -0
  22. data/lib/chid/commands/installs/dotfile.rb +27 -11
  23. data/lib/chid/commands/installs/node.rb +5 -3
  24. data/lib/chid/commands/installs/postgres.rb +6 -3
  25. data/lib/chid/commands/installs/rvm.rb +9 -4
  26. data/lib/chid/commands/installs/vim.rb +69 -0
  27. data/lib/chid/commands/pr.rb +63 -0
  28. data/lib/chid/commands/tmux/open.rb +3 -2
  29. data/lib/chid/commands/workstation/create.rb +101 -0
  30. data/lib/chid/commands/workstation/destroy.rb +61 -0
  31. data/lib/chid/commands/workstation/open.rb +4 -4
  32. data/lib/chid/github_api.rb +9 -0
  33. data/lib/chid/version.rb +1 -1
  34. data/spec/lib/chid/commands/alias/create_spec.rb +55 -0
  35. data/spec/lib/chid/commands/init_spec.rb +4 -2
  36. data/spec/lib/chid/commands/pr_spec.rb +68 -0
  37. data/spec/lib/chid/commands/workstation/create_spec.rb +153 -0
  38. data/spec/support/.bashrc +7 -0
  39. data/spec/support/.chid.config +7 -0
  40. data/tasks/install/yadr_dotfiles.rake +1 -0
  41. data/tasks/run/postgres.rake +1 -0
  42. data/tasks/update/os.rake +1 -0
  43. metadata +21 -58
  44. data/#README.md# +0 -221
  45. data/Rakefile +0 -18
  46. data/lib/chid/yandex_translate_api.rb +0 -39
  47. data/tasks/chid/config.rake +0 -5
  48. data/tasks/chid/init.rake +0 -19
  49. data/tasks/chid/install.rake +0 -14
  50. data/tasks/chid/start.rake +0 -26
  51. data/tasks/chid/update.rake +0 -14
  52. data/tasks/currency/convert.rake +0 -9
  53. data/tasks/currency/current.rake +0 -11
  54. data/tasks/currency/list.rake +0 -10
  55. data/tasks/github.rake +0 -12
  56. data/tasks/help.rake +0 -178
  57. data/tasks/install/node.rake +0 -18
  58. data/tasks/install/postgres.rake +0 -18
  59. data/tasks/install/rvm.rake +0 -21
  60. data/tasks/news.rake +0 -11
  61. data/tasks/stack_overflow.rake +0 -20
  62. data/tasks/tmux/config_windows.rake +0 -8
  63. data/tasks/tmux/new_session.rake +0 -9
  64. data/tasks/translate/yandex_list.rake +0 -7
  65. data/tasks/translate/yandex_translate.rake +0 -8
  66. data/tasks/workstation/create.rake +0 -23
  67. data/tasks/workstation/destroy.rake +0 -14
  68. data/tasks/workstation/list.rake +0 -10
  69. data/tasks/workstation/open.rake +0 -29
@@ -0,0 +1,47 @@
1
+ module Chid
2
+ module Commands
3
+ module Currency
4
+ class Current < Command
5
+
6
+ command :'currency now'
7
+
8
+ self.summary = 'Get the now converstion. Default -from USD -to BRL'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid currency now
14
+ or
15
+ $ chid currency now -to BRL -from USB
16
+
17
+ Get the now converstion. Default -from USD -to BRL
18
+
19
+ But you can given the options for any other Sources
20
+
21
+ To see all list of Source avaialble, please run `chid currency list`
22
+
23
+ Options:
24
+
25
+ -to SOURCE_TO_FINAL_VALUE
26
+ -from SOURCE_TO_BE_REFERANCE
27
+
28
+ DESC
29
+ self.arguments = ['-to', '-from']
30
+
31
+ def run
32
+ currency = CurrencyApi.convert(to: to, from: from)
33
+ puts "1 #{from} is #{currency} #{to}"
34
+ end
35
+
36
+ def to
37
+ options['-to']&.compact&.join || 'BRL'
38
+ end
39
+
40
+ def from
41
+ options['-from']&.compact&.join || 'USD'
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -57,7 +57,6 @@ Options:
57
57
  options_titles = {
58
58
  '-A' => 'Add',
59
59
  '-R' => 'Remove',
60
- '-U' => 'Update',
61
60
  '-Ref' => 'Refactor',
62
61
  '-F' => 'Fix'
63
62
  }
@@ -0,0 +1,40 @@
1
+ module Chid
2
+ module Commands
3
+ class Github < Command
4
+
5
+ command :'github'
6
+
7
+ self.summary = 'List all repositories from GitHub for a given SEARCH'
8
+ self.description = <<-DESC
9
+
10
+ Usage:
11
+
12
+ $ chid github -name rachidcalazans/chid
13
+ or
14
+ $ chid github -n rachidcalazans/chid
15
+
16
+ List all repositories from GitHub for a given SEARCH
17
+
18
+ Options:
19
+
20
+ -n NAME_TO_SEARCH
21
+ -name NAME_TO_SEARCH
22
+
23
+ DESC
24
+ self.arguments = ['-name', '-n']
25
+
26
+ def run
27
+ search_expression = name
28
+ repositories = GitHubApi.repositories(search_expression)
29
+
30
+ Paginator.new(repositories).paginate do |repository|
31
+ repository.summary
32
+ end
33
+ end
34
+
35
+ def name
36
+ self.class.arguments.map { |a| options[a] }.compact.join(' ')
37
+ end
38
+ end
39
+ end
40
+ end
@@ -24,7 +24,7 @@ Usage:
24
24
 
25
25
  private
26
26
  def chid_config_path
27
- @chid_config_path ||= ::Chid::chid_config_path
27
+ @chid_config_path ||= ::ChidConfig.new.chid_config_path
28
28
  end
29
29
 
30
30
  def create_or_update_chid_config_file
@@ -67,7 +67,6 @@ Usage:
67
67
  def chid_config_file_exist?
68
68
  File.exist?(chid_config_path)
69
69
  end
70
-
71
70
  end
72
71
  end
73
72
  end
@@ -1,3 +1,4 @@
1
+ # @deprecated
1
2
  module Chid
2
3
  module Commands
3
4
  class Install
@@ -12,7 +12,7 @@ Usage:
12
12
 
13
13
  $ chid install dotfile
14
14
 
15
- For Linux users will install through curl and will isntall zsh and git-core
15
+ For Linux users will install through curl
16
16
 
17
17
  For OSx users will install through curl
18
18
 
@@ -21,23 +21,39 @@ Usage:
21
21
 
22
22
  def run
23
23
  puts "\nInstalling the YADR Dotfiles..."
24
- ::Chid::on_linux do
24
+
25
+ puts "\nCreating undodir folder"
26
+ system('mkdir ~/.vim/undodir')
27
+
28
+ ::ChidConfig.on_linux do
29
+ puts "\nInstalling all dependencies"
25
30
  system('sudo apt-get update')
26
31
  system('sudo apt-get install curl')
32
+ system('sudo apt-get install tmux')
33
+ system('sudo apt-get install xclip')
34
+ system('sudo apt install npm')
35
+ system('sudo apt-get install ripgrep')
36
+ system('sudo apt-get install fzf')
27
37
  system('sudo apt-get install zsh')
28
- system('sudo apt-get install git-core')
38
+ system('sudo apt install git-all')
29
39
  end
30
40
 
31
- system('sh -c "`curl -fsSL https://raw.githubusercontent.com/skwp/dotfiles/master/install.sh`"')
41
+ puts "\nDownloading tmux config"
42
+ system('curl -o ~/.tmux.conf https://gist.githubusercontent.com/rachidcalazans/b9ede3f6e49450b41a5bbaff9ccc8cad/raw/f0c1fe18b22772ad04bf322aeb49df993e73877c/.tmux.conf')
43
+
44
+ puts "\nDownloading .vimrc"
45
+ system('curl -o ~/.vimrc https://gist.githubusercontent.com/rachidcalazans/e7b7ee668b9a8b247b3a9c20e5669366/raw/84af22bb3c5fb24b01aa8a01e8b783f85a6928b5/.vimrc')
46
+
47
+ puts "\nDownloading coc-settings.json"
48
+ system('curl -o ~/.vim/coc-settings.json https://gist.githubusercontent.com/rachidcalazans/a29bdedde40b328a14279bda419ccd4f/raw/59492c4096d77aef4690b1516d9c9f597fafd205/coc-settings.json')
49
+
50
+ puts "\nInstalling Oh My ZSH"
51
+ system('sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"')
32
52
 
33
- puts 'Updating YARD...'
34
- home_path = File.expand_path("~/")
35
- path = "#{home_path}/.yadr"
36
- Dir.chdir path
37
- system('git pull --rebase')
38
- system('rake update')
53
+ puts "\nInstalling all Vim Plugins"
54
+ system("vim +'PlugInstall --sync' +qa")
39
55
 
40
- puts "\nYARD Dotfiles installed successfully"
56
+ puts "\nDotfiles installed successfully"
41
57
  end
42
58
 
43
59
  end
@@ -22,11 +22,13 @@ Usage:
22
22
  def run
23
23
  puts "\nInstalling the Node..."
24
24
 
25
- ::Chid::on_linux do
26
- system('sudo apt-get install nodejs')
25
+ ::ChidConfig.on_linux do
26
+ system('sudo apt update')
27
+ system('sudo apt install nodejs')
27
28
  end
28
29
 
29
- ::Chid::on_osx do
30
+ ::ChidConfig.on_osx do
31
+ system('brew update')
30
32
  system('brew install node')
31
33
  end
32
34
 
@@ -24,11 +24,14 @@ Usage:
24
24
  def run
25
25
  puts "\nInstalling the Postgres..."
26
26
 
27
- ::Chid::on_linux do
28
- system('sudo apt-get install postgresql postgresql-contrib')
27
+ ::ChidConfig.on_linux do
28
+ system('sudo apt update')
29
+ system('sudo apt install postgresql postgresql-contrib')
30
+ system('sudo apt-get install libpq-dev')
29
31
  end
30
32
 
31
- ::Chid::on_osx do
33
+ ::ChidConfig.on_osx do
34
+ system('brew update')
32
35
  system('brew install postgres')
33
36
  end
34
37
 
@@ -22,19 +22,24 @@ Usage:
22
22
 
23
23
  def run
24
24
  puts "\nInstalling the RVM..."
25
+ system('gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB')
25
26
 
26
- ::Chid::on_linux do
27
+ ::ChidConfig.on_linux do
28
+ system('sudo apt-get install software-properties-common')
29
+ system('sudo apt-get install curl')
27
30
  system('sudo apt-add-repository -y ppa:rael-gc/rvm')
28
31
  system('sudo apt-get update')
29
- system('sudo apt-get install curl')
30
32
  system('sudo apt-get install rvm')
33
+
34
+ system("echo 'source \"/etc/profile.d/rvm.sh\"' >> ~/.bashrc")
31
35
  end
32
36
 
33
- ::Chid::on_osx do
34
- system('\curl -sSL https://get.rvm.io | bash')
37
+ ::ChidConfig.on_osx do
38
+ system('\curl -sSL https://get.rvm.io | bash -s stable --ruby')
35
39
  end
36
40
 
37
41
  puts "\nRVM installed successfully"
42
+ puts "\nPlease rebot your terminal"
38
43
  end
39
44
 
40
45
  end
@@ -0,0 +1,69 @@
1
+ module Chid
2
+ module Commands
3
+ module Installs
4
+ class Vim < Command
5
+
6
+ command :'install vim'
7
+
8
+ self.summary = 'Install vim and gvim'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+ $ chid install vim or chid install gvim
13
+
14
+ For Linux users will install through apt-get
15
+
16
+ For OSx users will install through brew
17
+
18
+ DESC
19
+ self.arguments = []
20
+
21
+ def run
22
+ puts "\nInstalling vim..."
23
+
24
+ is_vim = do_vim?
25
+ is_gvim = do_gvim?
26
+
27
+ ::ChidConfig.on_linux do
28
+ system('sudo apt update')
29
+
30
+ if is_vim
31
+ system('sudo add-apt-repository ppa:jonathonf/vim')
32
+ system('sudo apt update')
33
+ system('sudo apt install vim')
34
+ end
35
+
36
+ system('sudo apt-get install vim-gnome') if is_gvim
37
+ end
38
+
39
+ ::ChidConfig.on_osx do
40
+ system('brew update')
41
+ system('brew install vim')
42
+ end
43
+
44
+ puts "\nVim installed successfully" if is_vim
45
+ puts "\nGvim installed successfully" if is_gvim
46
+
47
+ puts "\nNothing installed =(" unless is_vim || is_gvim
48
+ end
49
+
50
+ def prompt
51
+ @prompt ||= TTY::Prompt.new
52
+ end
53
+
54
+ def do_vim?
55
+ answers = ['Yes','No']
56
+ should_install_vim = prompt.select('Install vim ?', answers)
57
+ should_install_vim == 'Yes'
58
+ end
59
+
60
+ def do_gvim?
61
+ answers = ['Yes','No']
62
+ should_install_gvim = prompt.select('Install gvim too?', answers)
63
+ should_install_gvim == 'Yes'
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,63 @@
1
+ module Chid
2
+ module Commands
3
+ class Pr < Command
4
+
5
+ command :'pr'
6
+
7
+ self.summary = "Will return a list of Open PR's filters by given user"
8
+ self.description = <<-DESC
9
+
10
+ Usage:
11
+
12
+ $ chid pr
13
+
14
+ or
15
+
16
+ $ chid pr -user rachidcalazans
17
+
18
+
19
+ Options:
20
+
21
+ -user
22
+
23
+ DESC
24
+ self.arguments = ['-user']
25
+
26
+ def run
27
+ json_prs = GitHubApi.prs(by: user)
28
+ msg = build_msg(json_prs)
29
+
30
+ send_msg(msg)
31
+
32
+ msg
33
+ end
34
+
35
+ private
36
+
37
+ def user
38
+ options['-user']&.first
39
+ end
40
+
41
+ def build_msg(json_prs)
42
+ json_prs
43
+ .filter { |pr| pr['user']['login'] == user }
44
+ .each_with_object([]) do |pr, memo|
45
+ pr.transform_keys!(&:to_sym)
46
+ pr[:user].transform_keys!(&:to_sym)
47
+
48
+ memo << <<~STR
49
+ ##{pr[:number]} - #{pr[:title]}
50
+ By #{pr[:user][:login]}
51
+ Status: #{pr[:state]}
52
+ Labels: #{pr[:labels].map { |label| label['name'] }.join(', ') }
53
+ STR
54
+ end.join("\n---\n\n")
55
+ end
56
+
57
+
58
+ def send_msg(msg)
59
+ puts msg
60
+ end
61
+ end
62
+ end
63
+ end
@@ -56,7 +56,7 @@ Options:
56
56
  end
57
57
 
58
58
  def chid_config
59
- ::Chid.chid_config
59
+ ::ChidConfig.new
60
60
  end
61
61
 
62
62
  def templates
@@ -65,8 +65,9 @@ Options:
65
65
 
66
66
  def select_template
67
67
  prompt = TTY::Prompt.new
68
- choices = templates.keys
68
+ choices = templates.keys.map(&:to_s)
69
69
  selected_template = prompt.select('Choose a template to open', choices)
70
+
70
71
  selected_template
71
72
  end
72
73
 
@@ -0,0 +1,101 @@
1
+ module Chid
2
+ module Commands
3
+ module Workstation
4
+ class Create < Command
5
+
6
+ command :'workstation create'
7
+
8
+ self.summary = 'Create a new workstation'
9
+ self.description = <<-DESC
10
+
11
+ Usage:
12
+
13
+ $ chid workstation create
14
+
15
+ Create a new workstation with the selected apps.
16
+
17
+ # @todo - Add description to use with new arguments
18
+
19
+ To see all workstations you can run
20
+
21
+ $ chid workstation list
22
+
23
+ DESC
24
+ self.arguments = ['-name', '-app_names']
25
+
26
+ def run
27
+ workstation_name = get_workstation_name
28
+ result = ::ChidConfig.on_osx { select_apps_on_osx }
29
+
30
+ if result.empty?
31
+ puts "\nYou did not select any App, please try again."
32
+ return
33
+ end
34
+
35
+ chid_config.create_workstation(workstation_name, result)
36
+
37
+ puts "\n#{workstation_name} workstation was created!"
38
+ end
39
+
40
+ private
41
+
42
+ def get_workstation_name
43
+ return option_name if option_name
44
+
45
+ puts 'tell me the name of the new workstation'
46
+ print "> "
47
+ STDIN.gets.strip
48
+ end
49
+
50
+ def option_name
51
+ options['-name']&.first&.strip
52
+ end
53
+
54
+ def option_app_names
55
+ options['-app_names']
56
+ end
57
+
58
+ def chid_config
59
+ ::ChidConfig.new
60
+ end
61
+
62
+ def select_apps_on_osx
63
+ prompt = TTY::Prompt.new
64
+
65
+ choices = osx_application_names
66
+
67
+ default_choices = default_choices(choices)
68
+
69
+ prompt.multi_select('select all apps for that workstation?', choices, default: default_choices)
70
+ end
71
+
72
+
73
+ def osx_application_names
74
+ osx_application_names = %x{ls /applications}.strip
75
+
76
+ osx_application_names
77
+ .gsub(/\n/, ' - ')
78
+ .gsub('.app', '')
79
+ .split(' - ')
80
+ end
81
+
82
+ def default_choices(choices)
83
+ return unless option_app_names
84
+
85
+ choices
86
+ .flatten
87
+ .each_with_object([])
88
+ .each_with_index do |(choice, memo), index|
89
+ memo << index + 1 if choice_in_option_app_names?(choice)
90
+ end
91
+ end
92
+
93
+ def choice_in_option_app_names?(choice)
94
+ DidYouMean::SpellChecker
95
+ .new(dictionary: option_app_names)
96
+ .correct(choice).any?
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end