Simple Git & GitHub CLI Shell Scripts
1#!/bin/bash 2 3function grst { 4 if ! is_a_git_repo; then 5 echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !" 6 return 0 7 fi 8 9 if [ $# -eq 0 ]; then 10 git checkout -- . 11 return 0 12 fi 13 14 if [ -f "$1" ]; then 15 git reset "$1" 16 return 0 17 fi 18 19 if [ $1 = "cmt" ]; then 20 git reset --soft HEAD~1 21 return 0 22 fi 23 24 # Loop through each argument and check if it's a file 25 for arg in "$@"; do 26 if [ ! -f "$arg" ]; then 27 echo "${BOLD}${RESET_COLOR} Sorry, only restore file(s). ${LIGHT_BLUE}'$arg'${RESET_COLOR} is not a valid file." 28 exit 1 29 fi 30 done 31 32 # If all arguments are valid files, restore them 33 git restore "$@" 34} 35 36# Resolve the full path to the script's directory 37REAL_PATH="$(dirname "$(readlink -f "$0")")" 38PARENT_DIR="$(dirname "$REAL_PATH")" 39CATEGORY="git.scripts" 40 41HELPS_DIR="$PARENT_DIR/helps/$CATEGORY" 42HELP_FILE="$(basename "$0" .sh)_help.sh" 43 44UTILS_DIR="$PARENT_DIR/utils" 45 46# Import necessary variables and functions 47source "$UTILS_DIR/check_git.sh" 48source "$UTILS_DIR/setup_git.sh" 49source "$UTILS_DIR/check_sudo.sh" 50source "$UTILS_DIR/colors.sh" 51source "$UTILS_DIR/usage.sh" 52 53# Import help file 54source "$HELPS_DIR/$HELP_FILE" 55 56# Usage function to display help 57function usage { 58 show_help "Usage" "${grst_arguments[@]}" 59 show_help "Description" "${grst_descriptions[@]}" 60 show_help "Options" "${grst_options[@]}" 61 show_extra "${grst_extras[@]}" 62 exit 0 63} 64 65# Check if --help is the first argument 66[ "$1" = "--help" ] && usage 67 68# prompt for sudo 69# password if required 70allow_sudo 71 72# Setting up git 73setup_git 74 75# Call grst function 76grst "$@"