shx
#!/bin/bash# Check the current shellexport SHX_VERSION=0.2.2export INVOKE_DIR=$PWDexport CURRENT_SHELL=$(ps h -p $$ -o args='' | cut -f1 -d' ')if [[ "${NO_SHELL_CHECK}" == "" ]] && [[ "${CURRENT_SHELL}" != *"bash" ]] && [[ "${CURRENT_SHELL}" != *"ksh" ]] && [[ "${CURRENT_SHELL}" != *"zsh" ]]; then echo -e "\033[1;31mError\033[0m: Please run with bash instead of ${CURRENT_SHELL}." exitfi# Define runnerrunner="bash"if [[ "${CURRENT_SHELL}" == *"bash" ]]; then runner=$CURRENT_SHELLelif [[ "$(bash --version >/dev/null 2>/dev/null;echo $?)" == "0" ]]; then printf ""else echo -e "\033[1;33mWarning\033[0m: Not using Bash. Scripts may not work."fi# Locate the project folderOIFS="$IFS"IFS='/' read -r -a paths <<< "$PWD" 2>/dev/null || paths=('' ${(@s:/:)PWD})let fsPointer=$((${#paths[@]} - 1))IFS='/'while [ "$fsPointer" -ge 0 ]; do fsPath="${paths[@]:0:$((fsPointer + 1))}" fsPath=${fsPath:-/} if [ -f "$fsPath/shx" ] && [ -d "$fsPath/sh" ] ; then #echo "Switched to \"$fsPath\"." cd "$fsPath" break #else #echo "No match for \"$fsPath\"." fi fsPointer=$(($fsPointer - 1))doneif [[ "$fsPath" == "/" ]] ; then echo -e "\033[1;31mError\033[0m: No project directory is found. Quitting." exit 1fiIFS="$OIFS"export SOURCE_DIR=$PWDexport PATH=$PATH:./:./sh# Command parsingarg="$@"args=( "$@" )if [[ "${arg}" == "" ]] ; then echo -e "\033[1;37mshx ${SHX_VERSION}\033[0m" echo "All available actions:" ls -1 sh | while IFS= read -r file; do echo "· ${file/.sh/}" doneelif [ -e "sh/$1.sh" ] ; then bash "sh/$1.sh" "${args[@]:1}"elif [ -e "sh/$1" ] ; then bash "sh/$1" "${args[@]:1}"else echo -e "\033[1;31mError\033[0m: No action found as \"$1\". Command: shx ${args[@]}".fiexit