Added gpush.
This commit is contained in:
94
ginit
Executable file
94
ginit
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
# ---------------------------------------------------------------------------
|
||||
# ginit – Initialise a new Git repository and add a remote origin
|
||||
#
|
||||
# Usage:
|
||||
# ./ginit [group] [project]
|
||||
#
|
||||
# group – (optional) Git organisation / group name. If omitted the script
|
||||
# tries to infer it from the current directory.
|
||||
# project – (optional) Repository name. If omitted, the script derives it
|
||||
# from the current directory name (stripping any leading prefix
|
||||
# before a dot, e.g. “foo.bar” → “bar”).
|
||||
#
|
||||
# The script will:
|
||||
# 1. Load the base Git URL from $HOME/.config/ginit-bash-url (prompting
|
||||
# the user the first time and persisting the value).
|
||||
# 2. Verify a README.md exists in the current directory.
|
||||
# 3. Build the remote URL: $GIT_BASEURL/$group/$project.git
|
||||
# 4. Prompt before running: git init && git remote add origin <repo>
|
||||
#
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Resolve GIT_BASEURL – always from the config file, never from the environment
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Path to the persisted config file
|
||||
GIT_BASEURL_CFG="$HOME/.config/ginit-bash-url"
|
||||
|
||||
# If the config file exists, read the URL from it
|
||||
if [ -f "$GIT_BASEURL_CFG" ]; then
|
||||
GIT_BASEURL=$(cat "$GIT_BASEURL_CFG")
|
||||
fi
|
||||
|
||||
# If we still don’t have a value, ask the user and persist it
|
||||
if [ -z "$GIT_BASEURL" ]; then
|
||||
read -p "Enter the Git base URL (e.g. https://your.git-domain.com): " GIT_BASEURL
|
||||
# Ensure the config directory exists
|
||||
mkdir -p "$(dirname "$GIT_BASEURL_CFG")"
|
||||
echo "$GIT_BASEURL" > "$GIT_BASEURL_CFG"
|
||||
echo "Saved Git base URL to $GIT_BASEURL_CFG"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Validate that we now have a value
|
||||
# ---------------------------------------------------------------------------
|
||||
if [ -z "$GIT_BASEURL" ]; then
|
||||
printf "Required git-base-url not set.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# clear
|
||||
|
||||
if [ -d .git ]; then
|
||||
echo 'GIT repo is already initialized!'
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -f README.md ]; then
|
||||
echo 'README.md is required.'
|
||||
exit
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Existing argument handling (unchanged)
|
||||
# ---------------------------------------------------------------------------
|
||||
if [ $1 ]; then
|
||||
group=$1
|
||||
if [ $2 ]; then
|
||||
project=$2
|
||||
else
|
||||
project=${PWD##*/}
|
||||
project=${project/*\./}
|
||||
project=${PWD##*/}
|
||||
group=${project/\.*/}
|
||||
group=${group/app/webapp}
|
||||
project=${project/*\./}
|
||||
fi
|
||||
fi
|
||||
|
||||
# Rock
|
||||
repo="$GIT_BASEURL/$group/$project.git"
|
||||
|
||||
# Roll
|
||||
echo "Git Repo Init:"
|
||||
echo "--------------"
|
||||
echo "Working dir: $PWD"
|
||||
echo "Repository : $repo"
|
||||
echo ""
|
||||
echo "Press enter to run \$ git init && git remote add origin [Repo]"
|
||||
echo "or press Ctrl‑C to cancel."
|
||||
|
||||
# Go go go
|
||||
read confirm2
|
||||
git init && git remote add origin $repo
|
||||
96
gpush
Executable file
96
gpush
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage notes for gpush script
|
||||
#
|
||||
# This script automates the process of committing and pushing changes to a git repository.
|
||||
# It also supports creating and pushing tags.
|
||||
#
|
||||
# Features:
|
||||
# - Automatically detects if you're in a git repository
|
||||
# - Shows current repository info (URL, tag, branch)
|
||||
# - Allows custom commit messages
|
||||
# - Supports custom remote and branch targets
|
||||
# - Option to create and push tags
|
||||
#
|
||||
# Usage:
|
||||
# ./gpush [default_commit_message]
|
||||
#
|
||||
# Examples:
|
||||
# ./gpush # Run with no default commit message
|
||||
# ./gpush "Fixed bug in login flow" # Run with a default commit message
|
||||
#
|
||||
# The script will prompt for:
|
||||
# - Commit message (uses default if provided, can be changed)
|
||||
# - Remote name (defaults to 'origin')
|
||||
# - Branch name (defaults to current branch)
|
||||
# - Tag name (optional, no tag created if left blank)
|
||||
#
|
||||
# After confirming the actions, it will:
|
||||
# 1. Add all changes (git add .)
|
||||
# 2. Commit with your message (git commit -am "message")
|
||||
# 3. Push to your specified remote/branch (git push remote branch)
|
||||
# 4. Create and push tag if specified
|
||||
|
||||
# Check if the current directory is a git repository
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
echo "Error: Not a git repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Gather info
|
||||
# Note: not capturing git log message because of colour loss.
|
||||
repo=$(git remote get-url origin)
|
||||
currTag=$(git describe --tags)
|
||||
currBranch=$(git rev-parse --abbrev-ref HEAD) # $(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
|
||||
inputCommit=$1
|
||||
if [ -z $currBranch ]
|
||||
then
|
||||
currBranch='master'
|
||||
fi
|
||||
|
||||
echo "Commit Changes and Push to Git Repository"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
git log -1
|
||||
echo ""
|
||||
echo "Repository : $repo"
|
||||
echo "Current Tag: $currTag"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
echo "Commands will be executed in batch at the after confirmation."
|
||||
echo "Press Ctrl-C at any point to cancel all actions."
|
||||
echo ""
|
||||
read -p "Input commit message (default: $inputCommit): " commit
|
||||
read -p "Input remote (default: origin): " remote
|
||||
read -p "Input branch (current: $currBranch): " branch
|
||||
read -p "Input tag (default: no tag): " tag
|
||||
remote=${remote:-origin}
|
||||
branch=${branch:-$currBranch}
|
||||
commit=${commit:-$inputCommit}
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
echo "Prepared command(s):"
|
||||
echo ""
|
||||
if [ "$commit" ]
|
||||
then
|
||||
echo " git add .";
|
||||
echo " git commit -am \"$commit\""
|
||||
fi
|
||||
echo " git push $remote $branch";
|
||||
if [ "$tag" ]
|
||||
then
|
||||
echo " git tag \"$tag\""
|
||||
echo " git push $remote --tags"
|
||||
fi
|
||||
echo ""
|
||||
echo "Enter to execute:"
|
||||
read confirm
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
if [ "$commit" ]
|
||||
then
|
||||
git add .
|
||||
git commit -am "$commit"
|
||||
git push "$remote" "$branch"
|
||||
if [ "$tag" ]; then
|
||||
git tag "$tag"
|
||||
git push "$remote" "$tag"
|
||||
fi
|
||||
#git push $remote $branch --tags
|
||||
fi
|
||||
@@ -33,7 +33,7 @@ alias dfnet='df -t fuseblk -t cifs -t nfs4 -h'
|
||||
alias du='du -h'
|
||||
alias du0='du -h -d 0'
|
||||
alias du1='du -h -d 1'
|
||||
alias permissionsreset='find ./ -type d -exec chmod 775 {} \; && find ./ -type f -exec chmod 664 {} \;'
|
||||
# alias permissionsreset='find ./ -type d -exec chmod 775 {} \; && find ./ -type f -exec chmod 664 {} \;' # Replaced by permissionsreset script
|
||||
|
||||
# Logs
|
||||
# alias syslog='sudo tail -F -n 32 -s 5 /var/log/syslog' # Replaced by syslog script
|
||||
@@ -42,7 +42,11 @@ alias a2logs='multitail /var/log/apache2/access.log /var/log/apache2/error.log'
|
||||
alias a2logs='multitail /var/log/apache2/access.log /var/log/apache2/error.log'
|
||||
alias nxlogs='multitail /var/log/nginx/access.log /var/log/nginx/error.log'
|
||||
|
||||
# Web Roots
|
||||
# Common Dirs
|
||||
alias ws='cd /mnt/workspace'
|
||||
alias ww='cd /mnt/workspace/www'
|
||||
alias www='cd /mnt/workspace/www'
|
||||
alias wa='cd /mnt/workspace/webapp'
|
||||
alias html='cd /var/www/html'
|
||||
alias webapps='cd /var/www/webapps'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user