···11+#!/bin/bash
22+33+function gbd {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ current_branch=$(git branch | awk '/\*/ {print $2}')
1010+ default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
1111+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
1212+1313+ if [ -z "$default_branch" ]; then
1414+ default_branch=$(git config --get init.defaultBranch)
1515+ fi
1616+1717+ if [ $# -eq 1 ]; then
1818+ if [ "$1" = "$default_branch" ]; then
1919+ echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
2020+ return 0
2121+ fi
2222+2323+ if ! git show-ref --verify --quiet "refs/heads/$1" &>/dev/null; then
2424+ echo "${BOLD} Fatal ! Branch ${GREEN}$1 ${RESET_COLOR}doesn't exist ${RESET}"
2525+ return 0
2626+ fi
2727+2828+ # this to check if we want to delete the remote branch too
2929+ check_delete_remote_branch() {
3030+ if [ "$current_branch" = "$default_branch" ]; then
3131+ echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
3232+ return 0
3333+ fi
3434+3535+ printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
3636+ read delete_remote_branch
3737+ echo ${RESET}
3838+3939+ if [ "$delete_remote_branch" = "y" ]; then
4040+ git push origin --delete "$current_branch"
4141+ elif [ "$delete_remote_branch" = "n" ]; then
4242+ return 0
4343+ else
4444+ check_delete_remote_branch
4545+ fi
4646+ }
4747+4848+ check_delete_branch() {
4949+ branch_name="$1"
5050+5151+ printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$branch_name"${RESET_COLOR} ? (y/n) ${RESET}"
5252+ read delete_branch
5353+5454+ if [ "$delete_branch" = "y" ]; then
5555+ if [ "$current_branch" != "$default_branch" ]; then
5656+ git checkout $default_branch >/dev/null 2>&1
5757+ fi
5858+5959+ if has_remote; then
6060+ repo_url=$(git config --get remote.origin.url)
6161+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
6262+6363+ # check if we are not the owner of the repo
6464+ if [ "$repo_owner" == "$current_user" ]; then
6565+ is_remote_branch=$(git branch -r | grep "origin/$1")
6666+ if [ -n "$is_remote_branch" ]; then
6767+ # prompt for sudo
6868+ # password if required
6969+ allow_sudo
7070+7171+ # Check for internet connectivity to GitHub
7272+ if $SUDO ping -c 1 github.com &>/dev/null; then
7373+ check_delete_remote_branch
7474+ fi
7575+ fi
7676+ fi
7777+ fi
7878+7979+ git branch -D "$1"
8080+ elif [ "$delete_branch" = "n" ]; then
8181+ return 0
8282+ else
8383+ check_delete_branch $branch_name
8484+ fi
8585+ }
8686+8787+ check_delete_branch $1
8888+ elif [ $# -eq 0 ]; then
8989+ if [ "$current_branch" = "$default_branch" ]; then
9090+ echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
9191+ return 0
9292+ fi
9393+9494+ check_delete_branch() {
9595+ printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
9696+ read delete_branch
9797+ if [ "$delete_branch" = "y" ]; then
9898+ # TODO : Remote branch Deletion
9999+ check_delete_remote_branch() {
100100+ if [ "$current_branch" = "$default_branch" ]; then
101101+ echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
102102+ else
103103+ printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
104104+ read delete_remote_branch
105105+ echo ${RESET}
106106+ if [ "$delete_remote_branch" = "y" ]; then
107107+ git push origin --delete "$current_branch"
108108+ elif [ "$delete_remote_branch" = "n" ]; then
109109+ return 0
110110+ else
111111+ check_delete_remote_branch
112112+ fi
113113+ fi
114114+ }
115115+116116+ git checkout "$default_branch" >/dev/null 2>&1
117117+118118+ if has_remote; then
119119+ repo_url=$(git config --get remote.origin.url)
120120+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
121121+122122+ # check if we are not the owner of the repo
123123+ if [ "$repo_owner" == "$current_user" ]; then
124124+ is_remote_branch=$(git branch -r | grep "origin/$current_branch")
125125+126126+ if [ -n "$is_remote_branch" ]; then
127127+ # prompt for sudo
128128+ # password if required
129129+ allow_sudo
130130+131131+ # Check for internet connectivity to GitHub
132132+ if $SUDO ping -c 1 github.com &>/dev/null; then
133133+ check_delete_remote_branch
134134+ fi
135135+ fi
136136+ fi
137137+ fi
138138+ git branch -D "$current_branch"
139139+ elif [ "$delete_branch" = "n" ]; then
140140+ return 0
141141+ else
142142+ check_delete_branch
143143+ fi
144144+ }
145145+ check_delete_branch
146146+ else
147147+ echo "${BOLD}${RESET_COLOR} Usage : gbd branch_to_delete"
148148+ fi
149149+}
150150+151151+# Resolve the full path to the script's directory
152152+REAL_PATH="$(dirname "$(readlink -f "$0")")"
153153+PARENT_DIR="$(dirname "$REAL_PATH")"
154154+CATEGORY="gh.scripts"
155155+156156+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
157157+HELP_FILE="$(basename "$0" .sh)_help.sh"
158158+159159+UTILS_DIR="$PARENT_DIR/utils"
160160+161161+# Import necessary variables and functions
162162+source "$UTILS_DIR/check_connection.sh"
163163+source "$UTILS_DIR/check_remote.sh"
164164+source "$UTILS_DIR/check_git.sh"
165165+source "$UTILS_DIR/setup_git.sh"
166166+source "$UTILS_DIR/check_sudo.sh"
167167+source "$UTILS_DIR/colors.sh"
168168+source "$UTILS_DIR/usage.sh"
169169+170170+# Import help file
171171+source "$HELPS_DIR/$HELP_FILE"
172172+173173+# Usage function to display help
174174+function usage {
175175+ show_help "Usage" "${gbd_arguments[@]}"
176176+ show_help "Description" "${gbd_descriptions[@]}"
177177+ show_help "Options" "${gbd_options[@]}"
178178+ show_extra "${gbd_extras[@]}"
179179+ exit 0
180180+}
181181+182182+# Check if --help is the first argument
183183+[ "$1" = "--help" ] && usage
184184+185185+# prompt for sudo
186186+# password if required
187187+allow_sudo
188188+189189+# Setting up git
190190+setup_git
191191+192192+# Check for internet connectivity to GitHub
193193+check_connection
194194+195195+# Call gbd function
196196+gbd "$@"
+177
gh.scripts/gck.sh
···11+#!/bin/bash
22+33+# WARNING : 03-30-2025 02:18
44+# Specify the base branch
55+# when trying to create feature
66+# branches with the following commands
77+# git switch -c new-branch old-branch
88+# git push -u origin new-branch
99+1010+function gck {
1111+ if ! is_a_git_repo; then
1212+ echo "${BOLD} This won't work, you are not in a git repo !"
1313+ return 0
1414+ fi
1515+1616+ current_branch=$(git branch | awk '/\*/ {print $2}')
1717+1818+ if has_remote; then
1919+ default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
2020+ repo_url=$(git config --get remote.origin.url)
2121+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2222+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
2323+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2424+ else
2525+ default_branch=$(git config --get init.defaultBranch)
2626+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
2727+ fi
2828+2929+ if [ -z "$default_branch" ]; then
3030+ default_branch=$(git config --get init.defaultBranch)
3131+ fi
3232+3333+ if [ $# -eq 0 ]; then
3434+ if [ "$current_branch" != "$default_branch" ]; then
3535+ git checkout "$default_branch"
3636+ else
3737+ user="$(whoami)"
3838+ if ! is_a_git_branch "$user"; then
3939+ check_new_branch() {
4040+ printf "${BOLD}${RESET_COLOR}New branch${GREEN} "$user"${RESET_COLOR} ? (y/n) "
4141+ read branch
4242+ if [ "$branch" = "y" ]; then
4343+ git checkout -b "$user" >/dev/null 2>&1
4444+4545+ # check for remote
4646+ if has_remote && gh_installed; then
4747+ check_new_remote_branch() {
4848+ printf "${BOLD}${RESET_COLOR}Add${GREEN} "$user"${RESET_COLOR} branch to ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub ? (y/n) "
4949+ read remote_branch
5050+ if [ "$remote_branch" = "y" ]; then
5151+ git push origin "$user"
5252+ elif [ "$remote_branch" = "n" ]; then
5353+ return 0
5454+ else
5555+ check_new_remote_branch
5656+ fi
5757+ }
5858+5959+ # check if we are not the owner of the repo
6060+ if [ "$repo_owner" == "$current_user" ]; then
6161+ # Check for internet connectivity to GitHub
6262+ if $SUDO ping -c 1 github.com &>/dev/null; then
6363+ check_new_remote_branch
6464+ else
6565+ echo "${BOLD} Cannot push to remote branch, you are offline !${RESET}"
6666+ fi
6767+ fi
6868+ fi
6969+ elif [ "$branch" = "n" ]; then
7070+ return 0
7171+ else
7272+ check_new_branch
7373+ fi
7474+ }
7575+ check_new_branch
7676+ else
7777+ git checkout "$user"
7878+ fi
7979+ fi
8080+ elif [ $# -eq 1 ]; then
8181+ # check if the branch doesn't exist yet
8282+ if ! is_a_git_branch "$1" >/dev/null 2>&1; then
8383+ new_branch="$1"
8484+ check_new_branch() {
8585+ printf "${BOLD}${RESET_COLOR}New branch${GREEN} "$new_branch"${RESET_COLOR} ? (y/n) "
8686+ read branch
8787+ if [ "$branch" = "y" ]; then
8888+ git checkout -b "$new_branch" >/dev/null 2>&1
8989+9090+ # check for remote
9191+ if has_remote; then
9292+ check_new_remote_branch() {
9393+ printf "${BOLD}${RESET_COLOR}Add${GREEN} "$new_branch"${RESET_COLOR} branch to ${LIGHT_BLUE}$repo_name ${RESET_COLOR} on GitHub ? (y/n) "
9494+ read remote_branch
9595+ echo ${RESET}
9696+ if [ "$remote_branch" = "y" ]; then
9797+ git push origin "$new_branch"
9898+ elif [ "$remote_branch" = "n" ]; then
9999+ return 0
100100+ else
101101+ check_new_remote_branch
102102+ fi
103103+ }
104104+105105+ # check if we are not the owner of the repo
106106+ if [ "$repo_owner" == "$current_user" ]; then
107107+ # Check for internet connectivity to GitHub
108108+ if $SUDO ping -c 1 github.com &>/dev/null; then
109109+ check_new_remote_branch
110110+ else
111111+ echo "${BOLD} Cannot push to remote branch, you are offline !${RESET}"
112112+ fi
113113+ fi
114114+ fi
115115+ elif [ "$branch" = "n" ]; then
116116+ return 0
117117+ else
118118+ check_new_branch
119119+ fi
120120+ }
121121+ check_new_branch
122122+ else
123123+ git checkout "$1"
124124+ fi
125125+ else
126126+ echo "${BOLD} Usage : gck branch or gck (switch default branch)"
127127+ fi
128128+}
129129+130130+# Resolve the full path to the script's directory
131131+REAL_PATH="$(dirname "$(readlink -f "$0")")"
132132+PARENT_DIR="$(dirname "$REAL_PATH")"
133133+CATEGORY="gh.scripts"
134134+135135+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
136136+HELP_FILE="$(basename "$0" .sh)_help.sh"
137137+138138+UTILS_DIR="$PARENT_DIR/utils"
139139+140140+# Import necessary variables and functions
141141+source "$UTILS_DIR/check_connection.sh"
142142+source "$UTILS_DIR/check_remote.sh"
143143+source "$UTILS_DIR/check_git.sh"
144144+source "$UTILS_DIR/check_gh.sh"
145145+source "$UTILS_DIR/setup_git.sh"
146146+source "$UTILS_DIR/check_branch.sh"
147147+source "$UTILS_DIR/check_sudo.sh"
148148+source "$UTILS_DIR/colors.sh"
149149+source "$UTILS_DIR/usage.sh"
150150+151151+# Import help file
152152+source "$HELPS_DIR/$HELP_FILE"
153153+154154+# Usage function to display help
155155+function usage {
156156+ show_help "Usage" "${gck_arguments[@]}"
157157+ show_help "Description" "${gck_descriptions[@]}"
158158+ show_help "Options" "${gck_options[@]}"
159159+ show_extra "${gck_extras[@]}"
160160+ exit 0
161161+}
162162+163163+# Check if --help is the first argument
164164+[ "$1" = "--help" ] && usage
165165+166166+# prompt for sudo
167167+# password if required
168168+allow_sudo
169169+170170+# Setting up git
171171+setup_git
172172+173173+# Check for internet connectivity to GitHub
174174+check_connection
175175+176176+# Call gck function
177177+gck "$@"
+105
gh.scripts/gcln.sh
···11+#!/bin/bash
22+33+function clone_repo {
44+ # Default GitHub URL prefix
55+ GITHUB_URL="https://github.com"
66+77+ local depth=""
88+99+ while [[ $# -gt 0 ]]; do
1010+ case "$1" in
1111+ --depth | -d)
1212+ depth="$2"
1313+ shift 2
1414+ ;;
1515+ *)
1616+ # Assuming the first argument is owner/repo
1717+ repo="$1"
1818+ IFS="/" read -r repo_owner repo_name <<< "$repo"
1919+ ;;
2020+ esac
2121+ shift
2222+ done
2323+2424+ # Check if repo has not the format owner/repo
2525+ if [[ ! "$repo" =~ $clone_regex ]]; then
2626+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2727+2828+ # if it is our own repo the clone it
2929+ if is_my_github_repo "$current_user/$repo"; then
3030+ gh repo clone "$current_user/$repo"
3131+ return 0
3232+ fi
3333+3434+ # else print the help
3535+ usage
3636+ fi
3737+3838+ # Check if the owner exists on GitHub
3939+ if ! is_a_github_user "$repo_owner"; then
4040+ echo "${BOLD} Sorry, there is no user named ${GREEN}$repo_owner ${RESET_COLOR}on ${LIGHT_BLUE}GitHub !"
4141+ return 0
4242+ fi
4343+4444+ # Construct the full GitHub clone URL
4545+ url="$GITHUB_URL/$repo"
4646+4747+ # If depth is provided, use it in the git clone command
4848+ if [[ -n "$depth" ]]; then
4949+ git clone "$url" --depth="$depth"
5050+ else
5151+ git clone "$url"
5252+ fi
5353+}
5454+5555+# Resolve the full path to the script's directory
5656+REAL_PATH="$(dirname "$(readlink -f "$0")")"
5757+PARENT_DIR="$(dirname "$REAL_PATH")"
5858+CATEGORY="gh.scripts"
5959+6060+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
6161+HELP_FILE="$(basename "$0" .sh)_help.sh"
6262+6363+UTILS_DIR="$PARENT_DIR/utils"
6464+6565+# Import necessary variables and functions
6666+source "$UTILS_DIR/check_connection.sh"
6767+source "$UTILS_DIR/check_repo.sh"
6868+source "$UTILS_DIR/check_git.sh"
6969+source "$UTILS_DIR/setup_git.sh"
7070+source "$UTILS_DIR/check_sudo.sh"
7171+source "$UTILS_DIR/check_user.sh"
7272+source "$UTILS_DIR/colors.sh"
7373+source "$UTILS_DIR/usage.sh"
7474+7575+# Import help file
7676+source "$HELPS_DIR/$HELP_FILE"
7777+7878+# Usage function to display help
7979+function usage {
8080+ show_help "Usage" "${gcln_arguments[@]}"
8181+ show_help "Description" "${gcln_descriptions[@]}"
8282+ show_help "Options" "${gcln_options[@]}"
8383+ exit 0
8484+}
8585+8686+# regex to match clone repo case
8787+clone_regex='^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$'
8888+8989+# Display help on --help flag and insifficient argument
9090+if [[ "$1" == "--help" || "$#" -lt 1 ]]; then
9191+ usage
9292+fi
9393+9494+# prompt for sudo
9595+# password if required
9696+allow_sudo
9797+9898+# Setting up git
9999+setup_git
100100+101101+# Check for internet connectivity to GitHub
102102+check_connection
103103+104104+# Call the function with all arguments
105105+clone_repo "$@"
+95
gh.scripts/ghadd.sh
···11+#!/bin/bash
22+33+function ghadd {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if ! has_remote; then
1010+ echo "${BOLD} This repo has no remote on GitHub !"
1111+ return 0
1212+ fi
1313+1414+ if [ $# -eq 0 ]; then
1515+ echo "${BOLD} Specify the username of the new collaborator !"
1616+ return 0
1717+ fi
1818+1919+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2020+ repo_url=$(git config --get remote.origin.url)
2121+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
2222+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2323+2424+ # check if we are not the owner of the repo
2525+ if [ "$repo_owner" != "$current_user" ]; then
2626+ echo "${BOLD} Sorry, you are not the owner of this repo !"
2727+ return 0
2828+ fi
2929+3030+ # Loop through each collaborator username provided as an argument
3131+ for collaborator in "$@"; do
3232+ # Check if the collaborator exists on GitHub
3333+ if ! is_a_github_user "$collaborator"; then
3434+ printf "${BOLD} Cannot invite ${LIGHT_BLUE}$collaborator ${RESET_COLOR}to collaborate on ${LIGHT_BLUE}$repo_name${RESET_COLOR} "
3535+ continue
3636+ fi
3737+3838+ execute_with_loading \
3939+ "${BOLD} Inviting ${LIGHT_BLUE}$collaborator ${RESET_COLOR}to collaborate on ${LIGHT_BLUE}$repo_name${RESET_COLOR}" \
4040+ "gh api --method=PUT repos/$current_user/$repo_name/collaborators/$collaborator"
4141+ done
4242+}
4343+4444+# Resolve the full path to the script's directory
4545+REAL_PATH="$(dirname "$(readlink -f "$0")")"
4646+PARENT_DIR="$(dirname "$REAL_PATH")"
4747+CATEGORY="gh.scripts"
4848+4949+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
5050+HELP_FILE="$(basename "$0" .sh)_help.sh"
5151+5252+UTILS_DIR="$PARENT_DIR/utils"
5353+5454+# Import necessary variables and functions
5555+source "$UTILS_DIR/check_connection.sh"
5656+source "$UTILS_DIR/check_git.sh"
5757+source "$UTILS_DIR/check_gh.sh"
5858+source "$UTILS_DIR/setup_git.sh"
5959+source "$UTILS_DIR/check_remote.sh"
6060+source "$UTILS_DIR/check_sudo.sh"
6161+source "$UTILS_DIR/check_user.sh"
6262+source "$UTILS_DIR/colors.sh"
6363+source "$UTILS_DIR/loading.sh"
6464+source "$UTILS_DIR/usage.sh"
6565+6666+# Import help file
6767+source "$HELPS_DIR/$HELP_FILE"
6868+6969+# Usage function to display help
7070+function usage {
7171+ show_help "Usage" "${ghadd_arguments[@]}"
7272+ show_help "Description" "${ghadd_descriptions[@]}"
7373+ show_help "Options" "${ghadd_options[@]}"
7474+ show_extra "${ghadd_extras[@]}"
7575+ exit 0
7676+}
7777+7878+# Check if --help is the first argument
7979+[ "$1" = "--help" ] && usage
8080+8181+# prompt for sudo
8282+# password if required
8383+allow_sudo
8484+8585+# Setting up git
8686+setup_git
8787+8888+# Check gh
8989+check_gh
9090+9191+# Check for internet connectivity to GitHub
9292+check_connection
9393+9494+# Call ghadd function
9595+ghadd "$@"
+178
gh.scripts/ghc.sh
···11+#!/bin/bash
22+33+function ghc {
44+ # Get the repo name and visibility
55+ if [ $# -eq 0 ]; then
66+ repo="$(basename "$PWD")"
77+ repo_visibility="public"
88+ elif [ $# -eq 1 ]; then
99+ if [ "$1" = "private" ]; then
1010+ repo="$(basename "$PWD")"
1111+ repo_visibility="private"
1212+ else
1313+ repo="$1"
1414+ repo_visibility="public"
1515+ fi
1616+ elif [ $# -eq 2 ]; then
1717+ repo="$1"
1818+ repo_visibility="$2"
1919+ else
2020+ echo "${BOLD}${RED}Error: Too many arguments.${RESET}"
2121+ usage
2222+ fi
2323+2424+ # Clean the repo name
2525+ repo_name=$(clean_repo "$repo")
2626+2727+ if is_a_git_repo; then
2828+ if has_remote; then
2929+ printf "${BOLD} This repo already has a remote on GitHub!${RESET}\n"
3030+ return 0
3131+ fi
3232+3333+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
3434+ current_protocol=$(grep 'git_protocol:' ~/.config/gh/hosts.yml | awk '{print $2}')
3535+ origin_base_url=$(
3636+ [[ "$current_protocol" == "ssh" ]] &&
3737+ echo "git@github.com:" ||
3838+ echo "https://github.com/"
3939+ )
4040+4141+ check_set_repo() {
4242+ printf "${BOLD}${RESET_COLOR} Create ${GREEN}$repo_visibility ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
4343+ read set_repo
4444+ if [ "$set_repo" = "y" ]; then
4545+ # Create the repo & set it as remote of the local one
4646+ printf "${BOLD} New repository ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub ... ${RESET}"
4747+ gh repo create "$repo_name" --"$repo_visibility" &>/dev/null
4848+ git remote add origin "$origin_base_url$current_user/$repo_name.git"
4949+ printf "${BOLD}${GREEN} ${RESET}\n"
5050+5151+ check_push() {
5252+ printf "${BOLD}${RESET_COLOR} Push local commits to ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
5353+ read check_push_commit
5454+5555+ if [ "$check_push_commit" = "y" ]; then
5656+ current_branch=$(git branch | awk '/\*/ {print $2}')
5757+ git push origin "$current_branch"
5858+ elif [ "$check_push_commit" = "n" ]; then
5959+ return 0
6060+ else
6161+ check_push
6262+ fi
6363+ }
6464+6565+ current_branch=$(git branch | awk '/\*/ {print $2}')
6666+6767+ if git rev-list --count "$current_branch" 2>/dev/null | grep -q '^[1-9]'; then
6868+ check_push
6969+ fi
7070+ elif [ "$set_repo" = "n" ]; then
7171+ return 0
7272+ else
7373+ check_set_repo
7474+ fi
7575+ }
7676+ check_set_repo
7777+ else
7878+ # Check for internet connectivity to GitHub
7979+ if ! connected; then
8080+ echo "${BOLD} Sorry, you are offline !${RESET}"
8181+ check_local() {
8282+ printf "${BOLD}${RESET_COLOR} Create ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
8383+ read create_local
8484+8585+ if [ "$create_local" = "y" ]; then
8686+ git init &>/dev/null
8787+ elif [ "$create_local" = "n" ]; then
8888+ return 0
8989+ else
9090+ check_local
9191+ fi
9292+ }
9393+ check_local
9494+ else
9595+ check_create_repo() {
9696+ printf "${BOLD}${RESET_COLOR} Create ${GREEN}$repo_visibility ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
9797+ read create_repo
9898+ if [ "$create_repo" = "y" ]; then
9999+ # Create the repo & clone it locally
100100+ printf "${BOLD} New repository ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub ... ${RESET}"
101101+ gh repo create "$repo_name" --"$repo_visibility" -c &>/dev/null
102102+ mv "$repo_name/.git" . && rm -rf "$repo_name"
103103+ printf "${BOLD}${GREEN} ${RESET}\n"
104104+ elif [ "$create_repo" = "n" ]; then
105105+ check_local() {
106106+ printf "${BOLD}${RESET_COLOR} Create ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
107107+ read create_local
108108+109109+ if [ "$create_local" = "y" ]; then
110110+ git init &>/dev/null
111111+ elif [ "$create_local" = "n" ]; then
112112+ return 0
113113+ else
114114+ check_local
115115+ fi
116116+ }
117117+ check_local
118118+ else
119119+ check_create_repo
120120+ fi
121121+ }
122122+ check_create_repo
123123+ fi
124124+ fi
125125+}
126126+127127+# Resolve the full path to the script's directory
128128+REAL_PATH="$(dirname "$(readlink -f "$0")")"
129129+PARENT_DIR="$(dirname "$REAL_PATH")"
130130+CATEGORY="gh.scripts"
131131+132132+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
133133+HELP_FILE="$(basename "$0" .sh)_help.sh"
134134+135135+UTILS_DIR="$PARENT_DIR/utils"
136136+137137+# Import necessary variables and functions
138138+source "$UTILS_DIR/check_connection.sh"
139139+source "$UTILS_DIR/check_git.sh"
140140+source "$UTILS_DIR/check_gh.sh"
141141+source "$UTILS_DIR/setup_git.sh"
142142+source "$UTILS_DIR/check_remote.sh"
143143+source "$UTILS_DIR/check_sudo.sh"
144144+source "$UTILS_DIR/check_user.sh"
145145+source "$UTILS_DIR/clean_repo.sh"
146146+source "$UTILS_DIR/colors.sh"
147147+source "$UTILS_DIR/usage.sh"
148148+149149+# Import help file
150150+source "$HELPS_DIR/$HELP_FILE"
151151+152152+# Usage function to display help
153153+function usage {
154154+ show_help "Usage" "${ghc_arguments[@]}"
155155+ show_help "Description" "${ghc_descriptions[@]}"
156156+ show_help "Options" "${ghc_options[@]}"
157157+ show_extra "${ghc_extras[@]}"
158158+ exit 0
159159+}
160160+161161+# Check if --help is the first argument
162162+[ "$1" = "--help" ] && usage
163163+164164+# prompt for sudo
165165+# password if required
166166+allow_sudo
167167+168168+# Setting up git
169169+setup_git
170170+171171+# Check gh
172172+check_gh
173173+174174+# Check for internet connectivity to GitHub
175175+check_connection
176176+177177+# Call ghc function
178178+ghc "$@"
+112
gh.scripts/ghcls.sh
···11+#!/bin/bash
22+33+function ghcls {
44+ # Check for git local repo
55+ if ! is_a_git_repo; then
66+ echo "${BOLD} This won't work, you are not in a git repo !"
77+ return 0
88+ fi
99+1010+ # Check for remote repo
1111+ if ! has_remote; then
1212+ echo "${BOLD} This repo has no remote on GitHub !"
1313+ return 0
1414+ fi
1515+1616+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
1717+ repo_url=$(git config --get remote.origin.url)
1818+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
1919+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2020+2121+ # check if we are not the owner of the repo
2222+ if [ "$repo_owner" != "$current_user" ]; then
2323+ echo "${BOLD} Sorry, you are not the owner of this repo !"
2424+ return 0
2525+ fi
2626+2727+ printf "${BOLD} ${LIGHT_BLUE}Collaborators ${RESET_COLOR}for the ${LIGHT_BLUE}$repo_name ${RESET_COLOR}repository "
2828+2929+ # List collaborators using gh api
3030+ collaborators=$(gh api "repos/$current_user/$repo_name/collaborators" --jq '.[].login')
3131+ invitations=$(gh api "repos/$current_user/$repo_name/invitations" --jq '.[].invitee.login')
3232+3333+ collaborators_count=$(echo "$collaborators" | wc -l)
3434+ invitations_count=$(echo "$invitations" | wc -l)
3535+ collaborators_num=$((collaborators_count + invitations_count))
3636+ echo "${RESET_COLOR}${BOLD}($collaborators_count)"
3737+3838+ # Check if we get any collaborators
3939+ if [ -z "$collaborators" ]; then
4040+ echo "No collaborators found."
4141+ return 0
4242+ fi
4343+4444+ # Iterate through each collaborator
4545+ echo "$collaborators" | while IFS= read -r collaborator; do
4646+ if [ "$collaborator" = "$current_user" ]; then
4747+ echo " ● $collaborator (owner)"
4848+ else
4949+ echo " ● $collaborator"
5050+ fi
5151+ done
5252+5353+ # Check if there are pending invitations
5454+ if [ -n "$invitations" ]; then
5555+ # Print pending invitations
5656+ echo "$invitations" | while IFS= read -r invitee; do
5757+ echo " ● $invitee (invitation pending)"
5858+ done
5959+ fi
6060+}
6161+6262+# Resolve the full path to the script's directory
6363+REAL_PATH="$(dirname "$(readlink -f "$0")")"
6464+PARENT_DIR="$(dirname "$REAL_PATH")"
6565+CATEGORY="gh.scripts"
6666+6767+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
6868+HELP_FILE="$(basename "$0" .sh)_help.sh"
6969+7070+UTILS_DIR="$PARENT_DIR/utils"
7171+7272+# Import necessary variables and functions
7373+source "$UTILS_DIR/check_connection.sh"
7474+source "$UTILS_DIR/check_git.sh"
7575+source "$UTILS_DIR/check_gh.sh"
7676+source "$UTILS_DIR/setup_git.sh"
7777+source "$UTILS_DIR/check_remote.sh"
7878+source "$UTILS_DIR/check_sudo.sh"
7979+source "$UTILS_DIR/check_user.sh"
8080+source "$UTILS_DIR/colors.sh"
8181+source "$UTILS_DIR/usage.sh"
8282+8383+# Import help file
8484+source "$HELPS_DIR/$HELP_FILE"
8585+8686+# Usage function to display help
8787+function usage {
8888+ show_help "Usage" "${ghcls_arguments[@]}"
8989+ show_help "Description" "${ghcls_descriptions[@]}"
9090+ show_help "Options" "${ghcls_options[@]}"
9191+ show_extra "${ghcls_extras[@]}"
9292+ exit 0
9393+}
9494+9595+# Check if --help is the first argument
9696+[ "$1" = "--help" ] && usage
9797+9898+# prompt for sudo
9999+# password if required
100100+allow_sudo
101101+102102+# Setting up git
103103+setup_git
104104+105105+# Check gh
106106+check_gh
107107+108108+# Check for internet connectivity to GitHub
109109+check_connection
110110+111111+# Call ghcls function
112112+ghcls
+153
gh.scripts/ghd.sh
···11+#!/bin/bash
22+33+function ghd {
44+ if [ $# -eq 1 ]; then
55+ if ! connected; then
66+ echo "${BOLD} Sorry, you are offline !${RESET}"
77+ return 0
88+ fi
99+1010+ if ! gh_installed; then
1111+ echo "${BOLD} gh is not installed !${RESET}"
1212+ return 0
1313+ fi
1414+1515+ repo_name="$1"
1616+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
1717+1818+ # Check if the repo doesn't exist
1919+ if ! load_and_delete \
2020+ "${BOLD} Checking the ${GREEN}repo${RESET_COLOR} named" \
2121+ "${LIGHT_BLUE}$current_user/$repo_name ${RESET_COLOR}on GitHub" \
2222+ "is_my_github_repo $current_user/$repo_name"; then
2323+2424+ echo "${BOLD} Sorry, there is ${GREEN}no repo ${RESET_COLOR}such as" \
2525+ "${LIGHT_BLUE}$current_user/$repo_name ${RESET_COLOR}on GitHub ${RESET}"
2626+ return 0
2727+ fi
2828+2929+ isPrivate=$(gh repo view "$repo_name" --json isPrivate --jq '.isPrivate')
3030+ repo_visibility=$([ "$isPrivate" = "true" ] && echo "private" || echo "public")
3131+3232+ delete_repo "$repo_name"
3333+ else
3434+ if ! is_a_git_repo; then
3535+ echo "${BOLD} This won't work, you are not in a git repo!${RESET}"
3636+ return 0
3737+ fi
3838+3939+ if has_remote; then
4040+ if connected; then
4141+ if ! gh_installed; then
4242+ echo "${BOLD} gh is not installed !${RESET}"
4343+ return 0
4444+ fi
4545+4646+ repo_url=$(git config --get remote.origin.url)
4747+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
4848+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
4949+5050+ if [ "$repo_owner" != "$current_user" ]; then
5151+ echo "${BOLD} Sorry, you are not the owner of this repo!${RESET}"
5252+ else
5353+ repo_name=$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')
5454+ isPrivate=$(gh repo view "$repo_name" --json isPrivate --jq '.isPrivate')
5555+ repo_visibility=$([ "$isPrivate" = "true" ] && echo "private" || echo "public")
5656+5757+ delete_repo "$repo_name"
5858+ git remote remove origin
5959+ echo
6060+ delete_local_repo "$repo_name"
6161+ fi
6262+ else
6363+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
6464+ delete_local_repo "$repo_name"
6565+ fi
6666+ else
6767+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
6868+ delete_local_repo "$repo_name"
6969+ fi
7070+ fi
7171+}
7272+7373+# Resolve the full path to the script's directory
7474+REAL_PATH="$(dirname "$(readlink -f "$0")")"
7575+PARENT_DIR="$(dirname "$REAL_PATH")"
7676+CATEGORY="gh.scripts"
7777+7878+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
7979+HELP_FILE="$(basename "$0" .sh)_help.sh"
8080+8181+UTILS_DIR="$PARENT_DIR/utils"
8282+8383+# Import necessary variables and functions
8484+source "$UTILS_DIR/check_connection.sh"
8585+source "$UTILS_DIR/check_git.sh"
8686+source "$UTILS_DIR/check_gh.sh"
8787+source "$UTILS_DIR/check_repo.sh"
8888+source "$UTILS_DIR/setup_git.sh"
8989+source "$UTILS_DIR/check_remote.sh"
9090+source "$UTILS_DIR/check_sudo.sh"
9191+source "$UTILS_DIR/check_user.sh"
9292+source "$UTILS_DIR/clean_repo.sh"
9393+source "$UTILS_DIR/colors.sh"
9494+source "$UTILS_DIR/loading.sh"
9595+source "$UTILS_DIR/usage.sh"
9696+9797+# Import help file
9898+source "$HELPS_DIR/$HELP_FILE"
9999+100100+# Usage function to display help
101101+function usage {
102102+ show_help "Usage" "${ghd_arguments[@]}"
103103+ show_help "Description" "${ghd_descriptions[@]}"
104104+ show_help "Options" "${ghd_options[@]}"
105105+ exit 0
106106+}
107107+108108+# Check if --help is the first argument
109109+[ "$1" = "--help" ] && usage
110110+111111+# prompt for sudo
112112+# password if required
113113+allow_sudo
114114+115115+# Setting up git
116116+setup_git
117117+118118+# Function to delete local repo
119119+function delete_local_repo {
120120+ printf "${BOLD}${RESET} Delete ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$1 ${RESET}? (y/n) ${RESET}"
121121+ read delete_local_repo
122122+123123+ if [ "$delete_local_repo" = "y" ]; then
124124+ local repo_source=$(git rev-parse --show-toplevel)
125125+126126+ execute_with_loading \
127127+ "${BOLD} Deleting ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$1 ${RESET}" \
128128+ "rm -rf "$repo_source/.git""
129129+ elif [ "$delete_local_repo" = "n" ]; then
130130+ return 0
131131+ else
132132+ delete_local_repo "$1"
133133+ fi
134134+}
135135+136136+# Function to delete GitHub repo
137137+function delete_repo {
138138+ printf "${BOLD} Delete ${GREEN}$repo_visibility ${RESET_COLOR}repo ${LIGHT_BLUE}$1 ${RESET_COLOR}? (y/n) ${RESET}"
139139+ read delete_repo
140140+141141+ if [ "$delete_repo" = "y" ]; then
142142+ execute_with_loading \
143143+ "${BOLD} Deleting repository ${LIGHT_BLUE}$1 ${RESET_COLOR}on GitHub" \
144144+ "gh repo delete "$1" --yes"
145145+ elif [ "$delete_repo" = "n" ]; then
146146+ return 0
147147+ else
148148+ delete_repo "$1"
149149+ fi
150150+}
151151+152152+# Call ghd function
153153+ghd "$@"
+107
gh.scripts/ghdel.sh
···11+#!/bin/bash
22+33+function ghdel {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if ! has_remote; then
1010+ echo "${BOLD} This repo has no remote on Github !"
1111+ return 0
1212+ fi
1313+1414+ if [ $# -eq 0 ]; then
1515+ echo "${BOLD} Specify the username of the collaborator to remove !"
1616+ return 0
1717+ fi
1818+1919+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2020+ repo_url=$(git config --get remote.origin.url)
2121+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
2222+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2323+2424+ # check if we are not the owner of the repo
2525+ if [ "$repo_owner" != "$current_user" ]; then
2626+ echo "${BOLD} Sorry, you are not the owner of this repo !"
2727+ return 0
2828+ fi
2929+3030+ # Retrieve the list of collaborators
3131+ collaborators=$(gh api "repos/$current_user/$repo_name/collaborators" --jq '.[].login')
3232+ invitations=$(gh api "repos/$current_user/$repo_name/invitations" --jq '.[].invitee.login')
3333+3434+ # Loop through each collaborator username provided as an argument
3535+ for collaborator in "$@"; do
3636+ # Check if the collaborator exists in the list of collaborators
3737+ if echo "$collaborators" | grep -q "$collaborator" ||
3838+ echo "$invitations" | grep -q "$collaborator"; then
3939+ printf "${BOLD} Removing ${LIGHT_BLUE}$collaborator ${RESET_COLOR}from ${LIGHT_BLUE}$repo_name${RESET_COLOR} "
4040+ # Check for pending invitations
4141+ invitation_id=$(gh api "repos/$current_user/$repo_name/invitations" --jq ".[] | select(.invitee.login==\"$collaborator\") | .id")
4242+4343+ if [ -n "$invitation_id" ]; then
4444+ # Delete the pending invitation
4545+ gh api --method=DELETE "repos/$current_user/$repo_name/invitations/$invitation_id" >/dev/null 2>&1
4646+ printf " ${BOLD}(invitation deleted) "
4747+ fi
4848+4949+ # Remove collaborator using gh api
5050+ gh api --method=DELETE "repos/$current_user/$repo_name/collaborators/$collaborator" >/dev/null 2>&1
5151+ echo "${BOLD}${GREEN} ${RESET_COLOR}"
5252+ else
5353+ echo "${BOLD}${LIGHT_BLUE}$collaborator ${RESET_COLOR}is not a ${LIGHT_BLUE}collaborator ${RED}✘ ${RESET_COLOR}"
5454+ fi
5555+ done
5656+}
5757+5858+# Resolve the full path to the script's directory
5959+REAL_PATH="$(dirname "$(readlink -f "$0")")"
6060+PARENT_DIR="$(dirname "$REAL_PATH")"
6161+CATEGORY="gh.scripts"
6262+6363+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
6464+HELP_FILE="$(basename "$0" .sh)_help.sh"
6565+6666+UTILS_DIR="$PARENT_DIR/utils"
6767+6868+# Import necessary variables and functions
6969+source "$UTILS_DIR/check_connection.sh"
7070+source "$UTILS_DIR/check_git.sh"
7171+source "$UTILS_DIR/check_gh.sh"
7272+source "$UTILS_DIR/setup_git.sh"
7373+source "$UTILS_DIR/check_remote.sh"
7474+source "$UTILS_DIR/check_sudo.sh"
7575+source "$UTILS_DIR/colors.sh"
7676+source "$UTILS_DIR/usage.sh"
7777+7878+# Import help file
7979+source "$HELPS_DIR/$HELP_FILE"
8080+8181+# Usage function to display help
8282+function usage {
8383+ show_help "Usage" "${ghdel_arguments[@]}"
8484+ show_help "Description" "${ghdel_descriptions[@]}"
8585+ show_help "Options" "${ghdel_options[@]}"
8686+ show_extra "${ghdel_extras[@]}"
8787+ exit 0
8888+}
8989+9090+# Check if --help is the first argument
9191+[ "$1" = "--help" ] && usage
9292+9393+# prompt for sudo
9494+# password if required
9595+allow_sudo
9696+9797+# Setting up git
9898+setup_git
9999+100100+# Check gh
101101+check_gh
102102+103103+# Check for internet connectivity to GitHub
104104+check_connection
105105+106106+# Call ghdel function
107107+ghdel "$@"
+119
gh.scripts/ghf.sh
···11+#!/bin/bash
22+33+function ghf {
44+ repo="$1"
55+ IFS="/" read -r repo_owner repo_name <<< "$repo"
66+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
77+ clone_repo="--clone"
88+99+ # regex to match clone repo case
1010+ clone_regex='^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$'
1111+1212+ # Check if repo has not the format owner/repo
1313+ if [[ ! "$repo" =~ $clone_regex ]]; then
1414+ usage
1515+ fi
1616+1717+ # Check if we have already forked it
1818+ if load_and_delete \
1919+ "${BOLD} Checking the forked ${GREEN}repo ${RESET_COLOR} named" \
2020+ "${LIGHT_BLUE}$current_user/$repo_name ${RESET_COLOR}on GitHub" \
2121+ "is_a_github_repo $current_user/$repo_name"; then
2222+ echo "${BOLD} You have already ${RED}forked ${RESET_COLOR}the repo named" \
2323+ "${GREEN}$repo_name ${RESET_COLOR}on ${LIGHT_BLUE}GitHub ${RESET}"
2424+ return 0
2525+ fi
2626+2727+ # Check if the owner exists on GitHub
2828+ if ! load_and_delete \
2929+ "${BOLD} Checking the ${GREEN}user ${RESET_COLOR}named" \
3030+ "${LIGHT_BLUE}$repo_owner ${RESET_COLOR}on GitHub" \
3131+ "is_a_github_user $repo_owner"; then
3232+ echo "${BOLD} Sorry, there is ${GREEN}no user ${RESET_COLOR}named" \
3333+ "${LIGHT_BLUE}$repo_owner ${RESET_COLOR}on GitHub ${RESET}"
3434+ return 0
3535+ fi
3636+3737+ # Check if the repo doesn't exist
3838+ if ! load_and_delete \
3939+ "${BOLD} Checking the ${GREEN}repo ${RESET_COLOR}named" \
4040+ "${LIGHT_BLUE}$repo_owner/$repo_name ${RESET_COLOR}on GitHub" \
4141+ "is_a_github_repo $repo_owner/$repo_name"; then
4242+ echo "${BOLD} Sorry, there is ${GREEN}no repo ${RESET_COLOR}such" \
4343+ "${LIGHT_BLUE}$repo_owner/$repo_name ${RESET_COLOR}on GitHub ${RESET}"
4444+ return 0
4545+ fi
4646+4747+ if load_and_delete \
4848+ "${BOLD} Checking the ${GREEN}local ${RESET_COLOR}git" \
4949+ "${LIGHT_BLUE}repo ${RESET_COLOR}" \
5050+ "is_a_git_repo"; then
5151+ printf "${BOLD}${GREEN} Local Git${RESET_COLOR} repo detected," \
5252+ "skipping fork clone for ${LIGHT_BLUE}$repo_name ${RESET}\n"
5353+ clone_repo=""
5454+ fi
5555+5656+ if execute_with_loading \
5757+ "${BOLD} Forking ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub" \
5858+ "gh repo fork $repo_owner/$repo_name"; then
5959+6060+ if [ "$clone_repo" == "--clone" ]; then
6161+ execute_with_loading \
6262+ "${BOLD} Cloning fork ${LIGHT_BLUE}$repo_name ${RESET_COLOR}locally" \
6363+ "gh repo clone $current_user/$repo_name"
6464+ fi
6565+ fi
6666+}
6767+6868+# Resolve the full path to the script's directory
6969+REAL_PATH="$(dirname "$(readlink -f "$0")")"
7070+PARENT_DIR="$(dirname "$REAL_PATH")"
7171+CATEGORY="gh.scripts"
7272+7373+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
7474+HELP_FILE="$(basename "$0" .sh)_help.sh"
7575+7676+UTILS_DIR="$PARENT_DIR/utils"
7777+7878+# Import necessary variables and functions
7979+source "$UTILS_DIR/check_connection.sh"
8080+source "$UTILS_DIR/check_git.sh"
8181+source "$UTILS_DIR/check_gh.sh"
8282+source "$UTILS_DIR/check_repo.sh"
8383+source "$UTILS_DIR/setup_git.sh"
8484+source "$UTILS_DIR/check_sudo.sh"
8585+source "$UTILS_DIR/check_user.sh"
8686+source "$UTILS_DIR/colors.sh"
8787+source "$UTILS_DIR/loading.sh"
8888+source "$UTILS_DIR/usage.sh"
8989+9090+# Import help file
9191+source "$HELPS_DIR/$HELP_FILE"
9292+9393+# Usage function to display help
9494+function usage {
9595+ show_help "Usage" "${ghf_arguments[@]}"
9696+ show_help "Description" "${ghf_descriptions[@]}"
9797+ show_help "Options" "${ghf_options[@]}"
9898+ show_help "Example" "${ghf_extras[@]}"
9999+ exit 0
100100+}
101101+102102+# Check if --help is the first argument
103103+[ "$1" = "--help" ] && usage
104104+105105+# prompt for sudo
106106+# password if required
107107+allow_sudo
108108+109109+# Setting up git
110110+setup_git
111111+112112+# Check gh
113113+check_gh
114114+115115+# Check for internet connectivity to GitHub
116116+check_connection
117117+118118+# Call the function with all arguments
119119+ghf "$@"
+91
gh.scripts/ghnm.sh
···11+#!/bin/bash
22+33+function ghnm {
44+ # Check if we are inside a git repo
55+ if ! load_and_delete \
66+ "${BOLD} Checking the ${GREEN}local ${RESET_COLOR}git" \
77+ "${LIGHT_BLUE}repo ${RESET_COLOR}" \
88+ "is_a_git_repo"; then
99+ echo "${BOLD} This won't work, you are not in a git repo !"
1010+ return 0
1111+ fi
1212+1313+ # Check if the repo has a remote
1414+ if ! load_and_delete \
1515+ "${BOLD} Checking the ${GREEN}remote ${RESET_COLOR}git" \
1616+ "${LIGHT_BLUE}repo ${RESET_COLOR}on GitHub" \
1717+ "has_remote"; then
1818+ echo "${BOLD} This repo has no remote on GitHub !"
1919+ return 0
2020+ fi
2121+2222+ # Define the new name of the repo
2323+ new_name="$1"
2424+ repo_url=$(git config --get remote.origin.url)
2525+ repo_name=$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')
2626+2727+ if [ "$new_name" == "$repo_name" ]; then
2828+ echo "${BOLD} The ${GREEN}remote ${RESET_COLOR}repo name is" \
2929+ "${LIGHT_BLUE}$repo_name ${RESET}"
3030+ return 0
3131+ fi
3232+3333+ execute_with_loading \
3434+ "${BOLD} Renaming ${GREEN}remote ${RESET_COLOR}repo" \
3535+ "${LIGHT_BLUE}$repo_name ${RESET_COLOR}to ${LIGHT_BLUE}$new_name ${RESET_COLOR}" \
3636+ "gh repo rename "$new_name" --yes"
3737+}
3838+3939+# Resolve the full path to the script's directory
4040+REAL_PATH="$(dirname "$(readlink -f "$0")")"
4141+PARENT_DIR="$(dirname "$REAL_PATH")"
4242+CATEGORY="gh.scripts"
4343+4444+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
4545+HELP_FILE="$(basename "$0" .sh)_help.sh"
4646+4747+UTILS_DIR="$PARENT_DIR/utils"
4848+4949+# Import necessary variables and functions
5050+source "$UTILS_DIR/check_connection.sh"
5151+source "$UTILS_DIR/check_git.sh"
5252+source "$UTILS_DIR/check_gh.sh"
5353+source "$UTILS_DIR/setup_git.sh"
5454+source "$UTILS_DIR/check_remote.sh"
5555+source "$UTILS_DIR/check_sudo.sh"
5656+source "$UTILS_DIR/check_user.sh"
5757+source "$UTILS_DIR/clean_repo.sh"
5858+source "$UTILS_DIR/colors.sh"
5959+source "$UTILS_DIR/loading.sh"
6060+source "$UTILS_DIR/usage.sh"
6161+6262+# Import help file
6363+source "$HELPS_DIR/$HELP_FILE"
6464+6565+# Usage function to display help
6666+function usage {
6767+ show_help "Usage" "${ghnm_arguments[@]}"
6868+ show_help "Description" "${ghnm_descriptions[@]}"
6969+ show_help "Options" "${ghnm_options[@]}"
7070+ show_help "Example" "${ghnm_extras[@]}"
7171+ exit 0
7272+}
7373+7474+# Check if --help is the first argument
7575+[ "$1" = "--help" ] && usage
7676+7777+# prompt for sudo
7878+# password if required
7979+allow_sudo
8080+8181+# Setting up git
8282+setup_git
8383+8484+# Check gh
8585+check_gh
8686+8787+# Check for internet connectivity to GitHub
8888+check_connection
8989+9090+# Call ghc function
9191+ghnm "$@"
+128
gh.scripts/ghv.sh
···11+#!/bin/bash
22+33+function ghv {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if [[ ! connected && "$1" = "owner" ]]; then
1010+ if has_remote; then
1111+ repo_url=$(git config --get remote.origin.url)
1212+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
1313+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
1414+ else
1515+ repo_owner=$(git config user.name)
1616+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
1717+ fi
1818+1919+ if has_remote; then
2020+ echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
2121+ else
2222+ echo "${BOLD} The local repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
2323+ fi
2424+2525+ return 0
2626+ fi
2727+2828+ if [ "$#" -eq 0 ] || [ "$1" = "show" ] || [ "$1" = "owner" ]; then
2929+ current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
3030+3131+ if has_remote; then
3232+ repo_url=$(git config --get remote.origin.url)
3333+ repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
3434+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
3535+ else
3636+ repo_owner=$(git config user.name)
3737+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
3838+ fi
3939+4040+ if [ "$repo_owner" != "$current_user" ] && [ "$1" != "owner" ]; then
4141+ echo "${BOLD} Sorry, you are not the owner of this repo !"
4242+ elif [ "$1" = "owner" ]; then
4343+ if has_remote; then
4444+ echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
4545+ else
4646+ echo "${BOLD} The local repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
4747+ fi
4848+ else
4949+ if has_remote; then
5050+ isPrivate=$(gh repo view "$repo_owner/$repo_name" --json isPrivate --jq '.isPrivate')
5151+5252+ if [ "$1" = "show" ]; then
5353+ visibility=$([ "$isPrivate" = "true" ] && echo "private" || echo "public")
5454+ echo "${BOLD} This repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is ${GREEN}$visibility"
5555+ else
5656+ new_visibility=$([ "$isPrivate" = "true" ] && echo "public" || echo "private")
5757+ toggle_visibility() {
5858+ printf "${BOLD}${RESET_COLOR} Make ${LIGHT_BLUE}$repo_name ${RESET_COLOR}repo ${GREEN}$new_visibility ${RESET_COLOR}? (y/n) "
5959+ read -r change_visibility
6060+ if [ "$change_visibility" = "y" ]; then
6161+ # toggle visibility
6262+ printf "${BOLD} Changing repo visibility to ${GREEN}$new_visibility ${RESET_COLOR}... "
6363+ gh repo edit "$repo_owner/$repo_name" --visibility "$new_visibility" &>/dev/null
6464+ echo "${BOLD}${GREEN} ${RESET_COLOR}"
6565+ elif [ "$change_visibility" = "n" ]; then
6666+ return 0
6767+ else
6868+ toggle_visibility
6969+ fi
7070+ }
7171+ toggle_visibility
7272+ fi
7373+ else
7474+ echo "${BOLD} The local repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
7575+ fi
7676+ fi
7777+ else
7878+ echo "${BOLD} Sorry, wrong command argument !"
7979+ fi
8080+}
8181+8282+# Resolve the full path to the script's directory
8383+REAL_PATH="$(dirname "$(readlink -f "$0")")"
8484+PARENT_DIR="$(dirname "$REAL_PATH")"
8585+CATEGORY="gh.scripts"
8686+8787+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
8888+HELP_FILE="$(basename "$0" .sh)_help.sh"
8989+9090+UTILS_DIR="$PARENT_DIR/utils"
9191+9292+# Import necessary variables and functions
9393+source "$UTILS_DIR/check_connection.sh"
9494+source "$UTILS_DIR/check_git.sh"
9595+source "$UTILS_DIR/check_gh.sh"
9696+source "$UTILS_DIR/setup_git.sh"
9797+source "$UTILS_DIR/check_remote.sh"
9898+source "$UTILS_DIR/check_sudo.sh"
9999+source "$UTILS_DIR/colors.sh"
100100+source "$UTILS_DIR/usage.sh"
101101+102102+# Import help file
103103+source "$HELPS_DIR/$HELP_FILE"
104104+105105+# Usage function to display help
106106+function usage {
107107+ show_help "Usage" "${ghv_arguments[@]}"
108108+ show_help "Description" "${ghv_descriptions[@]}"
109109+ show_help "Options" "${ghv_options[@]}"
110110+ show_extra "${ghv_extras[@]}"
111111+ exit 0
112112+}
113113+114114+# Check if --help is the first argument
115115+[ "$1" = "--help" ] && usage
116116+117117+# prompt for sudo
118118+# password if required
119119+allow_sudo
120120+121121+# Setting up git
122122+setup_git
123123+124124+# Check gh
125125+check_gh
126126+127127+# Call ghv function
128128+ghv "$@"
-196
gh_scripts/gbd.sh
···11-#!/bin/bash
22-33-function gbd {
44- if ! is_a_git_repo; then
55- echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- current_branch=$(git branch | awk '/\*/ {print $2}')
1010- default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
1111- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
1212-1313- if [ -z "$default_branch" ]; then
1414- default_branch=$(git config --get init.defaultBranch)
1515- fi
1616-1717- if [ $# -eq 1 ]; then
1818- if [ "$1" = "$default_branch" ]; then
1919- echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
2020- return 0
2121- fi
2222-2323- if ! git show-ref --verify --quiet "refs/heads/$1" &>/dev/null; then
2424- echo "${BOLD} Fatal ! Branch ${GREEN}$1 ${RESET_COLOR}doesn't exist ${RESET}"
2525- return 0
2626- fi
2727-2828- # this to check if we want to delete the remote branch too
2929- check_delete_remote_branch() {
3030- if [ "$current_branch" = "$default_branch" ]; then
3131- echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
3232- return 0
3333- fi
3434-3535- printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
3636- read delete_remote_branch
3737- echo ${RESET}
3838-3939- if [ "$delete_remote_branch" = "y" ]; then
4040- git push origin --delete "$current_branch"
4141- elif [ "$delete_remote_branch" = "n" ]; then
4242- return 0
4343- else
4444- check_delete_remote_branch
4545- fi
4646- }
4747-4848- check_delete_branch() {
4949- branch_name="$1"
5050-5151- printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$branch_name"${RESET_COLOR} ? (y/n) ${RESET}"
5252- read delete_branch
5353-5454- if [ "$delete_branch" = "y" ]; then
5555- if [ "$current_branch" != "$default_branch" ]; then
5656- git checkout $default_branch >/dev/null 2>&1
5757- fi
5858-5959- if has_remote; then
6060- repo_url=$(git config --get remote.origin.url)
6161- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
6262-6363- # check if we are not the owner of the repo
6464- if [ "$repo_owner" == "$current_user" ]; then
6565- is_remote_branch=$(git branch -r | grep "origin/$1")
6666- if [ -n "$is_remote_branch" ]; then
6767- # prompt for sudo
6868- # password if required
6969- allow_sudo
7070-7171- # Check for internet connectivity to GitHub
7272- if $SUDO ping -c 1 github.com &>/dev/null; then
7373- check_delete_remote_branch
7474- fi
7575- fi
7676- fi
7777- fi
7878-7979- git branch -D "$1"
8080- elif [ "$delete_branch" = "n" ]; then
8181- return 0
8282- else
8383- check_delete_branch $branch_name
8484- fi
8585- }
8686-8787- check_delete_branch $1
8888- elif [ $# -eq 0 ]; then
8989- if [ "$current_branch" = "$default_branch" ]; then
9090- echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
9191- return 0
9292- fi
9393-9494- check_delete_branch() {
9595- printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
9696- read delete_branch
9797- if [ "$delete_branch" = "y" ]; then
9898- # TODO : Remote branch Deletion
9999- check_delete_remote_branch() {
100100- if [ "$current_branch" = "$default_branch" ]; then
101101- echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
102102- else
103103- printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
104104- read delete_remote_branch
105105- echo ${RESET}
106106- if [ "$delete_remote_branch" = "y" ]; then
107107- git push origin --delete "$current_branch"
108108- elif [ "$delete_remote_branch" = "n" ]; then
109109- return 0
110110- else
111111- check_delete_remote_branch
112112- fi
113113- fi
114114- }
115115-116116- git checkout "$default_branch" >/dev/null 2>&1
117117-118118- if has_remote; then
119119- repo_url=$(git config --get remote.origin.url)
120120- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
121121-122122- # check if we are not the owner of the repo
123123- if [ "$repo_owner" == "$current_user" ]; then
124124- is_remote_branch=$(git branch -r | grep "origin/$current_branch")
125125-126126- if [ -n "$is_remote_branch" ]; then
127127- # prompt for sudo
128128- # password if required
129129- allow_sudo
130130-131131- # Check for internet connectivity to GitHub
132132- if $SUDO ping -c 1 github.com &>/dev/null; then
133133- check_delete_remote_branch
134134- fi
135135- fi
136136- fi
137137- fi
138138- git branch -D "$current_branch"
139139- elif [ "$delete_branch" = "n" ]; then
140140- return 0
141141- else
142142- check_delete_branch
143143- fi
144144- }
145145- check_delete_branch
146146- else
147147- echo "${BOLD}${RESET_COLOR} Usage : gbd branch_to_delete"
148148- fi
149149-}
150150-151151-# Resolve the full path to the script's directory
152152-REAL_PATH="$(dirname "$(readlink -f "$0")")"
153153-PARENT_DIR="$(dirname "$REAL_PATH")"
154154-CATEGORY="gh_scripts"
155155-156156-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
157157-HELP_FILE="$(basename "$0" .sh)_help.sh"
158158-159159-UTILS_DIR="$PARENT_DIR/utils"
160160-161161-# Import necessary variables and functions
162162-source "$UTILS_DIR/check_connection.sh"
163163-source "$UTILS_DIR/check_remote.sh"
164164-source "$UTILS_DIR/check_git.sh"
165165-source "$UTILS_DIR/setup_git.sh"
166166-source "$UTILS_DIR/check_sudo.sh"
167167-source "$UTILS_DIR/colors.sh"
168168-source "$UTILS_DIR/usage.sh"
169169-170170-# Import help file
171171-source "$HELPS_DIR/$HELP_FILE"
172172-173173-# Usage function to display help
174174-function usage {
175175- show_help "Usage" "${gbd_arguments[@]}"
176176- show_help "Description" "${gbd_descriptions[@]}"
177177- show_help "Options" "${gbd_options[@]}"
178178- show_extra "${gbd_extras[@]}"
179179- exit 0
180180-}
181181-182182-# Check if --help is the first argument
183183-[ "$1" = "--help" ] && usage
184184-185185-# prompt for sudo
186186-# password if required
187187-allow_sudo
188188-189189-# Setting up git
190190-setup_git
191191-192192-# Check for internet connectivity to GitHub
193193-check_connection
194194-195195-# Call gbd function
196196-gbd "$@"
-177
gh_scripts/gck.sh
···11-#!/bin/bash
22-33-# WARNING : 03-30-2025 02:18
44-# Specify the base branch
55-# when trying to create feature
66-# branches with the following commands
77-# git switch -c new-branch old-branch
88-# git push -u origin new-branch
99-1010-function gck {
1111- if ! is_a_git_repo; then
1212- echo "${BOLD} This won't work, you are not in a git repo !"
1313- return 0
1414- fi
1515-1616- current_branch=$(git branch | awk '/\*/ {print $2}')
1717-1818- if has_remote; then
1919- default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
2020- repo_url=$(git config --get remote.origin.url)
2121- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2222- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
2323- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2424- else
2525- default_branch=$(git config --get init.defaultBranch)
2626- repo_name=$(basename "$(git rev-parse --show-toplevel)")
2727- fi
2828-2929- if [ -z "$default_branch" ]; then
3030- default_branch=$(git config --get init.defaultBranch)
3131- fi
3232-3333- if [ $# -eq 0 ]; then
3434- if [ "$current_branch" != "$default_branch" ]; then
3535- git checkout "$default_branch"
3636- else
3737- user="$(whoami)"
3838- if ! is_a_git_branch "$user"; then
3939- check_new_branch() {
4040- printf "${BOLD}${RESET_COLOR}New branch${GREEN} "$user"${RESET_COLOR} ? (y/n) "
4141- read branch
4242- if [ "$branch" = "y" ]; then
4343- git checkout -b "$user" >/dev/null 2>&1
4444-4545- # check for remote
4646- if has_remote && gh_installed; then
4747- check_new_remote_branch() {
4848- printf "${BOLD}${RESET_COLOR}Add${GREEN} "$user"${RESET_COLOR} branch to ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub ? (y/n) "
4949- read remote_branch
5050- if [ "$remote_branch" = "y" ]; then
5151- git push origin "$user"
5252- elif [ "$remote_branch" = "n" ]; then
5353- return 0
5454- else
5555- check_new_remote_branch
5656- fi
5757- }
5858-5959- # check if we are not the owner of the repo
6060- if [ "$repo_owner" == "$current_user" ]; then
6161- # Check for internet connectivity to GitHub
6262- if $SUDO ping -c 1 github.com &>/dev/null; then
6363- check_new_remote_branch
6464- else
6565- echo "${BOLD} Cannot push to remote branch, you are offline !${RESET}"
6666- fi
6767- fi
6868- fi
6969- elif [ "$branch" = "n" ]; then
7070- return 0
7171- else
7272- check_new_branch
7373- fi
7474- }
7575- check_new_branch
7676- else
7777- git checkout "$user"
7878- fi
7979- fi
8080- elif [ $# -eq 1 ]; then
8181- # check if the branch doesn't exist yet
8282- if ! is_a_git_branch "$1" >/dev/null 2>&1; then
8383- new_branch="$1"
8484- check_new_branch() {
8585- printf "${BOLD}${RESET_COLOR}New branch${GREEN} "$new_branch"${RESET_COLOR} ? (y/n) "
8686- read branch
8787- if [ "$branch" = "y" ]; then
8888- git checkout -b "$new_branch" >/dev/null 2>&1
8989-9090- # check for remote
9191- if has_remote; then
9292- check_new_remote_branch() {
9393- printf "${BOLD}${RESET_COLOR}Add${GREEN} "$new_branch"${RESET_COLOR} branch to ${LIGHT_BLUE}$repo_name ${RESET_COLOR} on GitHub ? (y/n) "
9494- read remote_branch
9595- echo ${RESET}
9696- if [ "$remote_branch" = "y" ]; then
9797- git push origin "$new_branch"
9898- elif [ "$remote_branch" = "n" ]; then
9999- return 0
100100- else
101101- check_new_remote_branch
102102- fi
103103- }
104104-105105- # check if we are not the owner of the repo
106106- if [ "$repo_owner" == "$current_user" ]; then
107107- # Check for internet connectivity to GitHub
108108- if $SUDO ping -c 1 github.com &>/dev/null; then
109109- check_new_remote_branch
110110- else
111111- echo "${BOLD} Cannot push to remote branch, you are offline !${RESET}"
112112- fi
113113- fi
114114- fi
115115- elif [ "$branch" = "n" ]; then
116116- return 0
117117- else
118118- check_new_branch
119119- fi
120120- }
121121- check_new_branch
122122- else
123123- git checkout "$1"
124124- fi
125125- else
126126- echo "${BOLD} Usage : gck branch or gck (switch default branch)"
127127- fi
128128-}
129129-130130-# Resolve the full path to the script's directory
131131-REAL_PATH="$(dirname "$(readlink -f "$0")")"
132132-PARENT_DIR="$(dirname "$REAL_PATH")"
133133-CATEGORY="gh_scripts"
134134-135135-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
136136-HELP_FILE="$(basename "$0" .sh)_help.sh"
137137-138138-UTILS_DIR="$PARENT_DIR/utils"
139139-140140-# Import necessary variables and functions
141141-source "$UTILS_DIR/check_connection.sh"
142142-source "$UTILS_DIR/check_remote.sh"
143143-source "$UTILS_DIR/check_git.sh"
144144-source "$UTILS_DIR/check_gh.sh"
145145-source "$UTILS_DIR/setup_git.sh"
146146-source "$UTILS_DIR/check_branch.sh"
147147-source "$UTILS_DIR/check_sudo.sh"
148148-source "$UTILS_DIR/colors.sh"
149149-source "$UTILS_DIR/usage.sh"
150150-151151-# Import help file
152152-source "$HELPS_DIR/$HELP_FILE"
153153-154154-# Usage function to display help
155155-function usage {
156156- show_help "Usage" "${gck_arguments[@]}"
157157- show_help "Description" "${gck_descriptions[@]}"
158158- show_help "Options" "${gck_options[@]}"
159159- show_extra "${gck_extras[@]}"
160160- exit 0
161161-}
162162-163163-# Check if --help is the first argument
164164-[ "$1" = "--help" ] && usage
165165-166166-# prompt for sudo
167167-# password if required
168168-allow_sudo
169169-170170-# Setting up git
171171-setup_git
172172-173173-# Check for internet connectivity to GitHub
174174-check_connection
175175-176176-# Call gck function
177177-gck "$@"
-105
gh_scripts/gcln.sh
···11-#!/bin/bash
22-33-function clone_repo {
44- # Default GitHub URL prefix
55- GITHUB_URL="https://github.com"
66-77- local depth=""
88-99- while [[ $# -gt 0 ]]; do
1010- case "$1" in
1111- --depth | -d)
1212- depth="$2"
1313- shift 2
1414- ;;
1515- *)
1616- # Assuming the first argument is owner/repo
1717- repo="$1"
1818- IFS="/" read -r repo_owner repo_name <<< "$repo"
1919- ;;
2020- esac
2121- shift
2222- done
2323-2424- # Check if repo has not the format owner/repo
2525- if [[ ! "$repo" =~ $clone_regex ]]; then
2626- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2727-2828- # if it is our own repo the clone it
2929- if is_my_github_repo "$current_user/$repo"; then
3030- gh repo clone "$current_user/$repo"
3131- return 0
3232- fi
3333-3434- # else print the help
3535- usage
3636- fi
3737-3838- # Check if the owner exists on GitHub
3939- if ! is_a_github_user "$repo_owner"; then
4040- echo "${BOLD} Sorry, there is no user named ${GREEN}$repo_owner ${RESET_COLOR}on ${LIGHT_BLUE}GitHub !"
4141- return 0
4242- fi
4343-4444- # Construct the full GitHub clone URL
4545- url="$GITHUB_URL/$repo"
4646-4747- # If depth is provided, use it in the git clone command
4848- if [[ -n "$depth" ]]; then
4949- git clone "$url" --depth="$depth"
5050- else
5151- git clone "$url"
5252- fi
5353-}
5454-5555-# Resolve the full path to the script's directory
5656-REAL_PATH="$(dirname "$(readlink -f "$0")")"
5757-PARENT_DIR="$(dirname "$REAL_PATH")"
5858-CATEGORY="gh_scripts"
5959-6060-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
6161-HELP_FILE="$(basename "$0" .sh)_help.sh"
6262-6363-UTILS_DIR="$PARENT_DIR/utils"
6464-6565-# Import necessary variables and functions
6666-source "$UTILS_DIR/check_connection.sh"
6767-source "$UTILS_DIR/check_repo.sh"
6868-source "$UTILS_DIR/check_git.sh"
6969-source "$UTILS_DIR/setup_git.sh"
7070-source "$UTILS_DIR/check_sudo.sh"
7171-source "$UTILS_DIR/check_user.sh"
7272-source "$UTILS_DIR/colors.sh"
7373-source "$UTILS_DIR/usage.sh"
7474-7575-# Import help file
7676-source "$HELPS_DIR/$HELP_FILE"
7777-7878-# Usage function to display help
7979-function usage {
8080- show_help "Usage" "${gcln_arguments[@]}"
8181- show_help "Description" "${gcln_descriptions[@]}"
8282- show_help "Options" "${gcln_options[@]}"
8383- exit 0
8484-}
8585-8686-# regex to match clone repo case
8787-clone_regex='^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$'
8888-8989-# Display help on --help flag and insifficient argument
9090-if [[ "$1" == "--help" || "$#" -lt 1 ]]; then
9191- usage
9292-fi
9393-9494-# prompt for sudo
9595-# password if required
9696-allow_sudo
9797-9898-# Setting up git
9999-setup_git
100100-101101-# Check for internet connectivity to GitHub
102102-check_connection
103103-104104-# Call the function with all arguments
105105-clone_repo "$@"
-95
gh_scripts/ghadd.sh
···11-#!/bin/bash
22-33-function ghadd {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if ! has_remote; then
1010- echo "${BOLD} This repo has no remote on GitHub !"
1111- return 0
1212- fi
1313-1414- if [ $# -eq 0 ]; then
1515- echo "${BOLD} Specify the username of the new collaborator !"
1616- return 0
1717- fi
1818-1919- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2020- repo_url=$(git config --get remote.origin.url)
2121- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
2222- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2323-2424- # check if we are not the owner of the repo
2525- if [ "$repo_owner" != "$current_user" ]; then
2626- echo "${BOLD} Sorry, you are not the owner of this repo !"
2727- return 0
2828- fi
2929-3030- # Loop through each collaborator username provided as an argument
3131- for collaborator in "$@"; do
3232- # Check if the collaborator exists on GitHub
3333- if ! is_a_github_user "$collaborator"; then
3434- printf "${BOLD} Cannot invite ${LIGHT_BLUE}$collaborator ${RESET_COLOR}to collaborate on ${LIGHT_BLUE}$repo_name${RESET_COLOR} "
3535- continue
3636- fi
3737-3838- execute_with_loading \
3939- "${BOLD} Inviting ${LIGHT_BLUE}$collaborator ${RESET_COLOR}to collaborate on ${LIGHT_BLUE}$repo_name${RESET_COLOR}" \
4040- "gh api --method=PUT repos/$current_user/$repo_name/collaborators/$collaborator"
4141- done
4242-}
4343-4444-# Resolve the full path to the script's directory
4545-REAL_PATH="$(dirname "$(readlink -f "$0")")"
4646-PARENT_DIR="$(dirname "$REAL_PATH")"
4747-CATEGORY="gh_scripts"
4848-4949-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
5050-HELP_FILE="$(basename "$0" .sh)_help.sh"
5151-5252-UTILS_DIR="$PARENT_DIR/utils"
5353-5454-# Import necessary variables and functions
5555-source "$UTILS_DIR/check_connection.sh"
5656-source "$UTILS_DIR/check_git.sh"
5757-source "$UTILS_DIR/check_gh.sh"
5858-source "$UTILS_DIR/setup_git.sh"
5959-source "$UTILS_DIR/check_remote.sh"
6060-source "$UTILS_DIR/check_sudo.sh"
6161-source "$UTILS_DIR/check_user.sh"
6262-source "$UTILS_DIR/colors.sh"
6363-source "$UTILS_DIR/loading.sh"
6464-source "$UTILS_DIR/usage.sh"
6565-6666-# Import help file
6767-source "$HELPS_DIR/$HELP_FILE"
6868-6969-# Usage function to display help
7070-function usage {
7171- show_help "Usage" "${ghadd_arguments[@]}"
7272- show_help "Description" "${ghadd_descriptions[@]}"
7373- show_help "Options" "${ghadd_options[@]}"
7474- show_extra "${ghadd_extras[@]}"
7575- exit 0
7676-}
7777-7878-# Check if --help is the first argument
7979-[ "$1" = "--help" ] && usage
8080-8181-# prompt for sudo
8282-# password if required
8383-allow_sudo
8484-8585-# Setting up git
8686-setup_git
8787-8888-# Check gh
8989-check_gh
9090-9191-# Check for internet connectivity to GitHub
9292-check_connection
9393-9494-# Call ghadd function
9595-ghadd "$@"
-178
gh_scripts/ghc.sh
···11-#!/bin/bash
22-33-function ghc {
44- # Get the repo name and visibility
55- if [ $# -eq 0 ]; then
66- repo="$(basename "$PWD")"
77- repo_visibility="public"
88- elif [ $# -eq 1 ]; then
99- if [ "$1" = "private" ]; then
1010- repo="$(basename "$PWD")"
1111- repo_visibility="private"
1212- else
1313- repo="$1"
1414- repo_visibility="public"
1515- fi
1616- elif [ $# -eq 2 ]; then
1717- repo="$1"
1818- repo_visibility="$2"
1919- else
2020- echo "${BOLD}${RED}Error: Too many arguments.${RESET}"
2121- usage
2222- fi
2323-2424- # Clean the repo name
2525- repo_name=$(clean_repo "$repo")
2626-2727- if is_a_git_repo; then
2828- if has_remote; then
2929- printf "${BOLD} This repo already has a remote on GitHub!${RESET}\n"
3030- return 0
3131- fi
3232-3333- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
3434- current_protocol=$(grep 'git_protocol:' ~/.config/gh/hosts.yml | awk '{print $2}')
3535- origin_base_url=$(
3636- [[ "$current_protocol" == "ssh" ]] &&
3737- echo "git@github.com:" ||
3838- echo "https://github.com/"
3939- )
4040-4141- check_set_repo() {
4242- printf "${BOLD}${RESET_COLOR} Create ${GREEN}$repo_visibility ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
4343- read set_repo
4444- if [ "$set_repo" = "y" ]; then
4545- # Create the repo & set it as remote of the local one
4646- printf "${BOLD} New repository ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub ... ${RESET}"
4747- gh repo create "$repo_name" --"$repo_visibility" &>/dev/null
4848- git remote add origin "$origin_base_url$current_user/$repo_name.git"
4949- printf "${BOLD}${GREEN} ${RESET}\n"
5050-5151- check_push() {
5252- printf "${BOLD}${RESET_COLOR} Push local commits to ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
5353- read check_push_commit
5454-5555- if [ "$check_push_commit" = "y" ]; then
5656- current_branch=$(git branch | awk '/\*/ {print $2}')
5757- git push origin "$current_branch"
5858- elif [ "$check_push_commit" = "n" ]; then
5959- return 0
6060- else
6161- check_push
6262- fi
6363- }
6464-6565- current_branch=$(git branch | awk '/\*/ {print $2}')
6666-6767- if git rev-list --count "$current_branch" 2>/dev/null | grep -q '^[1-9]'; then
6868- check_push
6969- fi
7070- elif [ "$set_repo" = "n" ]; then
7171- return 0
7272- else
7373- check_set_repo
7474- fi
7575- }
7676- check_set_repo
7777- else
7878- # Check for internet connectivity to GitHub
7979- if ! connected; then
8080- echo "${BOLD} Sorry, you are offline !${RESET}"
8181- check_local() {
8282- printf "${BOLD}${RESET_COLOR} Create ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
8383- read create_local
8484-8585- if [ "$create_local" = "y" ]; then
8686- git init &>/dev/null
8787- elif [ "$create_local" = "n" ]; then
8888- return 0
8989- else
9090- check_local
9191- fi
9292- }
9393- check_local
9494- else
9595- check_create_repo() {
9696- printf "${BOLD}${RESET_COLOR} Create ${GREEN}$repo_visibility ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
9797- read create_repo
9898- if [ "$create_repo" = "y" ]; then
9999- # Create the repo & clone it locally
100100- printf "${BOLD} New repository ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub ... ${RESET}"
101101- gh repo create "$repo_name" --"$repo_visibility" -c &>/dev/null
102102- mv "$repo_name/.git" . && rm -rf "$repo_name"
103103- printf "${BOLD}${GREEN} ${RESET}\n"
104104- elif [ "$create_repo" = "n" ]; then
105105- check_local() {
106106- printf "${BOLD}${RESET_COLOR} Create ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}? (y/n) ${RESET}"
107107- read create_local
108108-109109- if [ "$create_local" = "y" ]; then
110110- git init &>/dev/null
111111- elif [ "$create_local" = "n" ]; then
112112- return 0
113113- else
114114- check_local
115115- fi
116116- }
117117- check_local
118118- else
119119- check_create_repo
120120- fi
121121- }
122122- check_create_repo
123123- fi
124124- fi
125125-}
126126-127127-# Resolve the full path to the script's directory
128128-REAL_PATH="$(dirname "$(readlink -f "$0")")"
129129-PARENT_DIR="$(dirname "$REAL_PATH")"
130130-CATEGORY="gh_scripts"
131131-132132-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
133133-HELP_FILE="$(basename "$0" .sh)_help.sh"
134134-135135-UTILS_DIR="$PARENT_DIR/utils"
136136-137137-# Import necessary variables and functions
138138-source "$UTILS_DIR/check_connection.sh"
139139-source "$UTILS_DIR/check_git.sh"
140140-source "$UTILS_DIR/check_gh.sh"
141141-source "$UTILS_DIR/setup_git.sh"
142142-source "$UTILS_DIR/check_remote.sh"
143143-source "$UTILS_DIR/check_sudo.sh"
144144-source "$UTILS_DIR/check_user.sh"
145145-source "$UTILS_DIR/clean_repo.sh"
146146-source "$UTILS_DIR/colors.sh"
147147-source "$UTILS_DIR/usage.sh"
148148-149149-# Import help file
150150-source "$HELPS_DIR/$HELP_FILE"
151151-152152-# Usage function to display help
153153-function usage {
154154- show_help "Usage" "${ghc_arguments[@]}"
155155- show_help "Description" "${ghc_descriptions[@]}"
156156- show_help "Options" "${ghc_options[@]}"
157157- show_extra "${ghc_extras[@]}"
158158- exit 0
159159-}
160160-161161-# Check if --help is the first argument
162162-[ "$1" = "--help" ] && usage
163163-164164-# prompt for sudo
165165-# password if required
166166-allow_sudo
167167-168168-# Setting up git
169169-setup_git
170170-171171-# Check gh
172172-check_gh
173173-174174-# Check for internet connectivity to GitHub
175175-check_connection
176176-177177-# Call ghc function
178178-ghc "$@"
-112
gh_scripts/ghcls.sh
···11-#!/bin/bash
22-33-function ghcls {
44- # Check for git local repo
55- if ! is_a_git_repo; then
66- echo "${BOLD} This won't work, you are not in a git repo !"
77- return 0
88- fi
99-1010- # Check for remote repo
1111- if ! has_remote; then
1212- echo "${BOLD} This repo has no remote on GitHub !"
1313- return 0
1414- fi
1515-1616- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
1717- repo_url=$(git config --get remote.origin.url)
1818- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
1919- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2020-2121- # check if we are not the owner of the repo
2222- if [ "$repo_owner" != "$current_user" ]; then
2323- echo "${BOLD} Sorry, you are not the owner of this repo !"
2424- return 0
2525- fi
2626-2727- printf "${BOLD} ${LIGHT_BLUE}Collaborators ${RESET_COLOR}for the ${LIGHT_BLUE}$repo_name ${RESET_COLOR}repository "
2828-2929- # List collaborators using gh api
3030- collaborators=$(gh api "repos/$current_user/$repo_name/collaborators" --jq '.[].login')
3131- invitations=$(gh api "repos/$current_user/$repo_name/invitations" --jq '.[].invitee.login')
3232-3333- collaborators_count=$(echo "$collaborators" | wc -l)
3434- invitations_count=$(echo "$invitations" | wc -l)
3535- collaborators_num=$((collaborators_count + invitations_count))
3636- echo "${RESET_COLOR}${BOLD}($collaborators_count)"
3737-3838- # Check if we get any collaborators
3939- if [ -z "$collaborators" ]; then
4040- echo "No collaborators found."
4141- return 0
4242- fi
4343-4444- # Iterate through each collaborator
4545- echo "$collaborators" | while IFS= read -r collaborator; do
4646- if [ "$collaborator" = "$current_user" ]; then
4747- echo " ● $collaborator (owner)"
4848- else
4949- echo " ● $collaborator"
5050- fi
5151- done
5252-5353- # Check if there are pending invitations
5454- if [ -n "$invitations" ]; then
5555- # Print pending invitations
5656- echo "$invitations" | while IFS= read -r invitee; do
5757- echo " ● $invitee (invitation pending)"
5858- done
5959- fi
6060-}
6161-6262-# Resolve the full path to the script's directory
6363-REAL_PATH="$(dirname "$(readlink -f "$0")")"
6464-PARENT_DIR="$(dirname "$REAL_PATH")"
6565-CATEGORY="gh_scripts"
6666-6767-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
6868-HELP_FILE="$(basename "$0" .sh)_help.sh"
6969-7070-UTILS_DIR="$PARENT_DIR/utils"
7171-7272-# Import necessary variables and functions
7373-source "$UTILS_DIR/check_connection.sh"
7474-source "$UTILS_DIR/check_git.sh"
7575-source "$UTILS_DIR/check_gh.sh"
7676-source "$UTILS_DIR/setup_git.sh"
7777-source "$UTILS_DIR/check_remote.sh"
7878-source "$UTILS_DIR/check_sudo.sh"
7979-source "$UTILS_DIR/check_user.sh"
8080-source "$UTILS_DIR/colors.sh"
8181-source "$UTILS_DIR/usage.sh"
8282-8383-# Import help file
8484-source "$HELPS_DIR/$HELP_FILE"
8585-8686-# Usage function to display help
8787-function usage {
8888- show_help "Usage" "${ghcls_arguments[@]}"
8989- show_help "Description" "${ghcls_descriptions[@]}"
9090- show_help "Options" "${ghcls_options[@]}"
9191- show_extra "${ghcls_extras[@]}"
9292- exit 0
9393-}
9494-9595-# Check if --help is the first argument
9696-[ "$1" = "--help" ] && usage
9797-9898-# prompt for sudo
9999-# password if required
100100-allow_sudo
101101-102102-# Setting up git
103103-setup_git
104104-105105-# Check gh
106106-check_gh
107107-108108-# Check for internet connectivity to GitHub
109109-check_connection
110110-111111-# Call ghcls function
112112-ghcls
-153
gh_scripts/ghd.sh
···11-#!/bin/bash
22-33-function ghd {
44- if [ $# -eq 1 ]; then
55- if ! connected; then
66- echo "${BOLD} Sorry, you are offline !${RESET}"
77- return 0
88- fi
99-1010- if ! gh_installed; then
1111- echo "${BOLD} gh is not installed !${RESET}"
1212- return 0
1313- fi
1414-1515- repo_name="$1"
1616- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
1717-1818- # Check if the repo doesn't exist
1919- if ! load_and_delete \
2020- "${BOLD} Checking the ${GREEN}repo${RESET_COLOR} named" \
2121- "${LIGHT_BLUE}$current_user/$repo_name ${RESET_COLOR}on GitHub" \
2222- "is_my_github_repo $current_user/$repo_name"; then
2323-2424- echo "${BOLD} Sorry, there is ${GREEN}no repo ${RESET_COLOR}such as" \
2525- "${LIGHT_BLUE}$current_user/$repo_name ${RESET_COLOR}on GitHub ${RESET}"
2626- return 0
2727- fi
2828-2929- isPrivate=$(gh repo view "$repo_name" --json isPrivate --jq '.isPrivate')
3030- repo_visibility=$([ "$isPrivate" = "true" ] && echo "private" || echo "public")
3131-3232- delete_repo "$repo_name"
3333- else
3434- if ! is_a_git_repo; then
3535- echo "${BOLD} This won't work, you are not in a git repo!${RESET}"
3636- return 0
3737- fi
3838-3939- if has_remote; then
4040- if connected; then
4141- if ! gh_installed; then
4242- echo "${BOLD} gh is not installed !${RESET}"
4343- return 0
4444- fi
4545-4646- repo_url=$(git config --get remote.origin.url)
4747- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
4848- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
4949-5050- if [ "$repo_owner" != "$current_user" ]; then
5151- echo "${BOLD} Sorry, you are not the owner of this repo!${RESET}"
5252- else
5353- repo_name=$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')
5454- isPrivate=$(gh repo view "$repo_name" --json isPrivate --jq '.isPrivate')
5555- repo_visibility=$([ "$isPrivate" = "true" ] && echo "private" || echo "public")
5656-5757- delete_repo "$repo_name"
5858- git remote remove origin
5959- echo
6060- delete_local_repo "$repo_name"
6161- fi
6262- else
6363- repo_name=$(basename "$(git rev-parse --show-toplevel)")
6464- delete_local_repo "$repo_name"
6565- fi
6666- else
6767- repo_name=$(basename "$(git rev-parse --show-toplevel)")
6868- delete_local_repo "$repo_name"
6969- fi
7070- fi
7171-}
7272-7373-# Resolve the full path to the script's directory
7474-REAL_PATH="$(dirname "$(readlink -f "$0")")"
7575-PARENT_DIR="$(dirname "$REAL_PATH")"
7676-CATEGORY="gh_scripts"
7777-7878-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
7979-HELP_FILE="$(basename "$0" .sh)_help.sh"
8080-8181-UTILS_DIR="$PARENT_DIR/utils"
8282-8383-# Import necessary variables and functions
8484-source "$UTILS_DIR/check_connection.sh"
8585-source "$UTILS_DIR/check_git.sh"
8686-source "$UTILS_DIR/check_gh.sh"
8787-source "$UTILS_DIR/check_repo.sh"
8888-source "$UTILS_DIR/setup_git.sh"
8989-source "$UTILS_DIR/check_remote.sh"
9090-source "$UTILS_DIR/check_sudo.sh"
9191-source "$UTILS_DIR/check_user.sh"
9292-source "$UTILS_DIR/clean_repo.sh"
9393-source "$UTILS_DIR/colors.sh"
9494-source "$UTILS_DIR/loading.sh"
9595-source "$UTILS_DIR/usage.sh"
9696-9797-# Import help file
9898-source "$HELPS_DIR/$HELP_FILE"
9999-100100-# Usage function to display help
101101-function usage {
102102- show_help "Usage" "${ghd_arguments[@]}"
103103- show_help "Description" "${ghd_descriptions[@]}"
104104- show_help "Options" "${ghd_options[@]}"
105105- exit 0
106106-}
107107-108108-# Check if --help is the first argument
109109-[ "$1" = "--help" ] && usage
110110-111111-# prompt for sudo
112112-# password if required
113113-allow_sudo
114114-115115-# Setting up git
116116-setup_git
117117-118118-# Function to delete local repo
119119-function delete_local_repo {
120120- printf "${BOLD}${RESET} Delete ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$1 ${RESET}? (y/n) ${RESET}"
121121- read delete_local_repo
122122-123123- if [ "$delete_local_repo" = "y" ]; then
124124- local repo_source=$(git rev-parse --show-toplevel)
125125-126126- execute_with_loading \
127127- "${BOLD} Deleting ${GREEN}local ${RESET_COLOR}repo ${LIGHT_BLUE}$1 ${RESET}" \
128128- "rm -rf "$repo_source/.git""
129129- elif [ "$delete_local_repo" = "n" ]; then
130130- return 0
131131- else
132132- delete_local_repo "$1"
133133- fi
134134-}
135135-136136-# Function to delete GitHub repo
137137-function delete_repo {
138138- printf "${BOLD} Delete ${GREEN}$repo_visibility ${RESET_COLOR}repo ${LIGHT_BLUE}$1 ${RESET_COLOR}? (y/n) ${RESET}"
139139- read delete_repo
140140-141141- if [ "$delete_repo" = "y" ]; then
142142- execute_with_loading \
143143- "${BOLD} Deleting repository ${LIGHT_BLUE}$1 ${RESET_COLOR}on GitHub" \
144144- "gh repo delete "$1" --yes"
145145- elif [ "$delete_repo" = "n" ]; then
146146- return 0
147147- else
148148- delete_repo "$1"
149149- fi
150150-}
151151-152152-# Call ghd function
153153-ghd "$@"
-107
gh_scripts/ghdel.sh
···11-#!/bin/bash
22-33-function ghdel {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if ! has_remote; then
1010- echo "${BOLD} This repo has no remote on Github !"
1111- return 0
1212- fi
1313-1414- if [ $# -eq 0 ]; then
1515- echo "${BOLD} Specify the username of the collaborator to remove !"
1616- return 0
1717- fi
1818-1919- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
2020- repo_url=$(git config --get remote.origin.url)
2121- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
2222- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
2323-2424- # check if we are not the owner of the repo
2525- if [ "$repo_owner" != "$current_user" ]; then
2626- echo "${BOLD} Sorry, you are not the owner of this repo !"
2727- return 0
2828- fi
2929-3030- # Retrieve the list of collaborators
3131- collaborators=$(gh api "repos/$current_user/$repo_name/collaborators" --jq '.[].login')
3232- invitations=$(gh api "repos/$current_user/$repo_name/invitations" --jq '.[].invitee.login')
3333-3434- # Loop through each collaborator username provided as an argument
3535- for collaborator in "$@"; do
3636- # Check if the collaborator exists in the list of collaborators
3737- if echo "$collaborators" | grep -q "$collaborator" ||
3838- echo "$invitations" | grep -q "$collaborator"; then
3939- printf "${BOLD} Removing ${LIGHT_BLUE}$collaborator ${RESET_COLOR}from ${LIGHT_BLUE}$repo_name${RESET_COLOR} "
4040- # Check for pending invitations
4141- invitation_id=$(gh api "repos/$current_user/$repo_name/invitations" --jq ".[] | select(.invitee.login==\"$collaborator\") | .id")
4242-4343- if [ -n "$invitation_id" ]; then
4444- # Delete the pending invitation
4545- gh api --method=DELETE "repos/$current_user/$repo_name/invitations/$invitation_id" >/dev/null 2>&1
4646- printf " ${BOLD}(invitation deleted) "
4747- fi
4848-4949- # Remove collaborator using gh api
5050- gh api --method=DELETE "repos/$current_user/$repo_name/collaborators/$collaborator" >/dev/null 2>&1
5151- echo "${BOLD}${GREEN} ${RESET_COLOR}"
5252- else
5353- echo "${BOLD}${LIGHT_BLUE}$collaborator ${RESET_COLOR}is not a ${LIGHT_BLUE}collaborator ${RED}✘ ${RESET_COLOR}"
5454- fi
5555- done
5656-}
5757-5858-# Resolve the full path to the script's directory
5959-REAL_PATH="$(dirname "$(readlink -f "$0")")"
6060-PARENT_DIR="$(dirname "$REAL_PATH")"
6161-CATEGORY="gh_scripts"
6262-6363-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
6464-HELP_FILE="$(basename "$0" .sh)_help.sh"
6565-6666-UTILS_DIR="$PARENT_DIR/utils"
6767-6868-# Import necessary variables and functions
6969-source "$UTILS_DIR/check_connection.sh"
7070-source "$UTILS_DIR/check_git.sh"
7171-source "$UTILS_DIR/check_gh.sh"
7272-source "$UTILS_DIR/setup_git.sh"
7373-source "$UTILS_DIR/check_remote.sh"
7474-source "$UTILS_DIR/check_sudo.sh"
7575-source "$UTILS_DIR/colors.sh"
7676-source "$UTILS_DIR/usage.sh"
7777-7878-# Import help file
7979-source "$HELPS_DIR/$HELP_FILE"
8080-8181-# Usage function to display help
8282-function usage {
8383- show_help "Usage" "${ghdel_arguments[@]}"
8484- show_help "Description" "${ghdel_descriptions[@]}"
8585- show_help "Options" "${ghdel_options[@]}"
8686- show_extra "${ghdel_extras[@]}"
8787- exit 0
8888-}
8989-9090-# Check if --help is the first argument
9191-[ "$1" = "--help" ] && usage
9292-9393-# prompt for sudo
9494-# password if required
9595-allow_sudo
9696-9797-# Setting up git
9898-setup_git
9999-100100-# Check gh
101101-check_gh
102102-103103-# Check for internet connectivity to GitHub
104104-check_connection
105105-106106-# Call ghdel function
107107-ghdel "$@"
-119
gh_scripts/ghf.sh
···11-#!/bin/bash
22-33-function ghf {
44- repo="$1"
55- IFS="/" read -r repo_owner repo_name <<< "$repo"
66- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
77- clone_repo="--clone"
88-99- # regex to match clone repo case
1010- clone_regex='^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$'
1111-1212- # Check if repo has not the format owner/repo
1313- if [[ ! "$repo" =~ $clone_regex ]]; then
1414- usage
1515- fi
1616-1717- # Check if we have already forked it
1818- if load_and_delete \
1919- "${BOLD} Checking the forked ${GREEN}repo ${RESET_COLOR} named" \
2020- "${LIGHT_BLUE}$current_user/$repo_name ${RESET_COLOR}on GitHub" \
2121- "is_a_github_repo $current_user/$repo_name"; then
2222- echo "${BOLD} You have already ${RED}forked ${RESET_COLOR}the repo named" \
2323- "${GREEN}$repo_name ${RESET_COLOR}on ${LIGHT_BLUE}GitHub ${RESET}"
2424- return 0
2525- fi
2626-2727- # Check if the owner exists on GitHub
2828- if ! load_and_delete \
2929- "${BOLD} Checking the ${GREEN}user ${RESET_COLOR}named" \
3030- "${LIGHT_BLUE}$repo_owner ${RESET_COLOR}on GitHub" \
3131- "is_a_github_user $repo_owner"; then
3232- echo "${BOLD} Sorry, there is ${GREEN}no user ${RESET_COLOR}named" \
3333- "${LIGHT_BLUE}$repo_owner ${RESET_COLOR}on GitHub ${RESET}"
3434- return 0
3535- fi
3636-3737- # Check if the repo doesn't exist
3838- if ! load_and_delete \
3939- "${BOLD} Checking the ${GREEN}repo ${RESET_COLOR}named" \
4040- "${LIGHT_BLUE}$repo_owner/$repo_name ${RESET_COLOR}on GitHub" \
4141- "is_a_github_repo $repo_owner/$repo_name"; then
4242- echo "${BOLD} Sorry, there is ${GREEN}no repo ${RESET_COLOR}such" \
4343- "${LIGHT_BLUE}$repo_owner/$repo_name ${RESET_COLOR}on GitHub ${RESET}"
4444- return 0
4545- fi
4646-4747- if load_and_delete \
4848- "${BOLD} Checking the ${GREEN}local ${RESET_COLOR}git" \
4949- "${LIGHT_BLUE}repo ${RESET_COLOR}" \
5050- "is_a_git_repo"; then
5151- printf "${BOLD}${GREEN} Local Git${RESET_COLOR} repo detected," \
5252- "skipping fork clone for ${LIGHT_BLUE}$repo_name ${RESET}\n"
5353- clone_repo=""
5454- fi
5555-5656- if execute_with_loading \
5757- "${BOLD} Forking ${LIGHT_BLUE}$repo_name ${RESET_COLOR}on GitHub" \
5858- "gh repo fork $repo_owner/$repo_name"; then
5959-6060- if [ "$clone_repo" == "--clone" ]; then
6161- execute_with_loading \
6262- "${BOLD} Cloning fork ${LIGHT_BLUE}$repo_name ${RESET_COLOR}locally" \
6363- "gh repo clone $current_user/$repo_name"
6464- fi
6565- fi
6666-}
6767-6868-# Resolve the full path to the script's directory
6969-REAL_PATH="$(dirname "$(readlink -f "$0")")"
7070-PARENT_DIR="$(dirname "$REAL_PATH")"
7171-CATEGORY="gh_scripts"
7272-7373-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
7474-HELP_FILE="$(basename "$0" .sh)_help.sh"
7575-7676-UTILS_DIR="$PARENT_DIR/utils"
7777-7878-# Import necessary variables and functions
7979-source "$UTILS_DIR/check_connection.sh"
8080-source "$UTILS_DIR/check_git.sh"
8181-source "$UTILS_DIR/check_gh.sh"
8282-source "$UTILS_DIR/check_repo.sh"
8383-source "$UTILS_DIR/setup_git.sh"
8484-source "$UTILS_DIR/check_sudo.sh"
8585-source "$UTILS_DIR/check_user.sh"
8686-source "$UTILS_DIR/colors.sh"
8787-source "$UTILS_DIR/loading.sh"
8888-source "$UTILS_DIR/usage.sh"
8989-9090-# Import help file
9191-source "$HELPS_DIR/$HELP_FILE"
9292-9393-# Usage function to display help
9494-function usage {
9595- show_help "Usage" "${ghf_arguments[@]}"
9696- show_help "Description" "${ghf_descriptions[@]}"
9797- show_help "Options" "${ghf_options[@]}"
9898- show_help "Example" "${ghf_extras[@]}"
9999- exit 0
100100-}
101101-102102-# Check if --help is the first argument
103103-[ "$1" = "--help" ] && usage
104104-105105-# prompt for sudo
106106-# password if required
107107-allow_sudo
108108-109109-# Setting up git
110110-setup_git
111111-112112-# Check gh
113113-check_gh
114114-115115-# Check for internet connectivity to GitHub
116116-check_connection
117117-118118-# Call the function with all arguments
119119-ghf "$@"
-91
gh_scripts/ghnm.sh
···11-#!/bin/bash
22-33-function ghnm {
44- # Check if we are inside a git repo
55- if ! load_and_delete \
66- "${BOLD} Checking the ${GREEN}local ${RESET_COLOR}git" \
77- "${LIGHT_BLUE}repo ${RESET_COLOR}" \
88- "is_a_git_repo"; then
99- echo "${BOLD} This won't work, you are not in a git repo !"
1010- return 0
1111- fi
1212-1313- # Check if the repo has a remote
1414- if ! load_and_delete \
1515- "${BOLD} Checking the ${GREEN}remote ${RESET_COLOR}git" \
1616- "${LIGHT_BLUE}repo ${RESET_COLOR}on GitHub" \
1717- "has_remote"; then
1818- echo "${BOLD} This repo has no remote on GitHub !"
1919- return 0
2020- fi
2121-2222- # Define the new name of the repo
2323- new_name="$1"
2424- repo_url=$(git config --get remote.origin.url)
2525- repo_name=$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')
2626-2727- if [ "$new_name" == "$repo_name" ]; then
2828- echo "${BOLD} The ${GREEN}remote ${RESET_COLOR}repo name is" \
2929- "${LIGHT_BLUE}$repo_name ${RESET}"
3030- return 0
3131- fi
3232-3333- execute_with_loading \
3434- "${BOLD} Renaming ${GREEN}remote ${RESET_COLOR}repo" \
3535- "${LIGHT_BLUE}$repo_name ${RESET_COLOR}to ${LIGHT_BLUE}$new_name ${RESET_COLOR}" \
3636- "gh repo rename "$new_name" --yes"
3737-}
3838-3939-# Resolve the full path to the script's directory
4040-REAL_PATH="$(dirname "$(readlink -f "$0")")"
4141-PARENT_DIR="$(dirname "$REAL_PATH")"
4242-CATEGORY="gh_scripts"
4343-4444-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
4545-HELP_FILE="$(basename "$0" .sh)_help.sh"
4646-4747-UTILS_DIR="$PARENT_DIR/utils"
4848-4949-# Import necessary variables and functions
5050-source "$UTILS_DIR/check_connection.sh"
5151-source "$UTILS_DIR/check_git.sh"
5252-source "$UTILS_DIR/check_gh.sh"
5353-source "$UTILS_DIR/setup_git.sh"
5454-source "$UTILS_DIR/check_remote.sh"
5555-source "$UTILS_DIR/check_sudo.sh"
5656-source "$UTILS_DIR/check_user.sh"
5757-source "$UTILS_DIR/clean_repo.sh"
5858-source "$UTILS_DIR/colors.sh"
5959-source "$UTILS_DIR/loading.sh"
6060-source "$UTILS_DIR/usage.sh"
6161-6262-# Import help file
6363-source "$HELPS_DIR/$HELP_FILE"
6464-6565-# Usage function to display help
6666-function usage {
6767- show_help "Usage" "${ghnm_arguments[@]}"
6868- show_help "Description" "${ghnm_descriptions[@]}"
6969- show_help "Options" "${ghnm_options[@]}"
7070- show_help "Example" "${ghnm_extras[@]}"
7171- exit 0
7272-}
7373-7474-# Check if --help is the first argument
7575-[ "$1" = "--help" ] && usage
7676-7777-# prompt for sudo
7878-# password if required
7979-allow_sudo
8080-8181-# Setting up git
8282-setup_git
8383-8484-# Check gh
8585-check_gh
8686-8787-# Check for internet connectivity to GitHub
8888-check_connection
8989-9090-# Call ghc function
9191-ghnm "$@"
-128
gh_scripts/ghv.sh
···11-#!/bin/bash
22-33-function ghv {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if [[ ! connected && "$1" = "owner" ]]; then
1010- if has_remote; then
1111- repo_url=$(git config --get remote.origin.url)
1212- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
1313- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
1414- else
1515- repo_owner=$(git config user.name)
1616- repo_name=$(basename "$(git rev-parse --show-toplevel)")
1717- fi
1818-1919- if has_remote; then
2020- echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
2121- else
2222- echo "${BOLD} The local repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
2323- fi
2424-2525- return 0
2626- fi
2727-2828- if [ "$#" -eq 0 ] || [ "$1" = "show" ] || [ "$1" = "owner" ]; then
2929- current_user=$(awk '/user:/ {print $2; exit}' ~/.config/gh/hosts.yml)
3030-3131- if has_remote; then
3232- repo_url=$(git config --get remote.origin.url)
3333- repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
3434- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
3535- else
3636- repo_owner=$(git config user.name)
3737- repo_name=$(basename "$(git rev-parse --show-toplevel)")
3838- fi
3939-4040- if [ "$repo_owner" != "$current_user" ] && [ "$1" != "owner" ]; then
4141- echo "${BOLD} Sorry, you are not the owner of this repo !"
4242- elif [ "$1" = "owner" ]; then
4343- if has_remote; then
4444- echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
4545- else
4646- echo "${BOLD} The local repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
4747- fi
4848- else
4949- if has_remote; then
5050- isPrivate=$(gh repo view "$repo_owner/$repo_name" --json isPrivate --jq '.isPrivate')
5151-5252- if [ "$1" = "show" ]; then
5353- visibility=$([ "$isPrivate" = "true" ] && echo "private" || echo "public")
5454- echo "${BOLD} This repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is ${GREEN}$visibility"
5555- else
5656- new_visibility=$([ "$isPrivate" = "true" ] && echo "public" || echo "private")
5757- toggle_visibility() {
5858- printf "${BOLD}${RESET_COLOR} Make ${LIGHT_BLUE}$repo_name ${RESET_COLOR}repo ${GREEN}$new_visibility ${RESET_COLOR}? (y/n) "
5959- read -r change_visibility
6060- if [ "$change_visibility" = "y" ]; then
6161- # toggle visibility
6262- printf "${BOLD} Changing repo visibility to ${GREEN}$new_visibility ${RESET_COLOR}... "
6363- gh repo edit "$repo_owner/$repo_name" --visibility "$new_visibility" &>/dev/null
6464- echo "${BOLD}${GREEN} ${RESET_COLOR}"
6565- elif [ "$change_visibility" = "n" ]; then
6666- return 0
6767- else
6868- toggle_visibility
6969- fi
7070- }
7171- toggle_visibility
7272- fi
7373- else
7474- echo "${BOLD} The local repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}is owned by ${GREEN}$repo_owner"
7575- fi
7676- fi
7777- else
7878- echo "${BOLD} Sorry, wrong command argument !"
7979- fi
8080-}
8181-8282-# Resolve the full path to the script's directory
8383-REAL_PATH="$(dirname "$(readlink -f "$0")")"
8484-PARENT_DIR="$(dirname "$REAL_PATH")"
8585-CATEGORY="gh_scripts"
8686-8787-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
8888-HELP_FILE="$(basename "$0" .sh)_help.sh"
8989-9090-UTILS_DIR="$PARENT_DIR/utils"
9191-9292-# Import necessary variables and functions
9393-source "$UTILS_DIR/check_connection.sh"
9494-source "$UTILS_DIR/check_git.sh"
9595-source "$UTILS_DIR/check_gh.sh"
9696-source "$UTILS_DIR/setup_git.sh"
9797-source "$UTILS_DIR/check_remote.sh"
9898-source "$UTILS_DIR/check_sudo.sh"
9999-source "$UTILS_DIR/colors.sh"
100100-source "$UTILS_DIR/usage.sh"
101101-102102-# Import help file
103103-source "$HELPS_DIR/$HELP_FILE"
104104-105105-# Usage function to display help
106106-function usage {
107107- show_help "Usage" "${ghv_arguments[@]}"
108108- show_help "Description" "${ghv_descriptions[@]}"
109109- show_help "Options" "${ghv_options[@]}"
110110- show_extra "${ghv_extras[@]}"
111111- exit 0
112112-}
113113-114114-# Check if --help is the first argument
115115-[ "$1" = "--help" ] && usage
116116-117117-# prompt for sudo
118118-# password if required
119119-allow_sudo
120120-121121-# Setting up git
122122-setup_git
123123-124124-# Check gh
125125-check_gh
126126-127127-# Call ghv function
128128-ghv "$@"
+71
git.scripts/gad.sh
···11+#!/bin/bash
22+33+function gad {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo!${RESET}"
66+ return 0
77+ fi
88+99+ if [ $# -eq 0 ]; then
1010+ # If no arguments, add all changes and commit (opens editor for commit message)
1111+ git add --all && git commit
1212+ return 0
1313+ fi
1414+1515+ if [ $# -lt 1 ]; then
1616+ # File is specified but no commit message
1717+ echo "${BOLD}${RED}Error: no commit message!${RESET}"
1818+ return 0
1919+ fi
2020+2121+ if [ -f "$1" ]; then
2222+ # Add the file and commit with message from arguments 2 onwards
2323+ git add "$1" && git commit "$1" -m "${*:2}"
2424+ return 0
2525+ fi
2626+2727+ # Add all changes and commit with the provided message
2828+ git add --all && git commit -m "$*"
2929+}
3030+3131+# Resolve the full path to the script's directory
3232+REAL_PATH="$(dirname "$(readlink -f "$0")")"
3333+PARENT_DIR="$(dirname "$REAL_PATH")"
3434+CATEGORY="git.scripts"
3535+3636+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3737+HELP_FILE="$(basename "$0" .sh)_help.sh"
3838+3939+UTILS_DIR="$PARENT_DIR/utils"
4040+4141+# Import necessary variables and functions
4242+source "$UTILS_DIR/check_git.sh"
4343+source "$UTILS_DIR/setup_git.sh"
4444+source "$UTILS_DIR/check_sudo.sh"
4545+source "$UTILS_DIR/colors.sh"
4646+source "$UTILS_DIR/usage.sh"
4747+4848+# Import help file
4949+source "$HELPS_DIR/$HELP_FILE"
5050+5151+# Usage function to display help
5252+function usage {
5353+ show_help "Usage" "${gad_arguments[@]}"
5454+ show_help "Description" "${gad_descriptions[@]}"
5555+ show_help "Options" "${gad_options[@]}"
5656+ show_extra "${gad_extras[@]}"
5757+ exit 0
5858+}
5959+6060+# Check if --help is the first argument
6161+[ "$1" = "--help" ] && usage
6262+6363+# prompt for sudo
6464+# password if required
6565+allow_sudo
6666+6767+# Setting up git
6868+setup_git
6969+7070+# Call gad function
7171+gad "$@"
+58
git.scripts/gcb.sh
···11+#!/bin/bash
22+33+function gcb {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if [ $# -eq 0 ]; then
1010+ git checkout -
1111+ return 0
1212+ fi
1313+1414+ # Wrong command
1515+ echo "${BOLD}${RESET_COLOR} Usage : gcb (no argument)"
1616+}
1717+1818+# Resolve the full path to the script's directory
1919+REAL_PATH="$(dirname "$(readlink -f "$0")")"
2020+PARENT_DIR="$(dirname "$REAL_PATH")"
2121+CATEGORY="git.scripts"
2222+2323+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
2424+HELP_FILE="$(basename "$0" .sh)_help.sh"
2525+2626+UTILS_DIR="$PARENT_DIR/utils"
2727+2828+# Import necessary variables and functions
2929+source "$UTILS_DIR/check_git.sh"
3030+source "$UTILS_DIR/setup_git.sh"
3131+source "$UTILS_DIR/check_sudo.sh"
3232+source "$UTILS_DIR/colors.sh"
3333+source "$UTILS_DIR/usage.sh"
3434+3535+# Import help file
3636+source "$HELPS_DIR/$HELP_FILE"
3737+3838+# Usage function to display help
3939+function usage() {
4040+ show_help "Usage" "${gcb_arguments[@]}"
4141+ show_help "Description" "${gcb_descriptions[@]}"
4242+ show_help "Options" "${gcb_options[@]}"
4343+ show_extra "${gcb_extras[@]}"
4444+ exit 0
4545+}
4646+4747+# Check if --help is the first argument
4848+[ "$1" = "--help" ] && usage
4949+5050+# prompt for sudo
5151+# password if required
5252+allow_sudo
5353+5454+# Setting up git
5555+setup_git
5656+5757+# Call gcb function
5858+gcb
+52
git.scripts/gdf.sh
···11+#!/bin/bash
22+33+function gdf {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !";
66+ return 0
77+ fi
88+99+ git diff ${1:-}
1010+}
1111+1212+# Resolve the full path to the script's directory
1313+REAL_PATH="$(dirname "$(readlink -f "$0")")"
1414+PARENT_DIR="$(dirname "$REAL_PATH")"
1515+CATEGORY="git.scripts"
1616+1717+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
1818+HELP_FILE="$(basename "$0" .sh)_help.sh"
1919+2020+UTILS_DIR="$PARENT_DIR/utils"
2121+2222+# Import necessary variables and functions
2323+source "$UTILS_DIR/check_git.sh"
2424+source "$UTILS_DIR/setup_git.sh"
2525+source "$UTILS_DIR/check_sudo.sh"
2626+source "$UTILS_DIR/colors.sh"
2727+source "$UTILS_DIR/usage.sh"
2828+2929+# Import help file
3030+source "$HELPS_DIR/$HELP_FILE"
3131+3232+# Usage function to display help
3333+function usage {
3434+ show_help "Usage" "${gdf_arguments[@]}"
3535+ show_help "Description" "${gdf_descriptions[@]}"
3636+ show_help "Options" "${gdf_options[@]}"
3737+ show_extra "${gdf_extras[@]}"
3838+ exit 0
3939+}
4040+4141+# Check if --help is the first argument
4242+[ "$1" = "--help" ] && usage
4343+4444+# prompt for sudo
4545+# password if required
4646+allow_sudo
4747+4848+# Setting up git
4949+setup_git
5050+5151+# Call gdf function
5252+gdf "$@"
+84
git.scripts/glc.sh
···11+#!/bin/bash
22+33+function glc {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !";
66+ return 0
77+ fi
88+99+ has_commits=$(git log > /dev/null 2>&1 && echo "true" || echo "false")
1010+1111+ if [ "$has_commits" = "false" ]; then
1212+ echo "${BOLD} Sorry, no commits yet inside this repo !";
1313+ return 0
1414+ fi
1515+1616+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
1717+ current_branch=$(git branch | awk '/\*/ {print $2}');
1818+ commits_num=$(git log --oneline | wc -l);
1919+ last_commit=$(git log --format="%H" -n 1);
2020+ last_commit_message=$(git show --format=%B -s "$last_commit" | head -n 1);
2121+ last_commit_author=$(git log --format='%an' -n 1)
2222+ current_user=$(git config user.name)
2323+ commits_done_today=$(git log --oneline --since="$(date +"%Y-%m-%d 00:00:00")" --author="$current_user" | wc -l)
2424+ commits_contrib_today=$(git log --oneline --since="$(date +"%Y-%m-%d 00:00:00")" --author="$last_commit_author" | wc -l)
2525+2626+ [ $commits_num -le 1 ] && commit_text="commit" || commit_text="commits";
2727+ [ $commits_done_today -le 1 ] && commit_done_text="commit" || commit_done_text="commits";
2828+ [ $commits_contrib_today -le 1 ] && commit_contrib_text="commit" || commit_contrib_text="commits";
2929+ [ $commits_done_today -gt 0 ] &&
3030+ commit_done="${RESET_COLOR}Including ${LIGHT_BLUE}$commits_done_today $commit_done_text ${RESET_COLOR}by ${GREEN}$current_user ${RESET_COLOR}today" ||
3131+ commit_done="${RESET_COLOR}Including ${LIGHT_BLUE}$commits_contrib_today $commit_contrib_text ${RESET_COLOR}by ${GREEN}$last_commit_author ${RESET_COLOR}today"
3232+3333+ if [ "$1" = "show" ]; then
3434+ git log --oneline --no-decorate;
3535+ return 0
3636+ fi
3737+3838+ echo "${BOLD}${LIGHT_BLUE} $repo_name ${RESET_COLOR}has ${LIGHT_BLUE}$commits_num $commit_text ";
3939+ echo " $commit_done";
4040+ echo "${BOLD}${RESET_COLOR} Last Commit on ${GREEN}$current_branch ${RESET_COLOR}: $last_commit_message";
4141+ echo
4242+}
4343+4444+# Resolve the full path to the script's directory
4545+REAL_PATH="$(dirname "$(readlink -f "$0")")"
4646+PARENT_DIR="$(dirname "$REAL_PATH")"
4747+CATEGORY="git.scripts"
4848+4949+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
5050+HELP_FILE="$(basename "$0" .sh)_help.sh"
5151+5252+UTILS_DIR="$PARENT_DIR/utils"
5353+5454+# Import necessary variables and functions
5555+source "$UTILS_DIR/check_git.sh"
5656+source "$UTILS_DIR/setup_git.sh"
5757+source "$UTILS_DIR/check_sudo.sh"
5858+source "$UTILS_DIR/colors.sh"
5959+source "$UTILS_DIR/usage.sh"
6060+6161+# Import help file
6262+source "$HELPS_DIR/$HELP_FILE"
6363+6464+# Usage function to display help
6565+function usage {
6666+ show_help "Usage" "${glc_arguments[@]}"
6767+ show_help "Description" "${glc_descriptions[@]}"
6868+ show_help "Options" "${glc_options[@]}"
6969+ show_extra "${glc_extras[@]}"
7070+ exit 0
7171+}
7272+7373+# Check if --help is the first argument
7474+[ "$1" = "--help" ] && usage
7575+7676+# prompt for sudo
7777+# password if required
7878+allow_sudo
7979+8080+# Setting up git
8181+setup_git
8282+8383+# Call glc function
8484+glc "$@"
+71
git.scripts/gmb.sh
···11+#!/bin/bash
22+33+function gmb {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if [ $# -eq 0 ]; then
1010+ echo "${BOLD} Fatal ! Specify the Branch to merge to $current_branch"
1111+ return 0
1212+ fi
1313+1414+ current_branch=$(git branch | awk '/\*/ {print $2}')
1515+1616+ # check if the branch doesn't exist
1717+ if ! is_a_git_branch "$1"; then
1818+ echo "${BOLD} Fatal ! $1 is a Non Existing branch "
1919+ return 0
2020+ fi
2121+2222+ if [ "$current_branch" = "$1" ]; then
2323+ echo "${BOLD} Fatal ! Cannot Merge Identical Branch "
2424+ return 0
2525+ fi
2626+2727+ git merge "$1"
2828+}
2929+3030+# Resolve the full path to the script's directory
3131+REAL_PATH="$(dirname "$(readlink -f "$0")")"
3232+PARENT_DIR="$(dirname "$REAL_PATH")"
3333+CATEGORY="git.scripts"
3434+3535+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3636+HELP_FILE="$(basename "$0" .sh)_help.sh"
3737+3838+UTILS_DIR="$PARENT_DIR/utils"
3939+4040+# Import necessary variables and functions
4141+source "$UTILS_DIR/check_git.sh"
4242+source "$UTILS_DIR/check_branch.sh"
4343+source "$UTILS_DIR/setup_git.sh"
4444+source "$UTILS_DIR/check_sudo.sh"
4545+source "$UTILS_DIR/colors.sh"
4646+source "$UTILS_DIR/usage.sh"
4747+4848+# Import help file
4949+source "$HELPS_DIR/$HELP_FILE"
5050+5151+# Usage function to display help
5252+function usage {
5353+ show_help "Usage" "${gmb_arguments[@]}"
5454+ show_help "Description" "${gmb_descriptions[@]}"
5555+ show_help "Options" "${gmb_options[@]}"
5656+ show_help "Examples" "${gmb_extras[@]}"
5757+ exit 0
5858+}
5959+6060+# Check if --help is the first argument
6161+[ "$1" = "--help" ] && usage
6262+6363+# prompt for sudo
6464+# password if required
6565+allow_sudo
6666+6767+# Setting up git
6868+setup_git
6969+7070+# Call gmb function
7171+gmb "$@"
+64
git.scripts/gnm.sh
···11+#!/bin/bash
22+33+function gnm {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if [ $# -eq 0 ]; then
1010+ echo "${BOLD}${RESET_COLOR} Please pass the new name of '$current_branch' branch as argument "
1111+ return 0
1212+ fi
1313+1414+ current_branch=$(git branch | awk '/\*/ {print $2}')
1515+1616+ if [ $# -eq 1 ]; then
1717+ git branch -M $current_branch "$1"
1818+ return 0
1919+ fi
2020+2121+ echo "${BOLD}${RESET_COLOR} Usage : gnm new_name_of_the_branch"
2222+}
2323+2424+# Resolve the full path to the script's directory
2525+REAL_PATH="$(dirname "$(readlink -f "$0")")"
2626+PARENT_DIR="$(dirname "$REAL_PATH")"
2727+CATEGORY="git.scripts"
2828+2929+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3030+HELP_FILE="$(basename "$0" .sh)_help.sh"
3131+3232+UTILS_DIR="$PARENT_DIR/utils"
3333+3434+# Import necessary variables and functions
3535+source "$UTILS_DIR/check_git.sh"
3636+source "$UTILS_DIR/setup_git.sh"
3737+source "$UTILS_DIR/check_sudo.sh"
3838+source "$UTILS_DIR/colors.sh"
3939+source "$UTILS_DIR/usage.sh"
4040+4141+# Import help file
4242+source "$HELPS_DIR/$HELP_FILE"
4343+4444+# Usage function to display help
4545+function usage {
4646+ show_help "Usage" "${gnm_arguments[@]}"
4747+ show_help "Description" "${gnm_descriptions[@]}"
4848+ show_help "Options" "${gnm_options[@]}"
4949+ show_help "Examples" "${gnm_extras[@]}"
5050+ exit 0
5151+}
5252+5353+# Check if --help is the first argument
5454+[ "$1" = "--help" ] && usage
5555+5656+# prompt for sudo
5757+# password if required
5858+allow_sudo
5959+6060+# Setting up git
6161+setup_git
6262+6363+# Call gnm function
6464+gnm "$@"
+77
git.scripts/gpl.sh
···11+#!/bin/bash
22+33+function gpl {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ # check if it has a remote to push
1010+ if ! has_remote; then
1111+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
1212+ echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}has ${RED}no remote"
1313+ return 0
1414+ fi
1515+1616+ repo_url=$(git config --get remote.origin.url)
1717+ repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
1818+ current_branch=$(git branch | awk '/\*/ {print $2}')
1919+ is_remote_branch=$(git branch -r | grep "origin/$current_branch")
2020+2121+ # check if the current branch has remote
2222+ if [ -z "$is_remote_branch" ]; then
2323+ echo "${BOLD} The remote repo ${LIGHT_BLUE}$repo_name" \
2424+ "${RESET_COLOR}has no branch named ${GREEN}$current_branch ${RESET_COLOR}!"
2525+ return 0
2626+ fi
2727+2828+ # Pull changes from remote branch
2929+ git pull origin $current_branch
3030+}
3131+3232+# Resolve the full path to the script's directory
3333+REAL_PATH="$(dirname "$(readlink -f "$0")")"
3434+PARENT_DIR="$(dirname "$REAL_PATH")"
3535+CATEGORY="git.scripts"
3636+3737+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3838+HELP_FILE="$(basename "$0" .sh)_help.sh"
3939+4040+UTILS_DIR="$PARENT_DIR/utils"
4141+4242+# Import necessary variables and functions
4343+source "$UTILS_DIR/check_connection.sh"
4444+source "$UTILS_DIR/check_remote.sh"
4545+source "$UTILS_DIR/check_git.sh"
4646+source "$UTILS_DIR/setup_git.sh"
4747+source "$UTILS_DIR/check_sudo.sh"
4848+source "$UTILS_DIR/colors.sh"
4949+source "$UTILS_DIR/usage.sh"
5050+5151+# Import help file
5252+source "$HELPS_DIR/$HELP_FILE"
5353+5454+# Usage function to display help
5555+function usage {
5656+ show_help "Usage" "${gpl_arguments[@]}"
5757+ show_help "Description" "${gpl_descriptions[@]}"
5858+ show_help "Options" "${gpl_options[@]}"
5959+ show_extra "${gpl_extras[@]}"
6060+ exit 0
6161+}
6262+6363+# Check if --help is the first argument
6464+[ "$1" = "--help" ] && usage
6565+6666+# prompt for sudo
6767+# password if required
6868+allow_sudo
6969+7070+# Setting up git
7171+setup_git
7272+7373+# Check for internet connectivity to GitHub
7474+check_connection
7575+7676+# Call gpl function
7777+gpl
+69
git.scripts/gpsh.sh
···11+#!/bin/bash
22+33+function gpsh {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ # Get the repo name
1010+ repo_name=$(basename "$(git rev-parse --show-toplevel)")
1111+1212+ # check if it has a remote to push
1313+ if ! has_remote; then
1414+ echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}has ${RED}no remote"
1515+ return 0
1616+ fi
1717+1818+ current_branch=$(git branch | awk '/\*/ {print $2}')
1919+2020+ # Push changes to remote branch
2121+ git push origin $current_branch
2222+}
2323+2424+# Resolve the full path to the script's directory
2525+REAL_PATH="$(dirname "$(readlink -f "$0")")"
2626+PARENT_DIR="$(dirname "$REAL_PATH")"
2727+CATEGORY="git.scripts"
2828+2929+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3030+HELP_FILE="$(basename "$0" .sh)_help.sh"
3131+3232+UTILS_DIR="$PARENT_DIR/utils"
3333+3434+# Import necessary variables and functions
3535+source "$UTILS_DIR/check_connection.sh"
3636+source "$UTILS_DIR/check_remote.sh"
3737+source "$UTILS_DIR/check_git.sh"
3838+source "$UTILS_DIR/setup_git.sh"
3939+source "$UTILS_DIR/check_sudo.sh"
4040+source "$UTILS_DIR/colors.sh"
4141+source "$UTILS_DIR/usage.sh"
4242+4343+# Import help file
4444+source "$HELPS_DIR/$HELP_FILE"
4545+4646+# Usage function to display help
4747+function usage {
4848+ show_help "Usage" "${gpsh_arguments[@]}"
4949+ show_help "Description" "${gpsh_descriptions[@]}"
5050+ show_help "Options" "${gpsh_options[@]}"
5151+ show_help "${gpsh_extras[@]}"
5252+ exit 0
5353+}
5454+5555+# Check if --help is the first argument
5656+[ "$1" = "--help" ] && usage
5757+5858+# prompt for sudo
5959+# password if required
6060+allow_sudo
6161+6262+# Setting up git
6363+setup_git
6464+6565+# Check for internet connectivity to GitHub
6666+check_connection
6767+6868+# Call gpsh function
6969+gpsh
+76
git.scripts/grst.sh
···11+#!/bin/bash
22+33+function grst {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ if [ $# -eq 0 ]; then
1010+ git checkout -- .
1111+ return 0
1212+ fi
1313+1414+ if [ -f "$1" ]; then
1515+ git reset "$1"
1616+ return 0
1717+ fi
1818+1919+ if [ $1 = "cmt" ]; then
2020+ git reset --soft HEAD~1
2121+ return 0
2222+ fi
2323+2424+ # Loop through each argument and check if it's a file
2525+ for arg in "$@"; do
2626+ if [ ! -f "$arg" ]; then
2727+ echo "${BOLD}${RESET_COLOR} Sorry, only restore file(s). ${LIGHT_BLUE}'$arg'${RESET_COLOR} is not a valid file."
2828+ exit 1
2929+ fi
3030+ done
3131+3232+ # If all arguments are valid files, restore them
3333+ git restore "$@"
3434+}
3535+3636+# Resolve the full path to the script's directory
3737+REAL_PATH="$(dirname "$(readlink -f "$0")")"
3838+PARENT_DIR="$(dirname "$REAL_PATH")"
3939+CATEGORY="git.scripts"
4040+4141+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
4242+HELP_FILE="$(basename "$0" .sh)_help.sh"
4343+4444+UTILS_DIR="$PARENT_DIR/utils"
4545+4646+# Import necessary variables and functions
4747+source "$UTILS_DIR/check_git.sh"
4848+source "$UTILS_DIR/setup_git.sh"
4949+source "$UTILS_DIR/check_sudo.sh"
5050+source "$UTILS_DIR/colors.sh"
5151+source "$UTILS_DIR/usage.sh"
5252+5353+# Import help file
5454+source "$HELPS_DIR/$HELP_FILE"
5555+5656+# Usage function to display help
5757+function usage {
5858+ show_help "Usage" "${grst_arguments[@]}"
5959+ show_help "Description" "${grst_descriptions[@]}"
6060+ show_help "Options" "${grst_options[@]}"
6161+ show_extra "${grst_extras[@]}"
6262+ exit 0
6363+}
6464+6565+# Check if --help is the first argument
6666+[ "$1" = "--help" ] && usage
6767+6868+# prompt for sudo
6969+# password if required
7070+allow_sudo
7171+7272+# Setting up git
7373+setup_git
7474+7575+# Call grst function
7676+grst "$@"
+53
git.scripts/gst.sh
···11+#!/bin/bash
22+33+function gst {
44+ if ! is_a_git_repo; then
55+ echo "${BOLD} This won't work, you are not in a git repo !"
66+ return 0
77+ fi
88+99+ # Get the status
1010+ git status -s
1111+}
1212+1313+# Resolve the full path to the script's directory
1414+REAL_PATH="$(dirname "$(readlink -f "$0")")"
1515+PARENT_DIR="$(dirname "$REAL_PATH")"
1616+CATEGORY="git.scripts"
1717+1818+HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
1919+HELP_FILE="$(basename "$0" .sh)_help.sh"
2020+2121+UTILS_DIR="$PARENT_DIR/utils"
2222+2323+# Import necessary variables and functions
2424+source "$UTILS_DIR/check_git.sh"
2525+source "$UTILS_DIR/setup_git.sh"
2626+source "$UTILS_DIR/check_sudo.sh"
2727+source "$UTILS_DIR/colors.sh"
2828+source "$UTILS_DIR/usage.sh"
2929+3030+# Import help file
3131+source "$HELPS_DIR/$HELP_FILE"
3232+3333+# Usage function to display help
3434+function usage {
3535+ show_help "Usage" "${gst_arguments[@]}"
3636+ show_help "Description" "${gst_descriptions[@]}"
3737+ show_help "Options" "${gst_options[@]}"
3838+ show_extra "${gst_extras[@]}"
3939+ exit 0
4040+}
4141+4242+# Check if --help is the first argument
4343+[ "$1" = "--help" ] && usage
4444+4545+# prompt for sudo
4646+# password if required
4747+allow_sudo
4848+4949+# Setting up git
5050+setup_git
5151+5252+# Call gst function
5353+gst
-71
git_scripts/gad.sh
···11-#!/bin/bash
22-33-function gad {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo!${RESET}"
66- return 0
77- fi
88-99- if [ $# -eq 0 ]; then
1010- # If no arguments, add all changes and commit (opens editor for commit message)
1111- git add --all && git commit
1212- return 0
1313- fi
1414-1515- if [ $# -lt 1 ]; then
1616- # File is specified but no commit message
1717- echo "${BOLD}${RED}Error: no commit message!${RESET}"
1818- return 0
1919- fi
2020-2121- if [ -f "$1" ]; then
2222- # Add the file and commit with message from arguments 2 onwards
2323- git add "$1" && git commit "$1" -m "${*:2}"
2424- return 0
2525- fi
2626-2727- # Add all changes and commit with the provided message
2828- git add --all && git commit -m "$*"
2929-}
3030-3131-# Resolve the full path to the script's directory
3232-REAL_PATH="$(dirname "$(readlink -f "$0")")"
3333-PARENT_DIR="$(dirname "$REAL_PATH")"
3434-CATEGORY="git_scripts"
3535-3636-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3737-HELP_FILE="$(basename "$0" .sh)_help.sh"
3838-3939-UTILS_DIR="$PARENT_DIR/utils"
4040-4141-# Import necessary variables and functions
4242-source "$UTILS_DIR/check_git.sh"
4343-source "$UTILS_DIR/setup_git.sh"
4444-source "$UTILS_DIR/check_sudo.sh"
4545-source "$UTILS_DIR/colors.sh"
4646-source "$UTILS_DIR/usage.sh"
4747-4848-# Import help file
4949-source "$HELPS_DIR/$HELP_FILE"
5050-5151-# Usage function to display help
5252-function usage {
5353- show_help "Usage" "${gad_arguments[@]}"
5454- show_help "Description" "${gad_descriptions[@]}"
5555- show_help "Options" "${gad_options[@]}"
5656- show_extra "${gad_extras[@]}"
5757- exit 0
5858-}
5959-6060-# Check if --help is the first argument
6161-[ "$1" = "--help" ] && usage
6262-6363-# prompt for sudo
6464-# password if required
6565-allow_sudo
6666-6767-# Setting up git
6868-setup_git
6969-7070-# Call gad function
7171-gad "$@"
-58
git_scripts/gcb.sh
···11-#!/bin/bash
22-33-function gcb {
44- if ! is_a_git_repo; then
55- echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if [ $# -eq 0 ]; then
1010- git checkout -
1111- return 0
1212- fi
1313-1414- # Wrong command
1515- echo "${BOLD}${RESET_COLOR} Usage : gcb (no argument)"
1616-}
1717-1818-# Resolve the full path to the script's directory
1919-REAL_PATH="$(dirname "$(readlink -f "$0")")"
2020-PARENT_DIR="$(dirname "$REAL_PATH")"
2121-CATEGORY="git_scripts"
2222-2323-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
2424-HELP_FILE="$(basename "$0" .sh)_help.sh"
2525-2626-UTILS_DIR="$PARENT_DIR/utils"
2727-2828-# Import necessary variables and functions
2929-source "$UTILS_DIR/check_git.sh"
3030-source "$UTILS_DIR/setup_git.sh"
3131-source "$UTILS_DIR/check_sudo.sh"
3232-source "$UTILS_DIR/colors.sh"
3333-source "$UTILS_DIR/usage.sh"
3434-3535-# Import help file
3636-source "$HELPS_DIR/$HELP_FILE"
3737-3838-# Usage function to display help
3939-function usage() {
4040- show_help "Usage" "${gcb_arguments[@]}"
4141- show_help "Description" "${gcb_descriptions[@]}"
4242- show_help "Options" "${gcb_options[@]}"
4343- show_extra "${gcb_extras[@]}"
4444- exit 0
4545-}
4646-4747-# Check if --help is the first argument
4848-[ "$1" = "--help" ] && usage
4949-5050-# prompt for sudo
5151-# password if required
5252-allow_sudo
5353-5454-# Setting up git
5555-setup_git
5656-5757-# Call gcb function
5858-gcb
-52
git_scripts/gdf.sh
···11-#!/bin/bash
22-33-function gdf {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !";
66- return 0
77- fi
88-99- git diff ${1:-}
1010-}
1111-1212-# Resolve the full path to the script's directory
1313-REAL_PATH="$(dirname "$(readlink -f "$0")")"
1414-PARENT_DIR="$(dirname "$REAL_PATH")"
1515-CATEGORY="git_scripts"
1616-1717-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
1818-HELP_FILE="$(basename "$0" .sh)_help.sh"
1919-2020-UTILS_DIR="$PARENT_DIR/utils"
2121-2222-# Import necessary variables and functions
2323-source "$UTILS_DIR/check_git.sh"
2424-source "$UTILS_DIR/setup_git.sh"
2525-source "$UTILS_DIR/check_sudo.sh"
2626-source "$UTILS_DIR/colors.sh"
2727-source "$UTILS_DIR/usage.sh"
2828-2929-# Import help file
3030-source "$HELPS_DIR/$HELP_FILE"
3131-3232-# Usage function to display help
3333-function usage {
3434- show_help "Usage" "${gdf_arguments[@]}"
3535- show_help "Description" "${gdf_descriptions[@]}"
3636- show_help "Options" "${gdf_options[@]}"
3737- show_extra "${gdf_extras[@]}"
3838- exit 0
3939-}
4040-4141-# Check if --help is the first argument
4242-[ "$1" = "--help" ] && usage
4343-4444-# prompt for sudo
4545-# password if required
4646-allow_sudo
4747-4848-# Setting up git
4949-setup_git
5050-5151-# Call gdf function
5252-gdf "$@"
-84
git_scripts/glc.sh
···11-#!/bin/bash
22-33-function glc {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !";
66- return 0
77- fi
88-99- has_commits=$(git log > /dev/null 2>&1 && echo "true" || echo "false")
1010-1111- if [ "$has_commits" = "false" ]; then
1212- echo "${BOLD} Sorry, no commits yet inside this repo !";
1313- return 0
1414- fi
1515-1616- repo_name=$(basename "$(git rev-parse --show-toplevel)")
1717- current_branch=$(git branch | awk '/\*/ {print $2}');
1818- commits_num=$(git log --oneline | wc -l);
1919- last_commit=$(git log --format="%H" -n 1);
2020- last_commit_message=$(git show --format=%B -s "$last_commit" | head -n 1);
2121- last_commit_author=$(git log --format='%an' -n 1)
2222- current_user=$(git config user.name)
2323- commits_done_today=$(git log --oneline --since="$(date +"%Y-%m-%d 00:00:00")" --author="$current_user" | wc -l)
2424- commits_contrib_today=$(git log --oneline --since="$(date +"%Y-%m-%d 00:00:00")" --author="$last_commit_author" | wc -l)
2525-2626- [ $commits_num -le 1 ] && commit_text="commit" || commit_text="commits";
2727- [ $commits_done_today -le 1 ] && commit_done_text="commit" || commit_done_text="commits";
2828- [ $commits_contrib_today -le 1 ] && commit_contrib_text="commit" || commit_contrib_text="commits";
2929- [ $commits_done_today -gt 0 ] &&
3030- commit_done="${RESET_COLOR}Including ${LIGHT_BLUE}$commits_done_today $commit_done_text ${RESET_COLOR}by ${GREEN}$current_user ${RESET_COLOR}today" ||
3131- commit_done="${RESET_COLOR}Including ${LIGHT_BLUE}$commits_contrib_today $commit_contrib_text ${RESET_COLOR}by ${GREEN}$last_commit_author ${RESET_COLOR}today"
3232-3333- if [ "$1" = "show" ]; then
3434- git log --oneline --no-decorate;
3535- return 0
3636- fi
3737-3838- echo "${BOLD}${LIGHT_BLUE} $repo_name ${RESET_COLOR}has ${LIGHT_BLUE}$commits_num $commit_text ";
3939- echo " $commit_done";
4040- echo "${BOLD}${RESET_COLOR} Last Commit on ${GREEN}$current_branch ${RESET_COLOR}: $last_commit_message";
4141- echo
4242-}
4343-4444-# Resolve the full path to the script's directory
4545-REAL_PATH="$(dirname "$(readlink -f "$0")")"
4646-PARENT_DIR="$(dirname "$REAL_PATH")"
4747-CATEGORY="git_scripts"
4848-4949-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
5050-HELP_FILE="$(basename "$0" .sh)_help.sh"
5151-5252-UTILS_DIR="$PARENT_DIR/utils"
5353-5454-# Import necessary variables and functions
5555-source "$UTILS_DIR/check_git.sh"
5656-source "$UTILS_DIR/setup_git.sh"
5757-source "$UTILS_DIR/check_sudo.sh"
5858-source "$UTILS_DIR/colors.sh"
5959-source "$UTILS_DIR/usage.sh"
6060-6161-# Import help file
6262-source "$HELPS_DIR/$HELP_FILE"
6363-6464-# Usage function to display help
6565-function usage {
6666- show_help "Usage" "${glc_arguments[@]}"
6767- show_help "Description" "${glc_descriptions[@]}"
6868- show_help "Options" "${glc_options[@]}"
6969- show_extra "${glc_extras[@]}"
7070- exit 0
7171-}
7272-7373-# Check if --help is the first argument
7474-[ "$1" = "--help" ] && usage
7575-7676-# prompt for sudo
7777-# password if required
7878-allow_sudo
7979-8080-# Setting up git
8181-setup_git
8282-8383-# Call glc function
8484-glc "$@"
-71
git_scripts/gmb.sh
···11-#!/bin/bash
22-33-function gmb {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if [ $# -eq 0 ]; then
1010- echo "${BOLD} Fatal ! Specify the Branch to merge to $current_branch"
1111- return 0
1212- fi
1313-1414- current_branch=$(git branch | awk '/\*/ {print $2}')
1515-1616- # check if the branch doesn't exist
1717- if ! is_a_git_branch "$1"; then
1818- echo "${BOLD} Fatal ! $1 is a Non Existing branch "
1919- return 0
2020- fi
2121-2222- if [ "$current_branch" = "$1" ]; then
2323- echo "${BOLD} Fatal ! Cannot Merge Identical Branch "
2424- return 0
2525- fi
2626-2727- git merge "$1"
2828-}
2929-3030-# Resolve the full path to the script's directory
3131-REAL_PATH="$(dirname "$(readlink -f "$0")")"
3232-PARENT_DIR="$(dirname "$REAL_PATH")"
3333-CATEGORY="git_scripts"
3434-3535-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3636-HELP_FILE="$(basename "$0" .sh)_help.sh"
3737-3838-UTILS_DIR="$PARENT_DIR/utils"
3939-4040-# Import necessary variables and functions
4141-source "$UTILS_DIR/check_git.sh"
4242-source "$UTILS_DIR/check_branch.sh"
4343-source "$UTILS_DIR/setup_git.sh"
4444-source "$UTILS_DIR/check_sudo.sh"
4545-source "$UTILS_DIR/colors.sh"
4646-source "$UTILS_DIR/usage.sh"
4747-4848-# Import help file
4949-source "$HELPS_DIR/$HELP_FILE"
5050-5151-# Usage function to display help
5252-function usage {
5353- show_help "Usage" "${gmb_arguments[@]}"
5454- show_help "Description" "${gmb_descriptions[@]}"
5555- show_help "Options" "${gmb_options[@]}"
5656- show_help "Examples" "${gmb_extras[@]}"
5757- exit 0
5858-}
5959-6060-# Check if --help is the first argument
6161-[ "$1" = "--help" ] && usage
6262-6363-# prompt for sudo
6464-# password if required
6565-allow_sudo
6666-6767-# Setting up git
6868-setup_git
6969-7070-# Call gmb function
7171-gmb "$@"
-64
git_scripts/gnm.sh
···11-#!/bin/bash
22-33-function gnm {
44- if ! is_a_git_repo; then
55- echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if [ $# -eq 0 ]; then
1010- echo "${BOLD}${RESET_COLOR} Please pass the new name of '$current_branch' branch as argument "
1111- return 0
1212- fi
1313-1414- current_branch=$(git branch | awk '/\*/ {print $2}')
1515-1616- if [ $# -eq 1 ]; then
1717- git branch -M $current_branch "$1"
1818- return 0
1919- fi
2020-2121- echo "${BOLD}${RESET_COLOR} Usage : gnm new_name_of_the_branch"
2222-}
2323-2424-# Resolve the full path to the script's directory
2525-REAL_PATH="$(dirname "$(readlink -f "$0")")"
2626-PARENT_DIR="$(dirname "$REAL_PATH")"
2727-CATEGORY="git_scripts"
2828-2929-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3030-HELP_FILE="$(basename "$0" .sh)_help.sh"
3131-3232-UTILS_DIR="$PARENT_DIR/utils"
3333-3434-# Import necessary variables and functions
3535-source "$UTILS_DIR/check_git.sh"
3636-source "$UTILS_DIR/setup_git.sh"
3737-source "$UTILS_DIR/check_sudo.sh"
3838-source "$UTILS_DIR/colors.sh"
3939-source "$UTILS_DIR/usage.sh"
4040-4141-# Import help file
4242-source "$HELPS_DIR/$HELP_FILE"
4343-4444-# Usage function to display help
4545-function usage {
4646- show_help "Usage" "${gnm_arguments[@]}"
4747- show_help "Description" "${gnm_descriptions[@]}"
4848- show_help "Options" "${gnm_options[@]}"
4949- show_help "Examples" "${gnm_extras[@]}"
5050- exit 0
5151-}
5252-5353-# Check if --help is the first argument
5454-[ "$1" = "--help" ] && usage
5555-5656-# prompt for sudo
5757-# password if required
5858-allow_sudo
5959-6060-# Setting up git
6161-setup_git
6262-6363-# Call gnm function
6464-gnm "$@"
-77
git_scripts/gpl.sh
···11-#!/bin/bash
22-33-function gpl {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- # check if it has a remote to push
1010- if ! has_remote; then
1111- repo_name=$(basename "$(git rev-parse --show-toplevel)")
1212- echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}has ${RED}no remote"
1313- return 0
1414- fi
1515-1616- repo_url=$(git config --get remote.origin.url)
1717- repo_name="$(echo "$repo_url" | awk -F '/' '{print $NF}' | sed 's/.git$//')"
1818- current_branch=$(git branch | awk '/\*/ {print $2}')
1919- is_remote_branch=$(git branch -r | grep "origin/$current_branch")
2020-2121- # check if the current branch has remote
2222- if [ -z "$is_remote_branch" ]; then
2323- echo "${BOLD} The remote repo ${LIGHT_BLUE}$repo_name" \
2424- "${RESET_COLOR}has no branch named ${GREEN}$current_branch ${RESET_COLOR}!"
2525- return 0
2626- fi
2727-2828- # Pull changes from remote branch
2929- git pull origin $current_branch
3030-}
3131-3232-# Resolve the full path to the script's directory
3333-REAL_PATH="$(dirname "$(readlink -f "$0")")"
3434-PARENT_DIR="$(dirname "$REAL_PATH")"
3535-CATEGORY="git_scripts"
3636-3737-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3838-HELP_FILE="$(basename "$0" .sh)_help.sh"
3939-4040-UTILS_DIR="$PARENT_DIR/utils"
4141-4242-# Import necessary variables and functions
4343-source "$UTILS_DIR/check_connection.sh"
4444-source "$UTILS_DIR/check_remote.sh"
4545-source "$UTILS_DIR/check_git.sh"
4646-source "$UTILS_DIR/setup_git.sh"
4747-source "$UTILS_DIR/check_sudo.sh"
4848-source "$UTILS_DIR/colors.sh"
4949-source "$UTILS_DIR/usage.sh"
5050-5151-# Import help file
5252-source "$HELPS_DIR/$HELP_FILE"
5353-5454-# Usage function to display help
5555-function usage {
5656- show_help "Usage" "${gpl_arguments[@]}"
5757- show_help "Description" "${gpl_descriptions[@]}"
5858- show_help "Options" "${gpl_options[@]}"
5959- show_extra "${gpl_extras[@]}"
6060- exit 0
6161-}
6262-6363-# Check if --help is the first argument
6464-[ "$1" = "--help" ] && usage
6565-6666-# prompt for sudo
6767-# password if required
6868-allow_sudo
6969-7070-# Setting up git
7171-setup_git
7272-7373-# Check for internet connectivity to GitHub
7474-check_connection
7575-7676-# Call gpl function
7777-gpl
-69
git_scripts/gpsh.sh
···11-#!/bin/bash
22-33-function gpsh {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- # Get the repo name
1010- repo_name=$(basename "$(git rev-parse --show-toplevel)")
1111-1212- # check if it has a remote to push
1313- if ! has_remote; then
1414- echo "${BOLD} The repo ${LIGHT_BLUE}$repo_name ${RESET_COLOR}has ${RED}no remote"
1515- return 0
1616- fi
1717-1818- current_branch=$(git branch | awk '/\*/ {print $2}')
1919-2020- # Push changes to remote branch
2121- git push origin $current_branch
2222-}
2323-2424-# Resolve the full path to the script's directory
2525-REAL_PATH="$(dirname "$(readlink -f "$0")")"
2626-PARENT_DIR="$(dirname "$REAL_PATH")"
2727-CATEGORY="git_scripts"
2828-2929-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
3030-HELP_FILE="$(basename "$0" .sh)_help.sh"
3131-3232-UTILS_DIR="$PARENT_DIR/utils"
3333-3434-# Import necessary variables and functions
3535-source "$UTILS_DIR/check_connection.sh"
3636-source "$UTILS_DIR/check_remote.sh"
3737-source "$UTILS_DIR/check_git.sh"
3838-source "$UTILS_DIR/setup_git.sh"
3939-source "$UTILS_DIR/check_sudo.sh"
4040-source "$UTILS_DIR/colors.sh"
4141-source "$UTILS_DIR/usage.sh"
4242-4343-# Import help file
4444-source "$HELPS_DIR/$HELP_FILE"
4545-4646-# Usage function to display help
4747-function usage {
4848- show_help "Usage" "${gpsh_arguments[@]}"
4949- show_help "Description" "${gpsh_descriptions[@]}"
5050- show_help "Options" "${gpsh_options[@]}"
5151- show_help "${gpsh_extras[@]}"
5252- exit 0
5353-}
5454-5555-# Check if --help is the first argument
5656-[ "$1" = "--help" ] && usage
5757-5858-# prompt for sudo
5959-# password if required
6060-allow_sudo
6161-6262-# Setting up git
6363-setup_git
6464-6565-# Check for internet connectivity to GitHub
6666-check_connection
6767-6868-# Call gpsh function
6969-gpsh
-76
git_scripts/grst.sh
···11-#!/bin/bash
22-33-function grst {
44- if ! is_a_git_repo; then
55- echo "${BOLD}${RESET_COLOR} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- if [ $# -eq 0 ]; then
1010- git checkout -- .
1111- return 0
1212- fi
1313-1414- if [ -f "$1" ]; then
1515- git reset "$1"
1616- return 0
1717- fi
1818-1919- if [ $1 = "cmt" ]; then
2020- git reset --soft HEAD~1
2121- return 0
2222- fi
2323-2424- # Loop through each argument and check if it's a file
2525- for arg in "$@"; do
2626- if [ ! -f "$arg" ]; then
2727- echo "${BOLD}${RESET_COLOR} Sorry, only restore file(s). ${LIGHT_BLUE}'$arg'${RESET_COLOR} is not a valid file."
2828- exit 1
2929- fi
3030- done
3131-3232- # If all arguments are valid files, restore them
3333- git restore "$@"
3434-}
3535-3636-# Resolve the full path to the script's directory
3737-REAL_PATH="$(dirname "$(readlink -f "$0")")"
3838-PARENT_DIR="$(dirname "$REAL_PATH")"
3939-CATEGORY="git_scripts"
4040-4141-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
4242-HELP_FILE="$(basename "$0" .sh)_help.sh"
4343-4444-UTILS_DIR="$PARENT_DIR/utils"
4545-4646-# Import necessary variables and functions
4747-source "$UTILS_DIR/check_git.sh"
4848-source "$UTILS_DIR/setup_git.sh"
4949-source "$UTILS_DIR/check_sudo.sh"
5050-source "$UTILS_DIR/colors.sh"
5151-source "$UTILS_DIR/usage.sh"
5252-5353-# Import help file
5454-source "$HELPS_DIR/$HELP_FILE"
5555-5656-# Usage function to display help
5757-function usage {
5858- show_help "Usage" "${grst_arguments[@]}"
5959- show_help "Description" "${grst_descriptions[@]}"
6060- show_help "Options" "${grst_options[@]}"
6161- show_extra "${grst_extras[@]}"
6262- exit 0
6363-}
6464-6565-# Check if --help is the first argument
6666-[ "$1" = "--help" ] && usage
6767-6868-# prompt for sudo
6969-# password if required
7070-allow_sudo
7171-7272-# Setting up git
7373-setup_git
7474-7575-# Call grst function
7676-grst "$@"
-53
git_scripts/gst.sh
···11-#!/bin/bash
22-33-function gst {
44- if ! is_a_git_repo; then
55- echo "${BOLD} This won't work, you are not in a git repo !"
66- return 0
77- fi
88-99- # Get the status
1010- git status -s
1111-}
1212-1313-# Resolve the full path to the script's directory
1414-REAL_PATH="$(dirname "$(readlink -f "$0")")"
1515-PARENT_DIR="$(dirname "$REAL_PATH")"
1616-CATEGORY="git_scripts"
1717-1818-HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
1919-HELP_FILE="$(basename "$0" .sh)_help.sh"
2020-2121-UTILS_DIR="$PARENT_DIR/utils"
2222-2323-# Import necessary variables and functions
2424-source "$UTILS_DIR/check_git.sh"
2525-source "$UTILS_DIR/setup_git.sh"
2626-source "$UTILS_DIR/check_sudo.sh"
2727-source "$UTILS_DIR/colors.sh"
2828-source "$UTILS_DIR/usage.sh"
2929-3030-# Import help file
3131-source "$HELPS_DIR/$HELP_FILE"
3232-3333-# Usage function to display help
3434-function usage {
3535- show_help "Usage" "${gst_arguments[@]}"
3636- show_help "Description" "${gst_descriptions[@]}"
3737- show_help "Options" "${gst_options[@]}"
3838- show_extra "${gst_extras[@]}"
3939- exit 0
4040-}
4141-4242-# Check if --help is the first argument
4343-[ "$1" = "--help" ] && usage
4444-4545-# prompt for sudo
4646-# password if required
4747-allow_sudo
4848-4949-# Setting up git
5050-setup_git
5151-5252-# Call gst function
5353-gst
···19192020# Extra help
2121ghnm_extras=(
2222- "ghnm source_controller"
2323- "This will rename the current repo to ${LIGHT_BLUE}source_controller ${RESET}"
2222+ "ghnm source.controller"
2323+ "This will rename the current repo to ${LIGHT_BLUE}source.controller ${RESET}"
2424)
···3838source "$UTILS_DIR/colors.sh"
39394040# Directories for source and target
4141-GIT_SCRIPTS_DIR="$PARENT_DIR/git_scripts"
4242-GH_SCRIPTS_DIR="$PARENT_DIR/gh_scripts"
4141+git.scripts_DIR="$PARENT_DIR/git.scripts"
4242+gh.scripts_DIR="$PARENT_DIR/gh.scripts"
43434444-HELP_GIT_SCRIPTS_DIR="$PARENT_DIR/helps/git_scripts"
4545-HELP_GH_SCRIPTS_DIR="$PARENT_DIR/helps/gh_scripts"
4444+HELP_git.scripts_DIR="$PARENT_DIR/helps/git.scripts"
4545+HELP_gh.scripts_DIR="$PARENT_DIR/helps/gh.scripts"
46464747# Create the directories if they don't exist
4848-mkdir -p "$HELP_GIT_SCRIPTS_DIR"
4949-mkdir -p "$HELP_GH_SCRIPTS_DIR"
4848+mkdir -p "$HELP_git.scripts_DIR"
4949+mkdir -p "$HELP_gh.scripts_DIR"
50505151# Function to write help file content
5252function write_help_file_content {
···7878EOL
7979}
80808181-# Create help files for git_scripts
8181+# Create help files for git.scripts
8282printf "\n${BOLD} Git Scripts Helps...${RESET}\n"
8383-create_help_files "$GIT_SCRIPTS_DIR" "$HELP_GIT_SCRIPTS_DIR"
8383+create_help_files "$git.scripts_DIR" "$HELP_git.scripts_DIR"
84848585echo
86868787-# Create help files for gh_scripts
8787+# Create help files for gh.scripts
8888printf "${BOLD} Gh Scripts Helps...${RESET}\n"
8989-create_help_files "$GH_SCRIPTS_DIR" "$HELP_GH_SCRIPTS_DIR"8989+create_help_files "$gh.scripts_DIR" "$HELP_gh.scripts_DIR"
+2-2
setup/install.sh
···77repo_source=$(git rev-parse --show-toplevel)
8899# Define paths to script directories
1010-git_scripts_path="$repo_source/git_scripts"
1111-gh_scripts_path="$repo_source/gh_scripts"
1010+git_scripts_path="$repo_source/git.scripts"
1111+gh_scripts_path="$repo_source/gh.scripts"
12121313# Function to extract script name without the .sh extension
1414function get_script_name {
+2-2
setup/uninstall.sh
···77repo_source=$(git rev-parse --show-toplevel)
8899# Define paths to script directories
1010-git_scripts_path="$repo_source/git_scripts"
1111-gh_scripts_path="$repo_source/gh_scripts"
1010+git_scripts_path="$repo_source/git.scripts"
1111+gh_scripts_path="$repo_source/gh.scripts"
12121313# Function to extract script name without the .sh extension
1414function get_script_name {