Skip to content

Commit

Permalink
优化phpweb函数,支持使用Windows Terminal打开目标目录
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiyou committed Oct 7, 2022
1 parent 5360e8f commit 323e012
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions phpweb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
phpweb() {
#快速打开phpEnv集成开发环境下的某个网站目录
local webRoot="H:\Work\phpEnv\phpEnv\www"
local webRoot="$(_get_phpenv_path)\\www"
[ ! -z "$PHPENV_WEBROOT" ] && webRoot="$PHPENV_WEBROOT" #读取环境变量,可用export PHPENV_WEBROOT=xxx 临时更改全部项目的根路径~
if [ ! -d "$webRoot" ];then
echo "Debug:webRoot => $webRoot"
Expand All @@ -12,7 +13,8 @@ phpweb() {
local opener="" #使用什么工具打开目标文件夹,默认使用cygstart调用,通常即是explorer;
[ ! -z "$1" ] && opener="$1" #$1可打开文件夹使用的工具或命令

[[ "${1,,}" == "root" ]] && cygstart $(cygpath -aw "$webRoot\\..\\") && return # $1 为root则表示打开 PHPENV安装路径根目录
[[ "${1,,}" == "root" ]] && cygstart $(cygpath -aw "$webRoot\\") && return # $1 为root则表示打开 PHPENV安装路径根目录
[[ "${1,,}" == "rewrite" ]] && cygstart $(cygpath -aw "$webRoot\\..\\server\\nginx\\conf\\vhosts\\rewrite") && return # $1 为root则表示打开 PHPENV Nginx rewrite配置目录

#子函数1:用VSCode打开网站目录;
_vscode_open() {
Expand All @@ -29,34 +31,48 @@ phpweb() {
[ $? -eq 0 ] && cygwin || return 1
popd &>/dev/null
}
#子函数3: etc......
#子函数3:用Windows Terminal打开网站目录;
_wt_open() {
print_color "使用Windows Terminal打开:$1"
pushd "$1" &>/dev/null
[ $? -eq 0 ] && _T="$1" eval wt || return 1
popd &>/dev/null
}
#子函数4: etc......

echo "可用网站目录:"
echo "$webDirs"|awk '{printf NR"):";print}'
while :;
do
read -p "请输入序号选择要打开的网站目录(输入 0 或 q 退出操作, p 输出选择清单):" webChoose
read -p "请输入序号选择要打开的网站目录,支持一次打开多个目录(多个序号用空格隔开);"$'\n'"(输入 0 或 q 退出操作, p 输出选择清单):" webChoose
if [[ "$webChoose" == "0" || "${webChoose,,}" == "q" ]];then
print_color 40 "退出操作..."
return
elif [[ "${webChoose,,}" == "p" ]];then #再次打印网站目录清单
echo "$webDirs"|awk '{printf NR"):";print}'
continue
fi
local webDir=$(echo "$webDirs"|awk 'NR=='"${webChoose}"'{print $0;exit}')
echo "打开网站目录:$webDir ..."
if [ ! -z "$opener" ];then
#echo "检测打开的函数或工具..."
if [ $(type -t $opener) = "function" ];then
$opener `cygpath -au "${webRoot}\\\\${webDir}"` #调用子函数打开文件夹
[ $? -ne 0 ] && print_color 9 "调用函数 $opener 返回状态异常!"
mapfile -t -d $' ' myWebArr<<<"$webChoose"
for web in ${myWebArr[@]};
do
[[ "$web" == "0" ]] && { echo "exit...";return; }

local webDir=$(echo "$webDirs"|awk 'NR=='"${web}"'{print $0;exit}')
echo "打开网站目录:$webDir ..."
if [ ! -z "$opener" ];then
#echo "检测打开的函数或工具..."
if [ $(type -t $opener) = "function" ];then
$opener `cygpath -au "${webRoot}\\\\${webDir}"` #调用子函数打开文件夹
[ $? -ne 0 ] && print_color 9 "调用函数 $opener 返回状态异常!"
else
eval $opener `cygpath -au "${webRoot}\\\\${webDir}"` #调用某个alias或可执行文件打开文件夹
fi
else
eval $opener `cygpath -au "${webRoot}\\\\${webDir}"` #调用某个alias或可执行文件打开文件夹
cygstart $(cygpath -aw "${webRoot}\\${webDir}")
fi
else
cygstart $(cygpath -aw "${webRoot}\\${webDir}")
fi
done
done
}
alias phpweb2='phpweb _vscode_open' #用VSCode打开网站项目
alias vsphpweb='phpweb _vscode_open'
alias vsphpweb='phpweb _vscode_open'
alias phpwebwt='phpweb _wt_open' #用Windows Terminal打开

0 comments on commit 323e012

Please sign in to comment.