toolkit / zsh /git-wrapper.zsh
k4d3's picture
update every stupid script
c2cc76d
raw
history blame
2.35 kB
#!/bin/zsh
# This function is a wrapper for the 'git' command, providing additional functionality for the 'clone' and 'add' operations.
#
# Usage:
# git <command> [<args>...]
#
# Parameters:
# <command> - The git command to execute (e.g., clone, pull, push, add, etc.).
# [<args>...] - The arguments to pass to the git command.
#
# Functionality:
# - If the first argument is 'clone', the function executes 'git clone' with the '--recurse-submodules' option.
# This ensures that all submodules are cloned along with the main repository.
# - If the first argument is 'add', the function checks if the current directory is inside '~/datasets'.
# If it is, it checks for the existence of a '.gitattributes' file and runs 'git lfs track "*.jxl"' before executing 'git add'.
# - For any other git command, the function simply passes all arguments to the 'git' command as-is.
#
# Examples:
# git clone https://github.com/user/repo.git
# This will execute 'git clone --recurse-submodules https://github.com/user/repo.git', cloning the repository along with its submodules.
#
# git add .
# This will check if the current directory is inside '~/datasets', check for a '.gitattributes' file, and run 'git lfs track "*.jxl"' if the file exists, then execute 'git add .'.
#
# git pull origin main
# This will execute 'git pull origin main', pulling the latest changes from the 'main' branch.
#
# Notes:
# - This function uses 'command' to bypass any other shell functions or aliases named 'git', ensuring that the actual git command is executed.
# - The use of "${@:2}" in the 'clone' case ensures that all arguments after 'clone' are passed to the 'git clone' command.
# - The use of "${@:2}" in the 'add' case ensures that all arguments after 'add' are passed to the 'git add' command.
# - The function checks if the current directory is inside '~/datasets' by comparing the current directory path with the '~/datasets' path.
function git() {
if [[ "$1" == "clone" ]]; then
command git clone --recurse-submodules "${@:2}"
elif [[ "$1" == "add" ]]; then
if [[ "$(pwd)" == ~/datasets* ]]; then
if [[ -f .gitattributes ]]; then
command git lfs track "*.jxl"
fi
fi
command git add "${@:2}"
else
command git "$@"
fi
}