add drawable mover script

master
Florian Schrofner 2023-05-16 17:01:26 +02:00
parent 7dcc8b095c
commit 2059abb93c
3 changed files with 46 additions and 1 deletions

25
drawable-mover/dm.clj Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bb
(require '[clojure.tools.cli :refer [parse-opts]])
(def cli-options
[["-s" "--source DIRECTORY" "Source directory containing the drawable folders"]
["-d" "--destination DIRECTORY" "Destination directory where the drawables should be moved to"]
["-n" "--name DRAWABLE_NAME" "The name of the drawable to move WITHOUT file extension"]])
(def options (:options (parse-opts *command-line-args* cli-options)))
(def drawable-folder-regex #"drawable-?(.*)?")
(def drawable-file-extension-regex-str "\\.[a-zA-Z]+")
(let [source-directory (io/file (:source options))
destination-directory (io/file (:destination options))
drawable-name (:name options)
source-drawable-directories (filter #(re-matches drawable-folder-regex (.getName %)) (.listFiles source-directory))]
(doseq [folder source-drawable-directories]
(let [files-to-move (filter #(re-matches (re-pattern (str drawable-name drawable-file-extension-regex-str)) (.getName %)) (.listFiles folder))]
(when-not (empty? files-to-move)
(let [file-to-move (first files-to-move)
target-file (io/file (.getAbsolutePath destination-directory) (.getName folder) (.getName file-to-move))]
(println (str "moving " (.getName (.getParentFile file-to-move)) fs/file-separator (.getName file-to-move)))
(.mkdirs (.getParentFile target-file))
(.renameTo file-to-move target-file))))))

21
drawable-mover/readme.md Normal file
View File

@ -0,0 +1,21 @@
# Drawable Mover
Quickly moves drawables from one module to another. It will reuse the density and file extension of the source file and simply move those drawables to the specified target module.
Just specify the source directory `-s` (the resource directory of the source module), the destination `-d` and the name of the resource to move `-n` *without* file extension.
## Example Usage
```bash
./dm.clj -s /home/schrofi/Projects/multi-module-project/app-module/src/main/res/ -d /home/schrofi/Projects/multi-module-project/shared-module/src/main/res -n "drawable-to-move"
```
### Fish
You can make it a bit more convenient to use by creating a fish function to at least fill in the source directory for you based on the current working directory.
```
function dm
PATH_TO_SCRIPT/dm.clj -s $(pwd) -n $argv[1] -d $argv[2]
end
funcsave dm
```
Then you can simply open a terminal in the source resource directory and execute the command like `dm DRAWABLE_NAME DESTINATION_DIRECTORY`.

View File

@ -7,7 +7,6 @@ It will reuse the file extension of the files that are already present inside th
./rr.clj -d "/home/schrofi/Downloads/random_asset" -n "ic_photo"
```
##
### Fish
To more conveniently use the tool from the commandline, you can define a fish function like this:
```