-
Notifications
You must be signed in to change notification settings - Fork 2
/
shx
executable file
·63 lines (63 loc) · 1.72 KB
/
shx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Check the current shell
export SHX_VERSION=0.2.2
export INVOKE_DIR=$PWD
export USER_DIR=~
export 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}."
exit
fi
# Define runner
runner="bash"
if [[ "${CURRENT_SHELL}" == *"bash" ]]; then
runner=$CURRENT_SHELL
elif [[ "$(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 folder
OIFS="$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))
done
if [[ "$fsPath" == "/" ]] ; then
echo -e "\033[1;31mError\033[0m: No project directory is found. Quitting."
exit 1
fi
IFS="$OIFS"
export SOURCE_DIR=$PWD
export PATH=$PATH:./:./sh
# Command parsing
arg="$@"
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/}"
done
elif [ -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[@]}".
fi
exit