bombay 0.1.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6995fb52e822ad155c50c7929a7739b5ec7d33634adf40406f922d2a7c5986a2
4
- data.tar.gz: d580dba8b3d38f32c47e7fec855292203d91cc2a15f2f18d2a25e3210f47530f
3
+ metadata.gz: 258caa2ba9f5deb75fd7be84e4084af50b6b2937d2fcd28fae7851f56289c9a3
4
+ data.tar.gz: 4231b016c7a18e0fef2a9e00532b36f04e57ef91e7786f84fc9a173198c2f230
5
5
  SHA512:
6
- metadata.gz: bdcaa147d64877122dae7fb9b16260a6c54c5cc83ee65f31a8ff0acc66dbed17007c11aa2e6a54be94a44480362c89491aa1a8630a6b79ba2c59d99609d98210
7
- data.tar.gz: 7703560c17159d3a2230f01f5f7afed389f528843e68450240b7a977045512fc2787bb58648e7824196c72f17d064cc54f3329a745992a3c858f8dabf2860c25
6
+ metadata.gz: 58a1ca1a28350a1f7158e39290372c59d686cbcf64d120594060ab22180eeec360b3bb5d4710553bd513c27053488fcdabd0e4c061ca519d99ef9f472f574e25
7
+ data.tar.gz: 154d7ae5209e966741e01e66f1899711e3976d101f2026a2b40cb65d21c333a726f8554990eef3bdca76b6837d28e9b443f4c9dcb76e6c06bd9d06de5dfd17ca
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Aziz Ben Ali
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # bombay
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/bombay.svg)](https://badge.fury.io/rb/bombay)
4
+
3
5
  `bombay` sorts the files in your working directory by filetype, and
4
6
  sends them to their appropriate `$XDG_*_DIR`.
5
7
 
8
+ ## Installation
9
+
10
+ ```
11
+ gem install bombay
12
+ ```
13
+
6
14
  ## Usage
7
15
 
8
16
  Imagine you had this mess in your `~/Downloads`:
@@ -38,15 +46,11 @@ badger-sock.pdf kind-vulture.epub
38
46
  summer-dance.gif funny-dialect.mp4
39
47
  ```
40
48
 
41
- `bombay` will parse your `$XDG_CONFIG_HOME/user-dirs.dirs` to locate
42
- the directories inside of which the files will be organized. Because
43
- of this, it is limited to *Linux* for the moment.
44
-
45
- ## Installation
49
+ ## Platform support
46
50
 
47
- ```
48
- gem install bombay
49
- ```
51
+ `bombay` was initially built for Linux with support for XDG user
52
+ directories, but has been extended to support macOS, although that remains to
53
+ be tested. The program will not run on any other platforms.
50
54
 
51
55
  ## Copying
52
56
 
data/bin/bombay ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bombay"
5
+ include Bombay
6
+
7
+ # Parse and process user directories
8
+ directories = Directories.new
9
+
10
+ # Initialize filetypes
11
+ filetypes = Filetypes.new
12
+
13
+ # Group files by filetype
14
+ pictures = filter_files(filetypes.pictures)
15
+ videos = filter_files(filetypes.videos)
16
+ documents = filter_files(filetypes.documents)
17
+
18
+ # Stack files into their appropriate directory
19
+ stack(pictures, directories.pictures)
20
+ stack(videos, directories.videos)
21
+ stack(documents, directories.documents)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Provides some helpful methods for strings
4
+ class String
5
+ # Unquotes a string.
6
+ def unquote
7
+ tr('"', "")
8
+ end
9
+
10
+ # Expands $HOME.
11
+ def expand
12
+ gsub("$HOME", Dir.home)
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bombay
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/bombay.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "bombay/version"
4
+ require_relative "bombay/string"
5
+
4
6
  require "fileutils"
7
+ require "os"
5
8
 
6
9
  # This module exposes the methods used to organize your $(pwd).
7
10
  module Bombay
@@ -19,7 +22,6 @@ module Bombay
19
22
  src_dir = FileUtils.pwd
20
23
 
21
24
  return if src_dir == dest_dir
22
-
23
25
  return if files.empty?
24
26
 
25
27
  FileUtils.mkdir(dest_dir) unless File.directory?(dest_dir)
@@ -36,26 +38,48 @@ class Directories
36
38
  ENV["XDG_CONFIG_HOME"] || File.join(Dir.home, ".config")
37
39
  end
38
40
 
39
- def user_dirs
41
+ def xdg_directory_type(dir)
42
+ dir.delete_prefix("XDG_").delete_suffix("_DIR")
43
+ end
44
+
45
+ def user_dirs_file
40
46
  File.join(config_directory, "user-dirs.dirs")
41
47
  end
42
48
 
43
- def parse_entry(line)
44
- entry = line.split("=")
45
- key = entry.first
46
- value = entry.last.tr('"', "").gsub("$HOME", Dir.home).strip
47
- [key, value]
49
+ def xdg_directories
50
+ dirs = {}
51
+ File.open(user_dirs_file).each do |line|
52
+ next if line.start_with?("#")
53
+ next if line.strip.empty?
54
+
55
+ entry = line.split("=")
56
+ key = xdg_directory_type(entry.first)
57
+ value = entry.last.unquote.expand.strip
58
+ dirs.store(key, value)
59
+ end
60
+ dirs
61
+ end
62
+
63
+ def macos_directories
64
+ dirs = {}
65
+ dirs.store("DOCUMENTS", File.join(Dir.home, "Documents"))
66
+ dirs.store("PICTURES", File.join(Dir.home, "Pictures"))
67
+ dirs.store("VIDEOS", File.join(Dir.home, "Movies"))
68
+ dirs
48
69
  end
49
70
 
50
71
  def initialize
51
- File.open(user_dirs).each do |line|
52
- xdg_dir = parse_entry(line)
53
- case xdg_dir.first
54
- when "XDG_DOCUMENTS_DIR" then @documents = xdg_dir.last
55
- when "XDG_PICTURES_DIR" then @pictures = xdg_dir.last
56
- when "XDG_VIDEOS_DIR" then @videos = xdg_dir.last
57
- end
58
- end
72
+ dirs = if OS.linux?
73
+ xdg_directories
74
+ elsif OS.macos?
75
+ macos_directories
76
+ else
77
+ abort("Unsupported platform.")
78
+ end
79
+
80
+ @documents = dirs["DOCUMENTS"]
81
+ @pictures = dirs["PICTURES"]
82
+ @videos = dirs["VIDEOS"]
59
83
  end
60
84
  end
61
85
 
metadata CHANGED
@@ -1,36 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bombay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - grtcdr
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-05-21 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: os
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.6
13
27
  description:
14
- email:
15
- - ba.tahaaziz@gmail.com
16
- executables: []
28
+ email: ba.tahaaziz@gmail.com
29
+ executables:
30
+ - bombay
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
34
  - ".rubocop.yml"
21
35
  - Gemfile
22
36
  - Gemfile.lock
37
+ - LICENSE
23
38
  - README.md
24
39
  - Rakefile
25
- - bombay.gemspec
40
+ - bin/bombay
26
41
  - lib/bombay.rb
42
+ - lib/bombay/string.rb
27
43
  - lib/bombay/version.rb
28
44
  - sig/bombay.rbs
29
- homepage: https://github.com/grtcdr/bombay
45
+ homepage: https://rubygems.org/gems/bombay
30
46
  licenses:
31
47
  - MIT
32
48
  metadata:
33
- homepage_uri: https://github.com/grtcdr/bombay
49
+ homepage_uri: https://rubygems.org/gems/bombay
34
50
  source_code_uri: https://github.com/grtcdr/bombay
35
51
  post_install_message:
36
52
  rdoc_options: []
@@ -50,5 +66,5 @@ requirements: []
50
66
  rubygems_version: 3.3.8
51
67
  signing_key:
52
68
  specification_version: 4
53
- summary: Organize your $(pwd)
69
+ summary: Organize your $(pwd).
54
70
  test_files: []
data/bombay.gemspec DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/bombay/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "bombay"
7
- spec.version = Bombay::VERSION
8
- spec.authors = ["grtcdr"]
9
- spec.email = ["ba.tahaaziz@gmail.com"]
10
-
11
- spec.summary = "Organize your $(pwd)"
12
- spec.homepage = "https://github.com/grtcdr/bombay"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(__dir__) do
22
- `git ls-files -z`.split("\x0").reject do |f|
23
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
- end
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
- end