Simple Git & GitHub CLI Shell Scripts
1#!/bin/bash 2 3function gpl { 4 if ! is_a_git_repo; then 5 echo "${BOLD} This won't work, you are not in a git repo !" 6 return 0 7 fi 8 9 # check if it has a remote to push 10 if ! has_remote; then 11 repo_name=$(basename "$(git rev-parse --show-toplevel)") 12 echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}has ${RED}no remote" 13 return 0 14 fi 15 16 repo_url=$(git config --get remote.origin.url) 17 repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')" 18 current_branch=$(git branch | awk '/\*/ {print $2}') 19 is_remote_branch=$(git branch -r | grep "origin/$current_branch") 20 21 # check if the current branch has remote 22 if [ -z "$is_remote_branch" ]; then 23 echo "${BOLD} The remote repo ${LIGHT_BLUE}$repo_name" \ 24 "${RESET_COLOR}has no branch named ${GREEN}$current_branch ${RESET_COLOR}!" 25 return 0 26 fi 27 28 # Pull changes from remote branch 29 git pull origin $current_branch 30} 31 32# Resolve the full path to the script's directory 33REAL_PATH="$(dirname "$(readlink -f "$0")")" 34PARENT_DIR="$(dirname "$REAL_PATH")" 35CATEGORY="git.scripts" 36 37HELPS_DIR="$PARENT_DIR/helps/$CATEGORY" 38HELP_FILE="$(basename "$0" .sh)_help.sh" 39 40UTILS_DIR="$PARENT_DIR/utils" 41 42# Import necessary variables and functions 43source "$UTILS_DIR/check_connection.sh" 44source "$UTILS_DIR/check_remote.sh" 45source "$UTILS_DIR/check_git.sh" 46source "$UTILS_DIR/setup_git.sh" 47source "$UTILS_DIR/check_sudo.sh" 48source "$UTILS_DIR/colors.sh" 49source "$UTILS_DIR/usage.sh" 50 51# Import help file 52source "$HELPS_DIR/$HELP_FILE" 53 54# Usage function to display help 55function usage { 56 show_help "Usage" "${gpl_arguments[@]}" 57 show_help "Description" "${gpl_descriptions[@]}" 58 show_help "Options" "${gpl_options[@]}" 59 show_extra "${gpl_extras[@]}" 60 exit 0 61} 62 63# Check if --help is the first argument 64[ "$1" = "--help" ] && usage 65 66# prompt for sudo 67# password if required 68allow_sudo 69 70# Setting up git 71setup_git 72 73# Check for internet connectivity to GitHub 74check_connection 75 76# Call gpl function 77gpl