From d5fcd9e8529125952826e313af7fd9fedf1b9b8d Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Tue, 9 Jun 2020 00:02:10 +0800 Subject: [PATCH 1/4] wslusc: multiple bug fixes - fixes #129 - fixes a possible white space path issue - When TMP is empty, try TEMP --- src/wslusc.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/wslusc.sh b/src/wslusc.sh index d77a111e..1602d1f4 100644 --- a/src/wslusc.sh +++ b/src/wslusc.sh @@ -1,5 +1,5 @@ # shellcheck shell=bash -version="37" +version="40" cname="" iconpath="" @@ -19,14 +19,16 @@ while [ "$1" != "" ]; do -g|--gui)is_gui=1;shift;; -h|--help) help "$0" "$help_short"; exit;; -v|--version) echo "wslu v$wslu_version; wslusc v$version"; exit;; - *) cname="$*";break;; + *) cname_header="$1"; shift; cname="$*"; break;; esac done # interactive mode if [[ $is_interactive -eq 1 ]]; then echo "${info} Welcome to wslu shortcut creator interactive mode." - read -r -e -i "$cname" -p "${input_info} Command to execute: " input + read -r -e -i "$cname_header" -p "${input_info} Command (Without Parameter): " input + cname_header="${input:-$cname_header}" + read -r -e -i "$cname" -p "${input_info} Command param: " input cname="${input:-$cname}" read -r -e -i "$customname" -p "${input_info} Shortcut name [optional, ENTER for default]: " input customname="${input:-$customname}" @@ -38,9 +40,10 @@ if [[ $is_interactive -eq 1 ]]; then iconpath="${input:-$iconpath}" fi -if [[ "$cname" != "" ]]; then +if [[ "$cname_header" != "" ]]; then up_path="$(wslvar -s USERPROFILE)" tpath=$(double_dash_p "$(wslvar -s TMP)") # Windows Temp, Win Double Sty. + tpath="${tpath:-$(double_dash_p "$(wslvar -s TEMP)")}" # sometimes TMP is not set for some reason dpath=$(wslpath "$(wslvar -l Desktop)") # Windows Desktop, WSL Sty. script_location="$(wslpath "$up_path")/wslu" # Windows wslu, Linux WSL Sty. script_location_win="$(double_dash_p "$up_path")\\wslu" # Windows wslu, Win Double Sty. @@ -49,16 +52,22 @@ if [[ "$cname" != "" ]]; then # change param according to the exec. distro_param="run" if [[ "$distro_location_win" == *wsl.exe* ]]; then - distro_param="" + distro_param="-e" fi + # always absolute path + cname_header=$(readlink -f "$cname_header") + # handling no name given case - new_cname=$(basename "$(echo "$cname" | awk '{print $1}')") + new_cname=$(basename "$cname_header") # handling name given case if [[ "$customname" != "" ]]; then new_cname=$customname fi + # construct full command + cname="\"$(echo "$cname_header" | sed "s| |\\\\ |g") $cname\"" + # Check default icon and runHidden.vbs wslu_file_check "$script_location" "wsl.ico" wslu_file_check "$script_location" "wsl-term.ico" @@ -111,9 +120,9 @@ if [[ "$cname" != "" ]]; then if [[ "$is_gui" == "1" ]]; then winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='C:\\Windows\\System32\\wscript.exe';\$s.Arguments='$script_location_win\\runHidden.vbs \"$distro_location_win\" $distro_param \"$customenv /usr/share/wslu/wslusc-helper.sh $cname\"';\$s.IconLocation='$iconpath';\$s.Save();" else - winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='\"$distro_location_win\"';\$s.Arguments='$distro_param \"$customenv bash -l -c $cname\"';\$s.IconLocation='$iconpath';\$s.Save();" + winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='\"$distro_location_win\"';\$s.Arguments='$distro_param $customenv bash -l -c $cname';\$s.IconLocation='$iconpath';\$s.Save();" fi - tpath="$(wslpath "$(wslvar -s TMP)")/$new_cname.lnk" + tpath="$(wslpath "$tpath")/$new_cname.lnk" mv "$tpath" "$dpath" echo "${info} Create shortcut ${new_cname}.lnk successful" else From 3d268b1f38933520c003ef32e2768383dd87efbf Mon Sep 17 00:00:00 2001 From: "Jinming Wu, Patrick" Date: Tue, 9 Jun 2020 00:14:48 +0800 Subject: [PATCH 2/4] Revert "wslusc: multiple bug fixes" This reverts commit d5fcd9e8529125952826e313af7fd9fedf1b9b8d. --- src/wslusc.sh | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/wslusc.sh b/src/wslusc.sh index 1602d1f4..d77a111e 100644 --- a/src/wslusc.sh +++ b/src/wslusc.sh @@ -1,5 +1,5 @@ # shellcheck shell=bash -version="40" +version="37" cname="" iconpath="" @@ -19,16 +19,14 @@ while [ "$1" != "" ]; do -g|--gui)is_gui=1;shift;; -h|--help) help "$0" "$help_short"; exit;; -v|--version) echo "wslu v$wslu_version; wslusc v$version"; exit;; - *) cname_header="$1"; shift; cname="$*"; break;; + *) cname="$*";break;; esac done # interactive mode if [[ $is_interactive -eq 1 ]]; then echo "${info} Welcome to wslu shortcut creator interactive mode." - read -r -e -i "$cname_header" -p "${input_info} Command (Without Parameter): " input - cname_header="${input:-$cname_header}" - read -r -e -i "$cname" -p "${input_info} Command param: " input + read -r -e -i "$cname" -p "${input_info} Command to execute: " input cname="${input:-$cname}" read -r -e -i "$customname" -p "${input_info} Shortcut name [optional, ENTER for default]: " input customname="${input:-$customname}" @@ -40,10 +38,9 @@ if [[ $is_interactive -eq 1 ]]; then iconpath="${input:-$iconpath}" fi -if [[ "$cname_header" != "" ]]; then +if [[ "$cname" != "" ]]; then up_path="$(wslvar -s USERPROFILE)" tpath=$(double_dash_p "$(wslvar -s TMP)") # Windows Temp, Win Double Sty. - tpath="${tpath:-$(double_dash_p "$(wslvar -s TEMP)")}" # sometimes TMP is not set for some reason dpath=$(wslpath "$(wslvar -l Desktop)") # Windows Desktop, WSL Sty. script_location="$(wslpath "$up_path")/wslu" # Windows wslu, Linux WSL Sty. script_location_win="$(double_dash_p "$up_path")\\wslu" # Windows wslu, Win Double Sty. @@ -52,22 +49,16 @@ if [[ "$cname_header" != "" ]]; then # change param according to the exec. distro_param="run" if [[ "$distro_location_win" == *wsl.exe* ]]; then - distro_param="-e" + distro_param="" fi - # always absolute path - cname_header=$(readlink -f "$cname_header") - # handling no name given case - new_cname=$(basename "$cname_header") + new_cname=$(basename "$(echo "$cname" | awk '{print $1}')") # handling name given case if [[ "$customname" != "" ]]; then new_cname=$customname fi - # construct full command - cname="\"$(echo "$cname_header" | sed "s| |\\\\ |g") $cname\"" - # Check default icon and runHidden.vbs wslu_file_check "$script_location" "wsl.ico" wslu_file_check "$script_location" "wsl-term.ico" @@ -120,9 +111,9 @@ if [[ "$cname_header" != "" ]]; then if [[ "$is_gui" == "1" ]]; then winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='C:\\Windows\\System32\\wscript.exe';\$s.Arguments='$script_location_win\\runHidden.vbs \"$distro_location_win\" $distro_param \"$customenv /usr/share/wslu/wslusc-helper.sh $cname\"';\$s.IconLocation='$iconpath';\$s.Save();" else - winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='\"$distro_location_win\"';\$s.Arguments='$distro_param $customenv bash -l -c $cname';\$s.IconLocation='$iconpath';\$s.Save();" + winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='\"$distro_location_win\"';\$s.Arguments='$distro_param \"$customenv bash -l -c $cname\"';\$s.IconLocation='$iconpath';\$s.Save();" fi - tpath="$(wslpath "$tpath")/$new_cname.lnk" + tpath="$(wslpath "$(wslvar -s TMP)")/$new_cname.lnk" mv "$tpath" "$dpath" echo "${info} Create shortcut ${new_cname}.lnk successful" else From ea62b06c2290c5a160fcb2a384894a36e22373f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E4=B9=9D=E9=BC=8E?= <109224573@qq.com> Date: Wed, 24 Jun 2020 15:55:59 +0800 Subject: [PATCH 3/4] Readme: fix semicolon --- README.hans.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.hans.md b/README.hans.md index e023a6d8..470a3d71 100644 --- a/README.hans.md +++ b/README.hans.md @@ -18,7 +18,7 @@ 这是一套适用于 Windows 10 Linux 子系统的工具组,可以在 Windows 10 Linux 子系统下完成诸如获取 Windows 环境变量或者创建你最喜爱的 Linux 程序桌面快捷方式等工作。 -需要 Windows 10 创造者更新; 部分功能需要更高版本的Windows 10;支持 WSL2。 +需要 Windows 10 创造者更新;部分功能需要更高版本的Windows 10;支持 WSL2。 ## 功能 From 8f1fde389d6b90125f68662f60a206aae69abc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E4=B9=9D=E9=BC=8E?= <109224573@qq.com> Date: Wed, 24 Jun 2020 15:56:35 +0800 Subject: [PATCH 4/4] Update README.hant.md --- README.hant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.hant.md b/README.hant.md index 5ad87f28..aa75b3f8 100644 --- a/README.hant.md +++ b/README.hant.md @@ -18,7 +18,7 @@ 這是一套適用於 Windows 10 Linux 子系統的工具組,可以在 Windows 10 Linux 子系統下完成諸如獲取 Windows 環境變數或者建立你最喜愛的 Linux 程式桌面捷徑等工作。 -需要 Windows 10 創造者更新; 部分功能需要更高版本的Windows 10;支援 WSL2。 +需要 Windows 10 創造者更新;部分功能需要更高版本的Windows 10;支援 WSL2。 ## 功能