desktop-boom 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/boom +41 -21
  3. data/lib/boom/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 547d447776351c8de974b75d424e32efd1ec6e76
4
- data.tar.gz: 4d439cecb4cc7bc8a3a79070b6c6283f56fc129a
3
+ metadata.gz: fd8dab305f791bf40d2f3a977ee742576070cee3
4
+ data.tar.gz: cac3af03a8f2b2f1a783ce87c41deef5cb43ca7a
5
5
  SHA512:
6
- metadata.gz: a641c607de91bfbf4e1e7bf415b42799349233e24d6d8306379db1d19c9273c1de3bdf691a002d02aa3b212043a9f29b6b2e71aee71f72c9f23f70b016ed36a9
7
- data.tar.gz: e69695c049a3e9f7c3fe488f09e431a2699ba047c8dcf859418b3b34a08f3a6f3c83b5a07c9e5bf1e009acfedb0dc77e666cd31c58e0069e108c719deff278ea
6
+ metadata.gz: 88629d36b73974e4a520e63ab95b6037a23c025e2cd30a61e2d2a8fd7e39d6c668a537b662f34409ec358d6c5f94b3d39abbd0a11a64dd1f08930ca66e25b451
7
+ data.tar.gz: b763052e70df7f3d256584ba1756ce794f47cbbdfe820d778e977a2b3d4a42b2084d96bc1b6d6d53df71852f86340f20f1f3cf410ccd44eb0beeb574a54cf0e7
data/bin/boom CHANGED
@@ -34,6 +34,7 @@ If `B` doesn't exist yet, it will be created.
34
34
 
35
35
  program :version, DesktopBoom::VERSION
36
36
  program :description, HELP_STRING
37
+ program :help, 'Author', 'Hwee-Boon Yar <hboon@motionobj.com>'
37
38
 
38
39
  default_command :switch
39
40
 
@@ -41,6 +42,25 @@ def config_path
41
42
  File.expand_path("~/.config/#{APP_NAME}.yml")
42
43
  end
43
44
 
45
+ def with_config(&block)
46
+ File.open(config_path) do |f|
47
+ mapping = Psych.load(f.read)
48
+ projects_directory = mapping['projects_directory']
49
+ current_project = mapping['current_project']
50
+ block.call(mapping, projects_directory, current_project)
51
+ end
52
+ end
53
+
54
+ def projects
55
+ with_config do |mapping, projects_directory, current_project|
56
+ return Dir.entries(File.expand_path(projects_directory)).reject {|e| e == '.' || e == '..' || !File.directory?(File.expand_path(e, projects_directory))}
57
+ end
58
+ end
59
+
60
+ def entries_in_dir(dir)
61
+ entries = Dir.entries(dir).reject {|e| e == '.' || e == '..' || e.start_with?('.')}
62
+ end
63
+
44
64
  command :switch do |c|
45
65
  c.syntax = "#{APP_NAME} [switch]"
46
66
  c.summary = 'Switch project'
@@ -54,11 +74,7 @@ doesn't exist, it will be created:
54
74
  " and abort if args.empty?
55
75
  new_project = args[0]
56
76
  create_configuration_file unless File.file? config_path
57
- File.open(config_path) do |f|
58
- mapping = Psych.load(f.read)
59
- projects_directory = mapping['projects_directory']
60
- current_project = mapping['current_project']
61
-
77
+ with_config do |mapping, projects_directory, current_project|
62
78
  if new_project == current_project
63
79
  say "Already at project '#{current_project}'"
64
80
  break
@@ -77,10 +93,7 @@ command :current do |c|
77
93
  c.example 'Run command', "$ #{APP_NAME} current"
78
94
  c.action do |args, options|
79
95
  create_configuration_file unless File.file? config_path
80
- File.open(config_path) do |f|
81
- mapping = Psych.load(f.read)
82
- projects_directory = mapping['projects_directory']
83
- current_project = mapping['current_project']
96
+ with_config do |mapping, projects_directory, current_project|
84
97
  say current_project
85
98
  end
86
99
  end
@@ -94,22 +107,18 @@ command :list do |c|
94
107
  c.option '-l', 'List in long format'
95
108
  c.action do |args, options|
96
109
  create_configuration_file unless File.file? config_path
97
- File.open(config_path) do |f|
98
- mapping = Psych.load(f.read)
99
- projects_directory = mapping['projects_directory']
100
- projects = Dir.entries(File.expand_path(projects_directory)).reject {|e| e == '.' || e == '..' || !File.directory?(File.expand_path(e, projects_directory))}
101
- current_project = mapping['current_project']
110
+ with_config do |mapping, projects_directory, current_project|
102
111
  projects.each do |e|
103
112
  if e == current_project
104
113
  if options.l
105
- entries = Dir.entries(File.expand_path(DESKTOP_DIR)).reject {|e| e == '.' || e == '..' || e.start_with?('.')}
114
+ entries = entries_in_dir(File.expand_path(DESKTOP_DIR))
106
115
  say "#{e} (#{entries.size}) <="
107
116
  else
108
117
  say "#{e} <="
109
118
  end
110
119
  else
111
120
  if options.l
112
- entries = Dir.entries(File.expand_path(e, projects_directory)).reject {|e| e == '.' || e == '..' || e.start_with?('.')}
121
+ entries = entries_in_dir(File.expand_path(e, projects_directory))
113
122
  say "#{e} (#{entries.size})"
114
123
  else
115
124
  say e
@@ -129,11 +138,7 @@ command :rename do |c|
129
138
  say_error "You must specify both the original project name and the new project name
130
139
  $ #{APP_NAME} rename <source> <target>
131
140
  " and abort unless args.size == 2
132
- File.open(config_path) do |f|
133
- mapping = Psych.load(f.read)
134
- projects_directory = mapping['projects_directory']
135
- current_project = mapping['current_project']
136
- projects = Dir.entries(File.expand_path(projects_directory)).reject {|e| e == '.' || e == '..' || !File.directory?(File.expand_path(e, projects_directory))}
141
+ with_config do |mapping, projects_directory, current_project|
137
142
  source = args[0]
138
143
  destination = args[1]
139
144
  say_error "Project does not exist: `#{source}`" and abort unless (projects + [current_project]).include? source
@@ -144,6 +149,21 @@ command :rename do |c|
144
149
  end
145
150
  end
146
151
 
152
+ command :close do |c|
153
+ c.syntax = "#{APP_NAME} close"
154
+ c.summary = 'Close current project'
155
+ c.description = c.summary
156
+ c.example 'Run command', "$ #{APP_NAME} close"
157
+ c.action do |args, options|
158
+ create_configuration_file unless File.file? config_path
159
+ with_config do |mapping, projects_directory, current_project|
160
+ break unless current_project && !current_project.empty?
161
+ move_desktop_to_project(current_project, projects_directory)
162
+ switch_to(mapping, '')
163
+ end
164
+ end
165
+ end
166
+
147
167
  def create_configuration_file
148
168
  write_configuration(nil)
149
169
  end
data/lib/boom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DesktopBoom
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desktop-boom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hwee-Boon Yar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander