Simple Git & GitHub CLI Shell Scripts
1#!/bin/bash
2
3function gpsh {
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 # Get the repo name
10 repo_name=$(basename "$(git rev-parse --show-toplevel)")
11
12 # check if it has a remote to push
13 if ! has_remote; then
14 echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}has ${RED}no remote"
15 return 0
16 fi
17
18 current_branch=$(git branch | awk '/\*/ {print $2}')
19
20 # Push changes to remote branch
21 git push origin $current_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_connection.sh"
36source "$UTILS_DIR/check_remote.sh"
37source "$UTILS_DIR/check_git.sh"
38source "$UTILS_DIR/setup_git.sh"
39source "$UTILS_DIR/check_sudo.sh"
40source "$UTILS_DIR/colors.sh"
41source "$UTILS_DIR/usage.sh"
42
43# Import help file
44source "$HELPS_DIR/$HELP_FILE"
45
46# Usage function to display help
47function usage {
48 show_help "Usage" "${gpsh_arguments[@]}"
49 show_help "Description" "${gpsh_descriptions[@]}"
50 show_help "Options" "${gpsh_options[@]}"
51 show_help "${gpsh_extras[@]}"
52 exit 0
53}
54
55# Check if --help is the first argument
56[ "$1" = "--help" ] && usage
57
58# prompt for sudo
59# password if required
60allow_sudo
61
62# Setting up git
63setup_git
64
65# Check for internet connectivity to GitHub
66check_connection
67
68# Call gpsh function
69gpsh