From 2059abb93c0592613d78b2598e56ebf12dbc4c3e Mon Sep 17 00:00:00 2001 From: Florian Schrofner Date: Tue, 16 May 2023 17:01:26 +0200 Subject: [PATCH] add drawable mover script --- drawable-mover/dm.clj | 25 +++++++++++++++++++++++++ drawable-mover/readme.md | 21 +++++++++++++++++++++ resource-renamer/readme.md | 1 - 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 drawable-mover/dm.clj create mode 100644 drawable-mover/readme.md diff --git a/drawable-mover/dm.clj b/drawable-mover/dm.clj new file mode 100755 index 0000000..4002b7c --- /dev/null +++ b/drawable-mover/dm.clj @@ -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)))))) diff --git a/drawable-mover/readme.md b/drawable-mover/readme.md new file mode 100644 index 0000000..aeec83d --- /dev/null +++ b/drawable-mover/readme.md @@ -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`. diff --git a/resource-renamer/readme.md b/resource-renamer/readme.md index 2cee41b..00afa17 100644 --- a/resource-renamer/readme.md +++ b/resource-renamer/readme.md @@ -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: ```