Skip to content

Instantly share code, notes, and snippets.

@prabhatsdp
Created May 22, 2026 04:37
Show Gist options
  • Select an option

  • Save prabhatsdp/dcde3c49e5f9e19c4d58cc992cfae60d to your computer and use it in GitHub Desktop.

Select an option

Save prabhatsdp/dcde3c49e5f9e19c4d58cc992cfae60d to your computer and use it in GitHub Desktop.
Zsh Function for Android Drawable Copy Script
# ==============================================================================
# copy_drawables
# ==============================================================================
#
# A small zsh helper function for running the Android Drawable Resource Copy
# Assistant from anywhere in the terminal.
#
# This function wraps the main Bash script:
#
# ~/scripts/copy_drawable_resources.sh
#
# Instead of manually going into the destination `res` folder and running the
# Bash script, you can simply run:
#
# copy_drawables <source-folder> <destination-res-folder>
#
# ------------------------------------------------------------------------------
# Usage
# ------------------------------------------------------------------------------
#
# 1. From inside Android `res` folder:
#
# cd app/src/main/res
# copy_drawables ~/Downloads/source-res
#
# 2. From anywhere:
#
# copy_drawables ~/Downloads/source-res ~/AndroidProjects/MyApp/app/src/main/res
#
# ------------------------------------------------------------------------------
# Parameters
# ------------------------------------------------------------------------------
#
# $1 - Source folder
# The folder that contains drawable folders like:
# drawable/
# drawable-mdpi/
# drawable-hdpi/
# drawable-xhdpi/
# drawable-xxhdpi/
# drawable-xxxhdpi/
#
# $2 - Destination Android res folder
# Optional.
# If not provided, the current directory will be used.
#
# ------------------------------------------------------------------------------
# Setup
# ------------------------------------------------------------------------------
#
# 1. Save the main Bash script at:
#
# ~/scripts/copy_drawable_resources.sh
#
# 2. Make it executable:
#
# chmod +x ~/scripts/copy_drawable_resources.sh
#
# 3. Add this function to:
#
# ~/.zshrc
#
# 4. Reload zsh:
#
# source ~/.zshrc
#
# ------------------------------------------------------------------------------
# Creator
# ------------------------------------------------------------------------------
#
# Crafted by Prabhat Pandey
#
# Built with love for Android developers who frequently copy drawable assets
# between projects, exported design folders, and resource bundles.
#
# Because manually copying drawable-mdpi, drawable-xhdpi, drawable-xxhdpi...
# one by one is not productivity. It is punishment.
#
# ==============================================================================
copy_drawables() {
local source_dir="$1"
local dest_dir="${2:-$(pwd)}"
local script_path="$HOME/scripts/copy_drawable_resources.sh"
# ---------------------------------------------------------------------------
# Validate source input.
# ---------------------------------------------------------------------------
if [[ -z "$source_dir" ]]; then
echo "❌ Source folder is required."
echo ""
echo "Usage:"
echo "copy_drawables /path/to/source-folder"
echo "copy_drawables /path/to/source-folder /path/to/destination-res-folder"
return 1
fi
# ---------------------------------------------------------------------------
# Validate source directory.
# ---------------------------------------------------------------------------
if [[ ! -d "$source_dir" ]]; then
echo "❌ Source folder does not exist:"
echo "$source_dir"
return 1
fi
# ---------------------------------------------------------------------------
# Validate destination directory.
# ---------------------------------------------------------------------------
if [[ ! -d "$dest_dir" ]]; then
echo "❌ Destination folder does not exist:"
echo "$dest_dir"
return 1
fi
# ---------------------------------------------------------------------------
# Validate main script path.
# ---------------------------------------------------------------------------
if [[ ! -f "$script_path" ]]; then
echo "❌ Script not found:"
echo "$script_path"
echo ""
echo "Please make sure copy_drawable_resources.sh exists at:"
echo "~/scripts/copy_drawable_resources.sh"
return 1
fi
# ---------------------------------------------------------------------------
# Run the main Bash script from inside the destination res folder.
#
# The Bash script treats the current working directory as the destination.
# That is why we temporarily cd into the destination folder here.
# ---------------------------------------------------------------------------
(
cd "$dest_dir" || exit 1
bash "$script_path" "$source_dir"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment