initial commit
This commit is contained in:
commit
df1999fd4f
46 files changed
+913
No files matched your search
@@ -0,0 +1,47 @@
|
||||
_bash-script-compiler-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="compile new 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" == "config" ]; then
|
||||
createFromString "$config"
|
||||
elif [ "$prevPrev" == "config" ]; then
|
||||
# no suggestions after config xyz
|
||||
return 0
|
||||
elif [ "$prev" == "compile" ] || [ "$prev" == "-c" ]; then
|
||||
createFromDirectory "."
|
||||
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 _bash-script-compiler-completion bash-script-compiler
|
||||
@@ -0,0 +1,10 @@
|
||||
compile() {
|
||||
pushd $PRJ_DIR >/dev/null 2>&1
|
||||
compile_setTargetFile
|
||||
compile_defineMainFunction
|
||||
compile_addFunctions
|
||||
compile_invokeMainFunction
|
||||
compile_copyCompletionFile
|
||||
echo "Compiled successfully"
|
||||
popd
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
compile_addFunctions() {
|
||||
PRJ_FUNC=$(ls -d ./functions/*)
|
||||
for filename in ${PRJ_FUNC[*]}; do
|
||||
cat ${filename} >> ${TARGET_FILE}
|
||||
echo "" >> ${TARGET_FILE}
|
||||
done
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
compile_copyCompletionFile() {
|
||||
cp *-completion ../${TARGET_DIR_NAME}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
compile_defineMainFunction() {
|
||||
touch ${TARGET_FILE}
|
||||
if [ ! -f "${INTRO_FILE_NAME}" ]; then
|
||||
echo "WARN: Could not find intro file '${INTRO_FILE_NAME}' in ${PRJ_DIR}"
|
||||
else
|
||||
cat "${INTRO_FILE_NAME}" > ${TARGET_FILE}
|
||||
echo "" >> ${TARGET_FILE}
|
||||
fi
|
||||
if [ ! -f "${MAIN_FUNC_FILE_NAME}" ]; then
|
||||
echo "ERROR: Could not find main function file '${MAIN_FUNC_FILE_NAME}' in ${PRJ_DIR}"
|
||||
help
|
||||
exit
|
||||
else
|
||||
echo -e "function main() {" >> ${TARGET_FILE}
|
||||
cat "${MAIN_FUNC_FILE_NAME}" | sed -e 's/^/ /g' >> ${TARGET_FILE}
|
||||
echo -e "\n}\n" >> ${TARGET_FILE}
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
compile_invokeMainFunction() {
|
||||
echo "main \"\$@\"" >> ${TARGET_FILE}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
compile_setTargetFile() {
|
||||
local bashScriptName=$(basename "$(pwd)")
|
||||
if [ ! -d "${TARGET_DIR_NAME}" ]; then
|
||||
echo "Creating output dir '${TARGET_DIR_NAME}'"
|
||||
mkdir -p ${TARGET_DIR_NAME}
|
||||
fi
|
||||
TARGET_FILE=../${TARGET_DIR_NAME}/$bashScriptName
|
||||
cd $SRC_DIR_NAME
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
help() {
|
||||
local progName=$(echo "$0" | rev | cut -d'/' -f1 | rev)
|
||||
|
||||
cat <<-END
|
||||
$progName is a tool for creating big bash script projects in smaller files / chunks.
|
||||
|
||||
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
|
||||
|
||||
compile PRJ_PATH ... compiles the bash project in the given path (./ compiles itself)
|
||||
new ... initializes a new bash project
|
||||
|
||||
help ... show this page
|
||||
|
||||
Version: $SCRIPT_VERSION
|
||||
END
|
||||
|
||||
exit
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
new() {
|
||||
new_ReadProjectData
|
||||
new_InitProject
|
||||
replaceFileNames
|
||||
replaceVariablesInFiles
|
||||
echo "Project created successfully"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
new_InitProject() {
|
||||
echo "Not yet implemented"
|
||||
# TODO implement copying from ./init to project name
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
new_ReadProjectData() {
|
||||
local year=$(date +'%Y')
|
||||
local author=$USER
|
||||
echo "Creating a new bash project"
|
||||
echo "Project name:"
|
||||
echo "Author name ($author):"
|
||||
echo "Year ($year):"
|
||||
echo "Is it MIT License (Y/n)?"
|
||||
# echo "Create sample data" # not sure if we should really ask that
|
||||
# TODO read the data into global variables
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
parseArgs() {
|
||||
if [ -z $1 ]; then
|
||||
help
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
parseArgs_compile() {
|
||||
if [ -z $1 ]; then
|
||||
echo "Please give a directory to the bash script to compile"
|
||||
help
|
||||
fi
|
||||
if [ ! -d $1 ]; then
|
||||
echo "$1 is not a directory"
|
||||
help
|
||||
else
|
||||
PRJ_DIR=$1
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
replaceFileNames() {
|
||||
echo "Not yet implemented"
|
||||
# TODO implement replacing the file names beginning with BASH_SCRIPT_COMPILER_SCRIPT_NAME
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
replaceVariablesInFiles() {
|
||||
echo "Not yet implemented"
|
||||
# TODO implement replacing the file content variables BASH_SCRIPT_COMPILER_*
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# This script is generated. Please do checkout the source code for editing!
|
||||
#
|
||||
# This is a tool for creating big bash script projects in smaller files / chunks.
|
||||
# Source Code: https://code.manhart.space/mmit/bash-script-compiler.git
|
||||
# Maintainer: Manuel Manhart
|
||||
# Company: Manuel Manhart IT e.U.
|
||||
# License: MIT
|
||||
# Created by bash-script-compiler version BASH_SCRIPT_COMPILER_VERSION
|
||||
|
||||
# set default constants / variables
|
||||
SCRIPT_VERSION="0.1"
|
||||
|
||||
CONFIG_FILE_NAME=BASH_SCRIPT_COMPILER_SCRIPT_NAME.config
|
||||
CONFIG_PATH=${HOME}/.config/mmit
|
||||
CONFIG_FILE=${CONFIG_PATH}/${CONFIG_FILE_NAME}
|
||||
ACTION=${1:-"help"}
|
||||
|
||||
TARGET_DIR_NAME="dist"
|
||||
SRC_DIR_NAME="src"
|
||||
MAIN_FUNC_FILE_NAME="main.sh"
|
||||
INTRO_FILE_NAME="intro.sh"
|
||||
PARSE_ARGS_PREFIX="parseArgs_"
|
||||
|
||||
# TODO (minor) we do not want to print every command which is executed, only our specific "echo"s
|
||||
# TODO (medium) implement support for PRJ_HELP (for loop can only be in one line it seems)
|
||||
@@ -0,0 +1,7 @@
|
||||
local action=${1:-"help"}
|
||||
local parseArgsFunc="${PARSE_ARGS_PREFIX}${action}"
|
||||
local isParseArgsDefined=$(type -t $parseArgsFunc)
|
||||
if [ "function" == "$isParseArgsDefined" ]; then
|
||||
"$parseArgsFunc" "${@:2}"
|
||||
fi
|
||||
"$action" "${@:2}"
|
||||
Reference in new issue
Block a user