From 0da9b06a43bd42ec0a2a3c90a63f217054ea04c1 Mon Sep 17 00:00:00 2001 From: yuting1214 Date: Tue, 25 Feb 2025 23:54:50 +0800 Subject: [PATCH 1/3] feat: add large-file-script. --- large-files | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 large-files diff --git a/large-files b/large-files new file mode 100644 index 0000000..df4c1f1 --- /dev/null +++ b/large-files @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +# Function to display help message +usage() { + cat </dev/null 2>&1; then + echo "Error: Not inside a Git repository." + exit 1 +fi + +echo "🔍 Finding the $NUM_FILES largest files in the repository..." + +# Extract large files from Git history +git rev-list --objects --all | + git cat-file --batch-check='%(objectsize:disk) %(rest)' | + sort -rh | + head -n "$NUM_FILES" | + awk '{ printf "%10s %s\n", $1, $2 }' | + numfmt --to=iec-i --suffix=B --padding=7 --field=1 + +echo "✅ Done!" From 9b5f72c24447158a892152a8a9a404444b6f7b3a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 00:34:31 +0000 Subject: [PATCH 2/3] chore: autofix via pre-commit hooks for more information, see https://pre-commit.ci --- ach | 154 ++++++++++++++++++++++++++-------------------------- chdirx | 84 ++++++++++++++-------------- gcfixup | 22 ++++---- git-shed | 124 +++++++++++++++++++++--------------------- how-big | 20 +++---- mergewith | 68 +++++++++++------------ touchx | 68 +++++++++++------------ update-mine | 122 ++++++++++++++++++++--------------------- venv-now | 74 ++++++++++++------------- 9 files changed, 368 insertions(+), 368 deletions(-) diff --git a/ach b/ach index 94f87fd..8eff1bb 100755 --- a/ach +++ b/ach @@ -7,7 +7,7 @@ DEFAULT_FILE=".git-blame-ignore-revs" INCLUDE_SUMMARY=true HELP=$( - cat << EOF + cat < /dev/null || echo) - if [ -z "$HASH_ENTRY" ]; then - echo "No prior commits found. Please make an initial commit before running this script." - exit 1 - fi + echo "Getting the last commit hash..." + HASH_ENTRY=$(git log -1 --pretty=format:"%H" 2>/dev/null || echo) + if [ -z "$HASH_ENTRY" ]; then + echo "No prior commits found. Please make an initial commit before running this script." + exit 1 + fi else - HASH_ENTRY="$HASH_ARG" + HASH_ENTRY="$HASH_ARG" fi -if ! git cat-file -e "$HASH_ENTRY" 2> /dev/null; then - echo "Invalid commit hash: $HASH_ENTRY" - exit 1 +if ! git cat-file -e "$HASH_ENTRY" 2>/dev/null; then + echo "Invalid commit hash: $HASH_ENTRY" + exit 1 fi HASH_ENTRY=$(git rev-parse "$HASH_ENTRY") @@ -76,69 +76,69 @@ SHORT_HASH=$(echo "$HASH_ENTRY" | cut -c 1-7) CREATE_MODE=0 if [ -f "$FILE" ]; then - if grep -qE "^\s*$SHORT_HASH" "$FILE"; then - echo "Hash already exists in $FILE. Skipping." - exit 0 - fi + if grep -qE "^\s*$SHORT_HASH" "$FILE"; then + echo "Hash already exists in $FILE. Skipping." + exit 0 + fi else - echo "Creating $FILE with commit hash." - CREATE_MODE=1 + echo "Creating $FILE with commit hash." + CREATE_MODE=1 fi if git status --short "$FILE" | grep -q "^[ MADRCU?]"; then - echo "The file $FILE has unstaged changes." - printf "Are you sure you want to proceed (y/n)? " - read -r confirm - confirm=${confirm:-n} - case "$confirm" in - [yY][eE][sS] | [yY]) ;; - *) - echo "Aborted." - exit 1 - ;; - esac + echo "The file $FILE has unstaged changes." + printf "Are you sure you want to proceed (y/n)? " + read -r confirm + confirm=${confirm:-n} + case "$confirm" in + [yY][eE][sS] | [yY]) ;; + *) + echo "Aborted." + exit 1 + ;; + esac fi STASHED=false if [ -n "$(git diff --cached)" ]; then - echo "There are staged changes. Stashing them temporarily..." - git stash push -k -m "Temporary stash for $SCRIPT_NAME" - STASHED=true - echo "Staged changes stashed." + echo "There are staged changes. Stashing them temporarily..." + git stash push -k -m "Temporary stash for $SCRIPT_NAME" + STASHED=true + echo "Staged changes stashed." fi { - if [[ $INCLUDE_SUMMARY == true ]]; then - SUMMARY=$(git log -1 --format=%s "$HASH_ENTRY" 2> /dev/null || echo "summary unavailable") - HASH_ENTRY="$HASH_ENTRY # $SUMMARY" - fi - echo "$HASH_ENTRY" >> "$FILE" - git add "$FILE" - COMMIT_MSG="docs(blame): ignore $SHORT_HASH" - - if [[ $CREATE_MODE -eq 1 && ${#FILE} -lt 38 ]]; then - COMMIT_MSG="docs: create $FILE" - if [[ ${#COMMIT_MSG} -lt 44 ]]; then - COMMIT_MSG="docs(blame): create $FILE" - else - if [[ ${#COMMIT_MSG} -lt 38 ]]; then - COMMIT_MSG="$COMMIT_MSG with $SHORT_HASH" - fi - fi - fi - - git commit --no-verify -m "$COMMIT_MSG" - echo "Successfully updated and committed $FILE." + if [[ $INCLUDE_SUMMARY == true ]]; then + SUMMARY=$(git log -1 --format=%s "$HASH_ENTRY" 2>/dev/null || echo "summary unavailable") + HASH_ENTRY="$HASH_ENTRY # $SUMMARY" + fi + echo "$HASH_ENTRY" >>"$FILE" + git add "$FILE" + COMMIT_MSG="docs(blame): ignore $SHORT_HASH" + + if [[ $CREATE_MODE -eq 1 && ${#FILE} -lt 38 ]]; then + COMMIT_MSG="docs: create $FILE" + if [[ ${#COMMIT_MSG} -lt 44 ]]; then + COMMIT_MSG="docs(blame): create $FILE" + else + if [[ ${#COMMIT_MSG} -lt 38 ]]; then + COMMIT_MSG="$COMMIT_MSG with $SHORT_HASH" + fi + fi + fi + + git commit --no-verify -m "$COMMIT_MSG" + echo "Successfully updated and committed $FILE." } || { - echo "Failed to update $FILE. Resolve manually." - if [ "$STASHED" = true ]; then git stash pop || echo "Failed to apply stashed changes."; fi - exit 1 + echo "Failed to update $FILE. Resolve manually." + if [ "$STASHED" = true ]; then git stash pop || echo "Failed to apply stashed changes."; fi + exit 1 } if [ "$STASHED" = true ]; then - echo "Reapplying stashed changes..." - git stash pop || { - echo "Failed to apply stashed changes. Resolve manually." - exit 1 - } + echo "Reapplying stashed changes..." + git stash pop || { + echo "Failed to apply stashed changes. Resolve manually." + exit 1 + } fi diff --git a/chdirx b/chdirx index b98ff50..e301eda 100755 --- a/chdirx +++ b/chdirx @@ -5,7 +5,7 @@ RECURSIVE=false TARGET_DIR="" usage() { - cat << EOF + cat < Adds executable permission to scripts in the specified directory. If a file starts with @@ -23,61 +23,61 @@ Examples: $SCRIPT_NAME -r mydir # Process subdirectories as well $SCRIPT_NAME mydir -r EOF - exit "$1" + exit "$1" } # Parse arguments manually to allow flexible order while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - usage 0 - ;; - -r) - RECURSIVE=true - ;; - -*) - echo "Error: Unknown option '$1'" >&2 - usage 1 - ;; - *) - if [[ -n $TARGET_DIR ]]; then - echo "Error: Multiple directories specified: '$TARGET_DIR' and '$1'" >&2 - usage 1 - fi - TARGET_DIR="$1" - ;; - esac - shift + case "$1" in + -h | --help) + usage 0 + ;; + -r) + RECURSIVE=true + ;; + -*) + echo "Error: Unknown option '$1'" >&2 + usage 1 + ;; + *) + if [[ -n $TARGET_DIR ]]; then + echo "Error: Multiple directories specified: '$TARGET_DIR' and '$1'" >&2 + usage 1 + fi + TARGET_DIR="$1" + ;; + esac + shift done # Ensure exactly one directory is provided if [[ -z $TARGET_DIR ]]; then - echo "Error: No directory specified." >&2 - usage 1 + echo "Error: No directory specified." >&2 + usage 1 fi if [[ ! -d $TARGET_DIR ]]; then - echo "Error: '$TARGET_DIR' is not a directory." >&2 - exit 1 + echo "Error: '$TARGET_DIR' is not a directory." >&2 + exit 1 fi process_directory() { - local dir="$1" - # Iterate over both normal and hidden files/directories - for file in "$dir"/.* "$dir"/*; do - # Skip if file doesn't exist (handles empty dirs) or if it's `.` or `..` - [[ -e $file && $file != "$dir/." && $file != "$dir/.." ]] || continue - if [[ -f $file ]]; then - # Check if the first line starts with #! - if head -n 1 "$file" | grep -q '^#!'; then - chmod +x "$file" - echo "Added executable permission to: $file" - fi - elif [[ -d $file && $RECURSIVE == true ]]; then - # Recursively process subdirectories - process_directory "$file" - fi - done + local dir="$1" + # Iterate over both normal and hidden files/directories + for file in "$dir"/.* "$dir"/*; do + # Skip if file doesn't exist (handles empty dirs) or if it's `.` or `..` + [[ -e $file && $file != "$dir/." && $file != "$dir/.." ]] || continue + if [[ -f $file ]]; then + # Check if the first line starts with #! + if head -n 1 "$file" | grep -q '^#!'; then + chmod +x "$file" + echo "Added executable permission to: $file" + fi + elif [[ -d $file && $RECURSIVE == true ]]; then + # Recursively process subdirectories + process_directory "$file" + fi + done } process_directory "$TARGET_DIR" diff --git a/gcfixup b/gcfixup index 4acf6c7..c257149 100755 --- a/gcfixup +++ b/gcfixup @@ -3,7 +3,7 @@ SCRIPT_NAME=$(basename "$0") gcfixup() { - read -r -d '' HELP_MSG << EOF + read -r -d '' HELP_MSG <&2 - exit 1 + echo "Error: '$TARGET_DIR' is not a valid directory." >&2 + exit 1 fi # Run the disk usage command with optional file inclusion diff --git a/mergewith b/mergewith index ab6b783..fb3183b 100755 --- a/mergewith +++ b/mergewith @@ -3,7 +3,7 @@ SCRIPT_NAME=$(basename "$0") usage() { - cat << EOF + cat < Merges the latest changes from a reference branch into the current branch. @@ -24,73 +24,73 @@ Examples: $SCRIPT_NAME main $SCRIPT_NAME feature-branch EOF - exit 0 + exit 0 } reference_branch="" while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - usage - ;; - -*) - echo "Error: Unknown option '$1'" >&2 - usage - ;; - *) - if [[ -n $reference_branch ]]; then - echo "Error: Multiple reference branches provided: '$reference_branch' and '$1'" >&2 - usage - fi - reference_branch="$1" - ;; - esac - shift + case "$1" in + -h | --help) + usage + ;; + -*) + echo "Error: Unknown option '$1'" >&2 + usage + ;; + *) + if [[ -n $reference_branch ]]; then + echo "Error: Multiple reference branches provided: '$reference_branch' and '$1'" >&2 + usage + fi + reference_branch="$1" + ;; + esac + shift done # Ensure exactly one reference branch is provided if [[ -z $reference_branch ]]; then - echo "Error: No reference branch specified." >&2 - usage + echo "Error: No reference branch specified." >&2 + usage fi # Ensure this is a git repository -if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then - echo "Error: Not inside a git repository." - exit 1 +if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + echo "Error: Not inside a git repository." + exit 1 fi # Capture the current branch name if ! current_branch=$(git branch --show-current); then - echo "Error: Failed to determine the current git branch." - exit 1 + echo "Error: Failed to determine the current git branch." + exit 1 fi echo "Current branch is $current_branch" echo "Pulling latest changes for $current_branch" if ! git pull; then - echo "Error: Failed to pull the latest changes for branch '$current_branch'." - exit 1 + echo "Error: Failed to pull the latest changes for branch '$current_branch'." + exit 1 fi if [[ $current_branch == "$reference_branch" ]]; then - echo "Warning: The current branch and reference branch are the same: '$current_branch'" >&2 - exit 0 + echo "Warning: The current branch and reference branch are the same: '$current_branch'" >&2 + exit 0 fi # Ensure the reference branch is up to date echo "Fetching latest changes for $reference_branch" if ! git fetch origin "$reference_branch"; then - echo "Error: Failed to fetch latest changes for '$reference_branch'." - exit 1 + echo "Error: Failed to fetch latest changes for '$reference_branch'." + exit 1 fi # Merge the reference branch into the current branch echo "Merging $reference_branch into $current_branch" if ! git merge origin/"$reference_branch"; then - echo "Error: Failed to merge branch '$reference_branch' into '$current_branch'." - exit 1 + echo "Error: Failed to merge branch '$reference_branch' into '$current_branch'." + exit 1 fi echo "Successfully updated $current_branch with changes from $reference_branch." diff --git a/touchx b/touchx index 86f5f23..9395039 100755 --- a/touchx +++ b/touchx @@ -3,7 +3,7 @@ SCRIPT_NAME=$(basename "$0") usage() { - cat << EOF + cat < [ ...] Create or update the specified file(s) and make them executable. @@ -22,12 +22,12 @@ Examples: $SCRIPT_NAME script.sh $SCRIPT_NAME file1.sh file2.sh EOF - exit 0 + exit 0 } # Check if no arguments were provided if [ "$#" -lt 1 ]; then - usage + usage fi # Collect file arguments @@ -35,46 +35,46 @@ files=() # Parse options and collect valid file arguments while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - usage - ;; - -*) - echo "Error: Unknown option '$1'" >&2 - usage - ;; - *) - files+=("$1") - ;; - esac - shift + case "$1" in + -h | --help) + usage + ;; + -*) + echo "Error: Unknown option '$1'" >&2 + usage + ;; + *) + files+=("$1") + ;; + esac + shift done # Ensure at least one valid file argument remains if [ "${#files[@]}" -eq 0 ]; then - echo "Error: No files specified." >&2 - usage + echo "Error: No files specified." >&2 + usage fi # Process each file argument for file in "${files[@]}"; do - # Ensure the file argument is not empty - if [[ -z $file || $file =~ ^[[:space:]]+$ ]]; then - echo "Error: Invalid filename '$file'." >&2 - exit 1 - fi + # Ensure the file argument is not empty + if [[ -z $file || $file =~ ^[[:space:]]+$ ]]; then + echo "Error: Invalid filename '$file'." >&2 + exit 1 + fi - # Create or update the file - if ! touch "$file"; then - echo "Error: Failed to create or update '$file'." >&2 - exit 1 - fi + # Create or update the file + if ! touch "$file"; then + echo "Error: Failed to create or update '$file'." >&2 + exit 1 + fi - # Make the file executable - if ! chmod +x "$file"; then - echo "Error: Failed to set execute permission for '$file'." >&2 - exit 1 - fi + # Make the file executable + if ! chmod +x "$file"; then + echo "Error: Failed to set execute permission for '$file'." >&2 + exit 1 + fi - echo "Created and made executable: '$file'" + echo "Created and made executable: '$file'" done diff --git a/update-mine b/update-mine index fcdd201..050e2f8 100755 --- a/update-mine +++ b/update-mine @@ -8,7 +8,7 @@ SCRIPT_NAME=$(basename "$0") # Function to display usage information usage() { - cat << EOF + cat < Updates branches with open pull requests authored by you by: @@ -30,91 +30,91 @@ Examples: $SCRIPT_NAME --all main $SCRIPT_NAME --debug --all main EOF - exit 0 + exit 0 } # Parse command-line arguments reference_branch="" while [[ $# -gt 0 ]]; do - case "$1" in - --debug) - debug=true - shift - ;; - --all) - all_branches=true - shift - ;; - --help) - usage - ;; - -*) - echo "Unknown option: $1" >&2 - usage - ;; - *) - if [ -z "$reference_branch" ]; then - reference_branch="$1" - else - echo "Error: Multiple reference branches specified: '$reference_branch' and '$1'" >&2 - usage - fi - shift - ;; - esac + case "$1" in + --debug) + debug=true + shift + ;; + --all) + all_branches=true + shift + ;; + --help) + usage + ;; + -*) + echo "Unknown option: $1" >&2 + usage + ;; + *) + if [ -z "$reference_branch" ]; then + reference_branch="$1" + else + echo "Error: Multiple reference branches specified: '$reference_branch' and '$1'" >&2 + usage + fi + shift + ;; + esac done # Validate that a reference branch was provided if [ -z "$reference_branch" ]; then - echo "Error: Missing argument." >&2 - echo "Use --help for usage information." >&2 - exit 1 + echo "Error: Missing argument." >&2 + echo "Use --help for usage information." >&2 + exit 1 fi # Enable debugging if --debug flag is set if [ "$debug" = true ]; then - set -x + set -x fi # Ensure we are inside a Git repository -if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then - echo "Error: Not inside a Git repository." >&2 - exit 1 +if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + echo "Error: Not inside a Git repository." >&2 + exit 1 fi # Fetch latest remote branches to avoid using stale references -git remote update > /dev/null 2>&1 +git remote update >/dev/null 2>&1 # Determine the list of branches to update if [ "$all_branches" = true ]; then - echo "Fetching all non-protected active branches authored by you..." - branches=$(gh api repos/:owner/:repo/branches --paginate --jq '.[] | select(.protected == false) | .name') + echo "Fetching all non-protected active branches authored by you..." + branches=$(gh api repos/:owner/:repo/branches --paginate --jq '.[] | select(.protected == false) | .name') else - echo "Fetching branches with open PRs authored by you..." - branches=$(gh pr list --author "@me" --state open --json headRefName -q '.[].headRefName') + echo "Fetching branches with open PRs authored by you..." + branches=$(gh pr list --author "@me" --state open --json headRefName -q '.[].headRefName') fi # Iterate through branches and update them echo "$branches" | while read -r branch; do - echo "Processing branch: $branch" - - # Checkout the branch - if ! git checkout "$branch"; then - echo "Error: Failed to checkout branch $branch. Skipping..." - continue - fi - - # Merge the reference branch into the current branch - if ! mergewith "$reference_branch"; then - echo "Error: Failed to merge $reference_branch into $branch. Skipping..." - git merge --abort > /dev/null 2>&1 - continue - fi - - # Push the updated branch - if git push origin "$branch"; then - echo "Successfully updated and pushed branch: $branch" - else - echo "Error: Failed to push branch $branch. Skipping..." - fi + echo "Processing branch: $branch" + + # Checkout the branch + if ! git checkout "$branch"; then + echo "Error: Failed to checkout branch $branch. Skipping..." + continue + fi + + # Merge the reference branch into the current branch + if ! mergewith "$reference_branch"; then + echo "Error: Failed to merge $reference_branch into $branch. Skipping..." + git merge --abort >/dev/null 2>&1 + continue + fi + + # Push the updated branch + if git push origin "$branch"; then + echo "Successfully updated and pushed branch: $branch" + else + echo "Error: Failed to push branch $branch. Skipping..." + fi done diff --git a/venv-now b/venv-now index e6c529c..e1d5d57 100755 --- a/venv-now +++ b/venv-now @@ -2,7 +2,7 @@ SOURCED=$([[ ${BASH_SOURCE[0]} != "$0" ]] && echo true || echo false) return-or-exit() { - [[ $SOURCED == true ]] && return "$1" || exit "$1" + [[ $SOURCED == true ]] && return "$1" || exit "$1" } VENV_DIR=".venv" @@ -10,7 +10,7 @@ REMOVE_EXISTING=true SCRIPT_NAME=$(basename "$0") usage() { - cat << EOF + cat <&2 - usage - ;; - *) - if [ "$positional_arg_set" = false ]; then - VENV_DIR="$1" - positional_arg_set=true - else - echo "Error: Multiple directory arguments specified: '$VENV_DIR' and '$1'" >&2 - usage - fi - shift - ;; - esac + case "$1" in + -h | --help) + usage + ;; + -n | --no-remove) + REMOVE_EXISTING=false + shift + ;; + -*) + echo "Unknown option: $1" >&2 + usage + ;; + *) + if [ "$positional_arg_set" = false ]; then + VENV_DIR="$1" + positional_arg_set=true + else + echo "Error: Multiple directory arguments specified: '$VENV_DIR' and '$1'" >&2 + usage + fi + shift + ;; + esac done if $REMOVE_EXISTING && [ -d "$VENV_DIR" ]; then - echo "Removing existing virtual environment: $VENV_DIR" - rm -rf "$VENV_DIR" + echo "Removing existing virtual environment: $VENV_DIR" + rm -rf "$VENV_DIR" fi echo "Creating virtual environment in: $VENV_DIR" python -m venv "$VENV_DIR" if [ -f "$VENV_DIR/bin/activate" ]; then - echo "Virtual environment created: $VENV_DIR" + echo "Virtual environment created: $VENV_DIR" else - echo "Error: Virtual environment creation failed!" >&2 - return-or-exit 1 + echo "Error: Virtual environment creation failed!" >&2 + return-or-exit 1 fi if [[ $SOURCED == true ]]; then - # shellcheck disable=SC1091 - { . "$VENV_DIR/bin/activate" && echo "Virtual environment activated: $VENV_DIR"; } || - { - echo "Error: Virtual environment activation failed!" >&2 - return 1 - } + # shellcheck disable=SC1091 + { . "$VENV_DIR/bin/activate" && echo "Virtual environment activated: $VENV_DIR"; } || + { + echo "Error: Virtual environment activation failed!" >&2 + return 1 + } fi From 8f3cab625aa3b3ab7feff895b2401989724a7fd7 Mon Sep 17 00:00:00 2001 From: Michael I Chen Date: Wed, 26 Nov 2025 05:56:56 -0500 Subject: [PATCH 3/3] fix(large-files): make the script executable --- large-files | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) mode change 100644 => 100755 large-files diff --git a/large-files b/large-files old mode 100644 new mode 100755 index df4c1f1..0403927 --- a/large-files +++ b/large-files @@ -4,7 +4,7 @@ set -e # Function to display help message usage() { - cat </dev/null 2>&1; then - echo "Error: Not inside a Git repository." - exit 1 + echo "Error: Not inside a Git repository." + exit 1 fi echo "🔍 Finding the $NUM_FILES largest files in the repository..." # Extract large files from Git history git rev-list --objects --all | - git cat-file --batch-check='%(objectsize:disk) %(rest)' | - sort -rh | - head -n "$NUM_FILES" | - awk '{ printf "%10s %s\n", $1, $2 }' | - numfmt --to=iec-i --suffix=B --padding=7 --field=1 + git cat-file --batch-check='%(objectsize:disk) %(rest)' | + sort -rh | + head -n "$NUM_FILES" | + awk '{ printf "%10s %s\n", $1, $2 }' | + numfmt --to=iec-i --suffix=B --padding=7 --field=1 echo "✅ Done!"