-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpcfg.zsh
71 lines (64 loc) · 2.2 KB
/
phpcfg.zsh
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
64
65
66
67
68
69
70
71
alias php74="phpcfg -php 7.4"
alias php80="phpcfg -php 8.0"
alias php8="phpcfg -php 8.0"
alias php81="phpcfg -php 8.1"
alias php82="phpcfg -php 8.2"
alias php83="phpcfg -php 8.3"
alias php84="phpcfg -php 8.4"
PHPVERSIONS=(7.4 8.0 8.1 8.2 8.3 8.4)
phpcfg_MAIN_FOLDER="${JAP_FOLDER}plugins/packages/phpcfg/config/"
phpcfg_CONFIG_FILE="${phpcfg_MAIN_FOLDER}phpcfg.config.json"
gphp=$(jq -r '.global' $phpcfg_CONFIG_FILE)
if [[ ! -z $gphp ]]; then
alias php="phpcfg -php $gphp"
fi
phpcfg() {
if [[ "$1" == "-v" || "$1" == "-version" || "$1" == "v" ]]; then
echo -e "${BLUE}phpcfg$NC$BLUE$BOLD v0.2.0 $NC"
fi
if [[ "$1" == "-php" ]]; then
v="$2"
root=$(jq -r '.phpRoot' $phpcfg_CONFIG_FILE)
phpcmd=${root//"!v"/$v}
if [[ -e $phpcmd ]]; then
eval "$phpcmd \"$3\""
else
echo -e "${RED}The PHP version is not installed$NC"
fi
fi
if [[ "$1" == "e" ]]; then
e $phpcfg_CONFIG_FILE
fi
if [[ "$1" == "--list" || "$1" == "list" || "$1" == "-list" ]]; then
phplist "$2"
fi
}
phplist() {
if [[ "$1" == "--all" || "$1" == "all" || "$1" == "-all" ]];then
TABLE="${BOLD}V\tPaths${NC}"
for v in "${PHPVERSIONS[@]}"; do
root=$(jq -r '.phpRoot' $phpcfg_CONFIG_FILE)
phpcmd=${root//"!v"/$v}
if [[ -e $phpcmd ]]; then
TABLE+="\n${BLUE}${BOLD}$v${NC}\t$phpcmd"
else
TABLE+="\n${RED}${BOLD}$v${NC}\t${RED}$phpcmd${NC}"
fi
done
else
TABLE="${BOLD}V\tCMD\tBehind it${NC}"
phplive=$(type php 2>/dev/null)
phplive=${phplive//"php is "/""}
phplive=${phplive//"an alias for "/""}
TABLE+="\n${MAGENTA}${BOLD}$(php -v | head -n 1 | awk '{print $2}' | awk -F '.' '{print $1"."$2}')${NC}\t${CYAN}php${NC}\t${BOLD}${phplive}${NC}"
for v in "${PHPVERSIONS[@]}"; do
root=$(jq -r '.phpRoot' $phpcfg_CONFIG_FILE)
phpcmd=${root//"!v"/$v}
phpcfgcode=${v//"."/""}
if [[ -e $phpcmd ]]; then
TABLE+="\n${BLUE}${BOLD}$v${NC}\t${CYAN}php$phpcfgcode${NC}\t$phpcmd"
fi
done
fi
echo -e $TABLE
}