Simple Git & GitHub CLI Shell Scripts
1#!/bin/bash 2 3function gnm { 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 echo "${BOLD}${RESET_COLOR} Please pass the new name of '$current_branch' branch as argument " 11 return 0 12 fi 13 14 current_branch=$(git branch | awk '/\*/ {print $2}') 15 16 if [ $# -eq 1 ]; then 17 git branch -M $current_branch "$1" 18 return 0 19 fi 20 21 echo "${BOLD}${RESET_COLOR} Usage : gnm new_name_of_the_branch" 22} 23 24# Resolve the full path to the script's directory 25REAL_PATH="$(dirname "$(readlink -f "$0")")" 26PARENT_DIR="$(dirname "$REAL_PATH")" 27CATEGORY="git.scripts" 28 29HELPS_DIR="$PARENT_DIR/helps/$CATEGORY" 30HELP_FILE="$(basename "$0" .sh)_help.sh" 31 32UTILS_DIR="$PARENT_DIR/utils" 33 34# Import necessary variables and functions 35source "$UTILS_DIR/check_git.sh" 36source "$UTILS_DIR/setup_git.sh" 37source "$UTILS_DIR/check_sudo.sh" 38source "$UTILS_DIR/colors.sh" 39source "$UTILS_DIR/usage.sh" 40 41# Import help file 42source "$HELPS_DIR/$HELP_FILE" 43 44# Usage function to display help 45function usage { 46 show_help "Usage" "${gnm_arguments[@]}" 47 show_help "Description" "${gnm_descriptions[@]}" 48 show_help "Options" "${gnm_options[@]}" 49 show_help "Examples" "${gnm_extras[@]}" 50 exit 0 51} 52 53# Check if --help is the first argument 54[ "$1" = "--help" ] && usage 55 56# prompt for sudo 57# password if required 58allow_sudo 59 60# Setting up git 61setup_git 62 63# Call gnm function 64gnm "$@"