initial commit
This commit is contained in:
commit
b3136b4d32
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist/
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Zinovyev Ivan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
15
README.md
Normal file
15
README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# gt bash script 0.1
|
||||
|
||||
A helper for git functions I really miss, like merging the lastest develop / main branch into my current branch, showing what I (or someone else) has checked in over the time, etc.
|
||||
|
||||
## Changelog
|
||||
|
||||
__0.1__
|
||||
|
||||
* Created the initial bash script
|
||||
* Added config functions (for future use)
|
||||
* Added commands pull, tag, mine, pullAndMerge
|
||||
|
||||
## Sources
|
||||
|
||||
-
|
||||
18
src/functions/buildCheckBuildSystem.sh
Normal file
18
src/functions/buildCheckBuildSystem.sh
Normal file
@ -0,0 +1,18 @@
|
||||
buildCheckBuildSystem() {
|
||||
if [ -f "package.json" ]; then
|
||||
BUILD_SYSTEM=$NPM
|
||||
elif [ -f "gulpfile.js" ]; then
|
||||
BUILD_SYSTEM=$GULP
|
||||
elif [ -f "build.gradle" ]; then
|
||||
BUILD_SYSTEM=$GRADLE
|
||||
elif [ -f "pom.xml" ]; then
|
||||
BUILD_SYSTEM=$MAVEN
|
||||
fi
|
||||
|
||||
# when no build system could be found, print a the help / usage (if not set to ignore)
|
||||
if [ "$1" != $IGNORE_ERROR ] && [ "$BUILD_SYSTEM" == "" ]; then
|
||||
echo "Could not find any supported build systems"
|
||||
echo ""
|
||||
help
|
||||
fi
|
||||
}
|
||||
28
src/functions/configInit.sh
Normal file
28
src/functions/configInit.sh
Normal file
@ -0,0 +1,28 @@
|
||||
configInit() {
|
||||
if [ ! -f "${DEV_CONFIG_FILE}" ]; then
|
||||
echo Could not find any config file, creating a file for you to fill in the values in ${DEV_CONFIG_FILE}
|
||||
if [ ! -d "${DEV_CONFIG_FILE_PATH}" ]; then
|
||||
echo "Config directory '${DEV_CONFIG_FILE_PATH}' does not exist yet, creating..."
|
||||
mkdir -p ${DEV_CONFIG_FILE_PATH}
|
||||
fi
|
||||
if [ -f "/IMAGE_NAME" ]; then
|
||||
# || [ `whoami` = 'dev' ]; then
|
||||
MODE=devcontainer
|
||||
GRADLE_DEFAULT=wrapper
|
||||
else
|
||||
MODE=host
|
||||
GRADLE_DEFAULT=normal
|
||||
fi
|
||||
|
||||
cat <<END >${DEV_CONFIG_FILE}
|
||||
# this file was created by dev script by Manuel Manhart
|
||||
# it is now in your hands and will not be changed by scripts anymore
|
||||
|
||||
MODE=$MODE
|
||||
LIFERAY_DOCKER=(
|
||||
"TODO" # change this to the real path
|
||||
)
|
||||
END
|
||||
|
||||
fi
|
||||
}
|
||||
11
src/functions/configPrint.sh
Normal file
11
src/functions/configPrint.sh
Normal file
@ -0,0 +1,11 @@
|
||||
# reads the configuration file where the docker container names are saved
|
||||
configPrint() {
|
||||
echo ""
|
||||
echo "Configuration file:"
|
||||
cat ${DEV_CONFIG_FILE} | while read line
|
||||
do
|
||||
echo "$line"
|
||||
done
|
||||
echo ""
|
||||
echo "Version: $SCRIPT_VERSION"
|
||||
}
|
||||
23
src/functions/configRead.sh
Normal file
23
src/functions/configRead.sh
Normal file
@ -0,0 +1,23 @@
|
||||
# reads the configuration file where the docker container names are saved
|
||||
configRead() {
|
||||
if [ -f "${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}" ]; then
|
||||
echo found config file in ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}
|
||||
source ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}
|
||||
|
||||
# Read common vars from the config file
|
||||
# the incantation here ensures (by env) that only key=value pairs are present
|
||||
# then declare-ing the result puts those vars in our environment
|
||||
# declare $(env -i `cat ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}` >/dev/null 2>&1) >/dev/null 2>&1
|
||||
|
||||
# IFS=$'\n' read -d '' -r -a LIFERAY_DOCKER < ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}
|
||||
fi
|
||||
# as fallback search in script home directory
|
||||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
if [ -f "${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}" ]; then
|
||||
echo found config file in ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}
|
||||
|
||||
declare $(env -i `cat ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}` >/dev/null 2>&1)
|
||||
# source ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}
|
||||
# IFS=$'\n' read -d '' -r -a LIFERAY_DOCKER < ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}
|
||||
fi
|
||||
}
|
||||
7
src/functions/gitPull.sh
Normal file
7
src/functions/gitPull.sh
Normal file
@ -0,0 +1,7 @@
|
||||
gitPull() {
|
||||
if [ -f ".git" ]; then
|
||||
git pull
|
||||
else
|
||||
echo "Seems not to be a git repo"
|
||||
fi
|
||||
}
|
||||
17
src/functions/gitTag.sh
Normal file
17
src/functions/gitTag.sh
Normal file
@ -0,0 +1,17 @@
|
||||
gitTag() {
|
||||
if [ -n "$2" ]; then
|
||||
git pull >/dev/null
|
||||
local message=""
|
||||
if [ -n "$3" ]; then
|
||||
message="-m $3"
|
||||
fi
|
||||
git tag -a $2 $message
|
||||
git push --tags
|
||||
else
|
||||
git fetch origin >/dev/null
|
||||
echo "Existing tags"
|
||||
git tag
|
||||
echo ""
|
||||
echo "If you want to create a new tag, just provide a tag version"
|
||||
fi
|
||||
}
|
||||
27
src/functions/help.sh
Normal file
27
src/functions/help.sh
Normal file
@ -0,0 +1,27 @@
|
||||
help() {
|
||||
local progName=$(echo "$0" | rev | cut -d'/' -f1 | rev)
|
||||
|
||||
cat <<-END
|
||||
$progName is a tool for makeing git easier to use.
|
||||
|
||||
Usage:
|
||||
$progName [options]
|
||||
|
||||
The options are:
|
||||
need a param (you can combine like ubd)
|
||||
config init ... for creating a config file (if none exists yet - automatically checked)
|
||||
config print ... for printing the config file content
|
||||
|
||||
mine [USER] ... fetches the log of either the given user or the one defined in git config
|
||||
pullAndMerge BRANCH ... pulls the given branch and merges it into the current one (updating to latest develop / main)
|
||||
pull ... for pulling from git (not working?)
|
||||
tag NAME [MESSAGE] ... creates and pushes a new tag
|
||||
branch NAME ... creates a new branch (TODO)
|
||||
|
||||
help ... show this page
|
||||
|
||||
Version: $SCRIPT_VERSION
|
||||
END
|
||||
|
||||
exit
|
||||
}
|
||||
13
src/functions/mine.sh
Normal file
13
src/functions/mine.sh
Normal file
@ -0,0 +1,13 @@
|
||||
mine() {
|
||||
# fetch user from args
|
||||
local gitUser=$GIT_USER
|
||||
# Get the user defined in the local config
|
||||
if [ -z "$gitUser" ]; then
|
||||
gitUser=$(git config --get user.name)
|
||||
echo "Fetching user from git config: $gitUser"
|
||||
fi
|
||||
echo "Git user: $gitUser"
|
||||
|
||||
# get my commits
|
||||
git log --author="$gitUser"
|
||||
}
|
||||
36
src/functions/parseArgs.sh
Normal file
36
src/functions/parseArgs.sh
Normal file
@ -0,0 +1,36 @@
|
||||
parseArgs() {
|
||||
if [ -z "$1" ]; then
|
||||
help
|
||||
fi
|
||||
local setVariable=0
|
||||
local variableName=""
|
||||
|
||||
#echo "parsing args"
|
||||
for var in "$@"
|
||||
do
|
||||
#echo "DEBUG - arg[i]: '$var' - setVariable: $setVariable"
|
||||
if [ "$setVariable" == 0 ]; then
|
||||
variableName=""
|
||||
fi
|
||||
|
||||
if [ "$var" == "-h" ] || [ "$var" == "--help" ]; then
|
||||
help
|
||||
elif [ $setVariable -gt 0 ]; then
|
||||
#echo "Setting variables..."
|
||||
setVariable="$(($setVariable - 1))"
|
||||
if [ "$variableName" == "tag" ]; then
|
||||
TAG=$var
|
||||
#echo "DEBUG - Setting tag to '$var'"
|
||||
elif [ "$variableName" == "path" ]; then
|
||||
SOURCE_PATH=$var
|
||||
#echo "DEBUG - Setting source path to '$var'"
|
||||
fi
|
||||
elif [ "$var" == "-p" ] || [ "$var" == "--path" ]; then
|
||||
setVariable=1
|
||||
variableName="path"
|
||||
elif [ "$var" == "tag" ]; then
|
||||
setVariable=1
|
||||
variableName="tag"
|
||||
fi
|
||||
done
|
||||
}
|
||||
6
src/functions/parseArgs_mine.sh
Normal file
6
src/functions/parseArgs_mine.sh
Normal file
@ -0,0 +1,6 @@
|
||||
parseArgs_mine() {
|
||||
echo "Fetching user: $1"
|
||||
if [ -n "$1" ]; then
|
||||
GIT_USER=$1
|
||||
fi
|
||||
}
|
||||
9
src/functions/parseArgs_pullAndMerge.sh
Normal file
9
src/functions/parseArgs_pullAndMerge.sh
Normal file
@ -0,0 +1,9 @@
|
||||
parseArgs_pullAndMerge() {
|
||||
echo "Pulling and merging branch $1 into current one"
|
||||
if [ -z "$1" ]; then
|
||||
echo "ERROR: Argument BRANCH is missing"
|
||||
help pullAndMerge
|
||||
else
|
||||
GIT_BRANCH=$1
|
||||
fi
|
||||
}
|
||||
19
src/functions/preset.sh
Normal file
19
src/functions/preset.sh
Normal file
@ -0,0 +1,19 @@
|
||||
preset() {
|
||||
# not yet working
|
||||
# FIXME properties file not correctly read
|
||||
# FIXME how do we set multiple values in a simple properties file
|
||||
# TODO think about a better mechanism
|
||||
utilIsReadPropertiesFile ./.dev-presets presetOptions presetValues
|
||||
printf "presetOptions %s\n" "${presetOptions[@]}"
|
||||
printf "presetValues %s\n" "${presetValues[@]}"
|
||||
echo 'Please enter your choice: '
|
||||
local index=0
|
||||
for item in "${presetOptions[@]}"
|
||||
do
|
||||
echo ${index}. ${item}
|
||||
index="$((index + 1))"
|
||||
done
|
||||
read n
|
||||
echo "opt: $n"
|
||||
echo "presetValue: ${presetValues[$n]}"
|
||||
}
|
||||
12
src/functions/pullAndMerge.sh
Normal file
12
src/functions/pullAndMerge.sh
Normal file
@ -0,0 +1,12 @@
|
||||
pullAndMerge() {
|
||||
# fetch user from args
|
||||
local gitBranch=$GIT_BRANCH
|
||||
local currentBranch=$(git rev-parse --abbrev-ref HEAD)
|
||||
echo "current branch: $currentBranch"
|
||||
|
||||
# Update the current branch to the latest of the given branch
|
||||
git checkout $gitBranch
|
||||
git pull
|
||||
git checkout $currentBranch
|
||||
echo DEBUG: git merge $gitBranch
|
||||
}
|
||||
34
src/functions/runScript.sh
Normal file
34
src/functions/runScript.sh
Normal file
@ -0,0 +1,34 @@
|
||||
runScript() {
|
||||
# go to source path (if neccessary)
|
||||
pushd $SOURCE_PATH >/dev/null 2>&1
|
||||
local runFunctions=${@// /|}
|
||||
#echo "DEBUG - runFunctions: $runFunctions"
|
||||
|
||||
# in the execution there are in- and dependent tasks, this file ensures that everything
|
||||
# will be executed in a helpful way
|
||||
|
||||
if [[ "$runFunctions" = *"help"* ]]; then
|
||||
help
|
||||
fi
|
||||
# run config functions
|
||||
if [[ "$runFunctions" = *"config"* ]]; then
|
||||
if [[ "$runFunctions" = *"config init"* ]]; then
|
||||
configInit
|
||||
elif [[ "$runFunctions" = *"config print"* ]]; then
|
||||
configPrint
|
||||
exit
|
||||
elif [[ "$runFunctions" = *"config set"* ]]; then
|
||||
echo "Setting configurations is not yet supported"
|
||||
fi
|
||||
fi
|
||||
|
||||
local parseArgsFunc="parseArgs_$ACTION"
|
||||
local isParseArgsDefined=$(type -t $parseArgsFunc)
|
||||
if [ "function" == "$isParseArgsDefined" ]; then
|
||||
"$parseArgsFunc" "${@:2}"
|
||||
fi
|
||||
"$ACTION" "${@:2}"
|
||||
|
||||
# return to initial path (if neccessary)
|
||||
popd >/dev/null 2>&1
|
||||
}
|
||||
7
src/functions/utilIsExistingFile.sh
Normal file
7
src/functions/utilIsExistingFile.sh
Normal file
@ -0,0 +1,7 @@
|
||||
utilIsExistingFile() {
|
||||
if ls $1 1> /dev/null 2>&1; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
21
src/functions/utilIsReadPropertiesFile.sh
Normal file
21
src/functions/utilIsReadPropertiesFile.sh
Normal file
@ -0,0 +1,21 @@
|
||||
utilIsReadPropertiesFile() {
|
||||
local fileName=$1
|
||||
local keysName=$2
|
||||
local valuesName=$3
|
||||
local keys=()
|
||||
local values=()
|
||||
echo "reading properties file $1 into $2 and $3"
|
||||
if [ -n "$fileName" ]; then
|
||||
while IFS='=' read -r key value
|
||||
do
|
||||
key=$(echo $key | tr '.' '_')
|
||||
keys+=("$key")
|
||||
values+=("$value")
|
||||
# eval ${key}=\${value}
|
||||
done < "$fileName"
|
||||
fi
|
||||
echo "keys: $keys"
|
||||
echo "values: $values"
|
||||
eval $keysName="'$keys'"
|
||||
eval $valuesName="'$values'"
|
||||
}
|
||||
54
src/gt-completion
Normal file
54
src/gt-completion
Normal file
@ -0,0 +1,54 @@
|
||||
_gt-completion()
|
||||
{
|
||||
local cur prev opts tag help
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
prevPrev="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
opts="mind pullAndMerge help config"
|
||||
config="print set init"
|
||||
|
||||
# TODO check if this is still the most efficient way to list help options
|
||||
HELP_PATH=${BASH_SOURCE%/*}/gt-help
|
||||
help=${opts}
|
||||
#help=`ls $HELP_PATH`
|
||||
|
||||
if [[ ${cur} == "help" ]] ; then
|
||||
createFromString "${help}"
|
||||
return 0
|
||||
elif [[ $COMP_CWORD -gt 1 ]]; then
|
||||
if [ "$prev" == "tag" ]; then
|
||||
# no suggestions for tags
|
||||
return 0
|
||||
elif [ "$prev" == "config" ]; then
|
||||
createFromString "$config"
|
||||
elif [ "$prevPrev" == "config" ]; then
|
||||
# no suggestions after config xyz
|
||||
return 0
|
||||
elif [ "$prev" == "--path" ] || [ "$prev" == "-p" ]; then
|
||||
createFromDirectory "$DOCKER_SERVICES_HOME"
|
||||
elif [[ $COMP_CWORD -gt 1 ]] && [ "$prev" == "-p" ]; then
|
||||
createFromDirectory "$DOCKER_SERVICES_HOME"
|
||||
# elif [[ $COMP_CWORD -gt 1 ]] && [ "$prev" != "desc" ] && [ "$prev" != "year" ]; then
|
||||
# createFromString "${twoPlus}"
|
||||
else
|
||||
createFromString "${opts}"
|
||||
fi
|
||||
return 0
|
||||
elif [[ $COMP_CWORD -eq 1 ]]; then
|
||||
createFromString "${opts}"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
createFromString() {
|
||||
COMPREPLY=( $(compgen -W "${1}" -- ${cur}) )
|
||||
}
|
||||
|
||||
createFromDirectory() {
|
||||
pushd $1 >/dev/null
|
||||
COMPREPLY=( $(compgen -o plusdirs -- $cur) )
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
complete -F _gt-completion gt
|
||||
26
src/intro.sh
Normal file
26
src/intro.sh
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# This script is generated. Please do checkout the source code for editing!
|
||||
#
|
||||
# This is the main script for easing up Liferay development (inside AND outside a container).
|
||||
# Source Code: https://code.manhart.space/mmit/gt-bash-script.git
|
||||
# Maintainer: Manuel Manhart
|
||||
# Company: Manuel Manhart IT e.U.
|
||||
# License: Proprietary
|
||||
#
|
||||
|
||||
# set default constants
|
||||
SCRIPT_VERSION="0.1"
|
||||
|
||||
#SOURCE_PATH=./
|
||||
#BUILD_SYSTEM=""
|
||||
#GULP="gulp"
|
||||
#NPM="npm"
|
||||
#GRADLE="gradle"
|
||||
#MAVEN="mvn"
|
||||
#IGNORE_ERROR="IGNORE_ERROR"
|
||||
CONFIG_FILE_NAME=gt.config
|
||||
CONFIG_PATH=${HOME}/.config/mmit
|
||||
CONFIG_FILE=${CONFIG_PATH}/${CONFIG_FILE_NAME}
|
||||
ACTION=${1:-"help"}
|
||||
11
src/main.sh
Normal file
11
src/main.sh
Normal file
@ -0,0 +1,11 @@
|
||||
# main
|
||||
# import colors
|
||||
if [ -f ${BASH_SOURCE%/*}/define-colors ]; then
|
||||
. ${BASH_SOURCE%/*}/define-colors ""
|
||||
fi
|
||||
# read docker container configuration
|
||||
configRead
|
||||
# parse the arguments
|
||||
parseArgs "$@"
|
||||
# run the script
|
||||
runScript "$@"
|
||||
Loading…
x
Reference in New Issue
Block a user