Simple Git & GitHub CLI Shell Scripts
1#!/bin/bash
2
3function gad {
4 if ! is_a_git_repo; then
5 echo "${BOLD} This won't work, you are not in a git repo!${RESET}"
6 return 0
7 fi
8
9 if [ $# -eq 0 ]; then
10 # If no arguments, add all changes and commit (opens editor for commit message)
11 git add --all && git commit
12 return 0
13 fi
14
15 if [ $# -lt 1 ]; then
16 # File is specified but no commit message
17 echo "${BOLD}${RED}Error: no commit message!${RESET}"
18 return 0
19 fi
20
21 if [ -f "$1" ]; then
22 # Add the file and commit with message from arguments 2 onwards
23 git add "$1" && git commit "$1" -m "${*:2}"
24 return 0
25 fi
26
27 # Add all changes and commit with the provided message
28 git add --all && git commit -m "$*"
29}
30
31# Resolve the full path to the script's directory
32REAL_PATH="$(dirname "$(readlink -f "$0")")"
33PARENT_DIR="$(dirname "$REAL_PATH")"
34CATEGORY="git.scripts"
35
36HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
37HELP_FILE="$(basename "$0" .sh)_help.sh"
38
39UTILS_DIR="$PARENT_DIR/utils"
40
41# Import necessary variables and functions
42source "$UTILS_DIR/check_git.sh"
43source "$UTILS_DIR/setup_git.sh"
44source "$UTILS_DIR/check_sudo.sh"
45source "$UTILS_DIR/colors.sh"
46source "$UTILS_DIR/usage.sh"
47
48# Import help file
49source "$HELPS_DIR/$HELP_FILE"
50
51# Usage function to display help
52function usage {
53 show_help "Usage" "${gad_arguments[@]}"
54 show_help "Description" "${gad_descriptions[@]}"
55 show_help "Options" "${gad_options[@]}"
56 show_extra "${gad_extras[@]}"
57 exit 0
58}
59
60# Check if --help is the first argument
61[ "$1" = "--help" ] && usage
62
63# prompt for sudo
64# password if required
65allow_sudo
66
67# Setting up git
68setup_git
69
70# Call gad function
71gad "$@"