mirror of
https://github.com/mintty/wsltty.git
synced 2025-01-31 02:01:01 +00:00
fix EOL, restore misdeleted chunk on original L138-141, tabs to spaces
This commit is contained in:
parent
52b03a43d9
commit
017b05c48c
@ -1,233 +1,236 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
PATH=/bin:$PATH
|
PATH=/bin:$PATH
|
||||||
|
|
||||||
contextmenu=false
|
contextmenu=false
|
||||||
remove=false
|
remove=false
|
||||||
alldistros=true
|
alldistros=true
|
||||||
config=true
|
config=true
|
||||||
|
|
||||||
case "`basename $0`" in
|
case "`basename $0`" in
|
||||||
wsl*)
|
wsl*)
|
||||||
config=false;;
|
config=false;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-info)
|
-info)
|
||||||
config=false
|
config=false
|
||||||
shift;;
|
shift;;
|
||||||
-shortcuts-remove)
|
-shortcuts-remove)
|
||||||
remove=true
|
remove=true
|
||||||
shift;;
|
shift;;
|
||||||
-contextmenu)
|
-contextmenu)
|
||||||
contextmenu=true
|
contextmenu=true
|
||||||
shift;;
|
shift;;
|
||||||
-contextmenu-default)
|
-contextmenu-default)
|
||||||
contextmenu=true
|
contextmenu=true
|
||||||
alldistros=false
|
alldistros=false
|
||||||
shift;;
|
shift;;
|
||||||
-contextmenu-remove)
|
-contextmenu-remove)
|
||||||
contextmenu=true
|
contextmenu=true
|
||||||
remove=true
|
remove=true
|
||||||
direckey='/HKEY_CURRENT_USER/Software/Classes/Directory'
|
direckey='/HKEY_CURRENT_USER/Software/Classes/Directory'
|
||||||
|
|
||||||
regtool list "$direckey/shell" 2>/dev/null |
|
regtool list "$direckey/shell" 2>/dev/null |
|
||||||
while read name
|
while read name
|
||||||
do
|
do
|
||||||
case `regtool get "$direckey/shell/$name/command/"` in
|
case `regtool get "$direckey/shell/$name/command/"` in
|
||||||
*bin\\mintty.exe*/bin/wslbridge*|*bin\\mintty.exe*--WSL*)
|
*bin\\mintty.exe*/bin/wslbridge*|*bin\\mintty.exe*--WSL*)
|
||||||
regtool remove "$direckey/shell/$name/command"
|
regtool remove "$direckey/shell/$name/command"
|
||||||
regtool remove "$direckey/shell/$name"
|
regtool remove "$direckey/shell/$name"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
regtool list "$direckey/Background/shell" 2>/dev/null |
|
regtool list "$direckey/Background/shell" 2>/dev/null |
|
||||||
while read name
|
while read name
|
||||||
do
|
do
|
||||||
case `regtool get "$direckey/Background/shell/$name/command/"` in
|
case `regtool get "$direckey/Background/shell/$name/command/"` in
|
||||||
*bin\\mintty.exe*/bin/wslbridge*|*bin\\mintty.exe*--WSL*)
|
*bin\\mintty.exe*/bin/wslbridge*|*bin\\mintty.exe*--WSL*)
|
||||||
regtool remove "$direckey/Background/shell/$name/command"
|
regtool remove "$direckey/Background/shell/$name/command"
|
||||||
regtool remove "$direckey/Background/shell/$name"
|
regtool remove "$direckey/Background/shell/$name"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
exit
|
exit
|
||||||
shift;;
|
shift;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# test w/o WSL: call this script with REGTOOLFAKE=true dash config-distros.sh
|
# test w/o WSL: call this script with REGTOOLFAKE=true dash config-distros.sh
|
||||||
if ${REGTOOLFAKE:-false}
|
if ${REGTOOLFAKE:-false}
|
||||||
then
|
then
|
||||||
regtool () {
|
regtool () {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-*) shift;;
|
-*) shift;;
|
||||||
esac
|
esac
|
||||||
key=`echo $2 | sed -e 's,.*{\(.*\)}.*,\1,' -e t -e d`
|
key=`echo $2 | sed -e 's,.*{\(.*\)}.*,\1,' -e t -e d`
|
||||||
case "$1.$2" in
|
case "$1.$2" in
|
||||||
list.*)
|
list.*)
|
||||||
if $contextmenu
|
if $contextmenu
|
||||||
then echo "{0}"
|
then echo "{0}"
|
||||||
else echo "{1}"; echo "{2}"
|
else echo "{1}"; echo "{2}"
|
||||||
fi;;
|
fi;;
|
||||||
get.*/DistributionName)
|
get.*/DistributionName)
|
||||||
echo "distro$key";;
|
echo "distro$key";;
|
||||||
get.*/BasePath)
|
get.*/BasePath)
|
||||||
echo "C:\\Program\\{$key}\\State";;
|
echo "C:\\Program\\{$key}\\State";;
|
||||||
get.*/PackageFamilyName)
|
get.*/PackageFamilyName)
|
||||||
echo "distro{$key}";;
|
echo "distro{$key}";;
|
||||||
get.*/PackageFullName)
|
get.*/PackageFullName)
|
||||||
echo "C:\\Program\\{$key}";;
|
echo "C:\\Program\\{$key}";;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# dash built-in echo enforces interpretation of \t etc
|
# dash built-in echo enforces interpretation of \t etc
|
||||||
echoc () {
|
echoc () {
|
||||||
cmd /c echo $*
|
cmd /c echo $*
|
||||||
}
|
}
|
||||||
|
|
||||||
if $config
|
if $config
|
||||||
then while read line; do echo "$line"; done <</EOB > mkbat.bat
|
then while read line; do echo "$line"; done <</EOB > mkbat.bat
|
||||||
@echo off
|
@echo off
|
||||||
echo Creating %1.bat
|
echo Creating %1.bat
|
||||||
|
|
||||||
echo @echo off> %1.bat
|
echo @echo off> %1.bat
|
||||||
echo rem Start mintty terminal for WSL package %name% in current directory>> %1.bat
|
echo rem Start mintty terminal for WSL package %name% in current directory>> %1.bat
|
||||||
echo %target% -i "%icon%" %minttyargs% %bridgeargs%>> %1.bat
|
echo %target% -i "%icon%" %minttyargs% %bridgeargs%>> %1.bat
|
||||||
/EOB
|
/EOB
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=/bin:$PATH
|
PATH=/bin:$PATH
|
||||||
|
|
||||||
lxss="/HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Lxss"
|
lxss="/HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Lxss"
|
||||||
schema="/HKEY_CURRENT_USER/Software/Classes/Local Settings/Software/Microsoft/Windows/CurrentVersion/AppModel/SystemAppData"
|
schema="/HKEY_CURRENT_USER/Software/Classes/Local Settings/Software/Microsoft/Windows/CurrentVersion/AppModel/SystemAppData"
|
||||||
|
|
||||||
#(regtool list "$lxss" 2>/dev/null && echo || echo "No WSL packages registered" >&2) |
|
#(regtool list "$lxss" 2>/dev/null && echo || echo "No WSL packages registered" >&2) |
|
||||||
(
|
(
|
||||||
if $alldistros
|
if $alldistros
|
||||||
then regtool list "$lxss" 2>/dev/null
|
then regtool list "$lxss" 2>/dev/null
|
||||||
else true
|
else true
|
||||||
fi && echo || echo "No WSL packages registered" >&2) |
|
fi && echo || echo "No WSL packages registered" >&2) |
|
||||||
while read guid
|
while read guid
|
||||||
do
|
do
|
||||||
ok=false
|
ok=false
|
||||||
case $guid in
|
case $guid in
|
||||||
{*)
|
{*)
|
||||||
distro=`regtool get "$lxss/$guid/DistributionName"`
|
distro=`regtool get "$lxss/$guid/DistributionName"`
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
Legacy)
|
Legacy)
|
||||||
name="Bash on Windows"
|
name="Bash on Windows"
|
||||||
launch=
|
launch=
|
||||||
launcher="$SYSTEMROOT/System32/bash.exe"
|
launcher="$SYSTEMROOT/System32/bash.exe"
|
||||||
;;
|
;;
|
||||||
*) name="$distro"
|
*) name="$distro"
|
||||||
launch="$distro"
|
launch="$distro"
|
||||||
launcher="$LOCALAPPDATA/Microsoft/WindowsApps/$distro.exe"
|
launcher="$LOCALAPPDATA/Microsoft/WindowsApps/$distro.exe"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
basepath=`regtool get "$lxss/$guid/BasePath"`
|
basepath=`regtool get "$lxss/$guid/BasePath"`
|
||||||
if package=`regtool -q get "$lxss/$guid/PackageFamilyName"`
|
if package=`regtool -q get "$lxss/$guid/PackageFamilyName"`
|
||||||
then
|
then
|
||||||
instdir=`regtool get "$schema/$package/Schemas/PackageFullName"`
|
instdir=`regtool get "$schema/$package/Schemas/PackageFullName"`
|
||||||
|
|
||||||
# get actual executable path (may not match $distro) from the app manifest
|
# get actual executable path (may not match $distro) from the app manifest
|
||||||
manifest="$ProgramW6432/WindowsApps/$instdir/AppxManifest.xml"
|
manifest="$ProgramW6432/WindowsApps/$instdir/AppxManifest.xml"
|
||||||
psh_cmd='([xml]$(Get-Content '"\"$manifest\""')).Package.Applications.Application.Executable'
|
psh_cmd='([xml]$(Get-Content '"\"$manifest\""')).Package.Applications.Application.Executable'
|
||||||
executable=`powershell "$psh_cmd"`
|
executable=`powershell "$psh_cmd"`
|
||||||
|
|
||||||
# remove trailing newline that above command introduces
|
# remove trailing newline that above command introduces
|
||||||
executable="${executable%"${executable##*[![:space:]]}"}"
|
executable="${executable%"${executable##*[![:space:]]}"}"
|
||||||
if [ -r "$ProgramW6432/WindowsApps/$instdir/$executable" ]
|
if [ -r "$ProgramW6432/WindowsApps/$instdir/$executable" ]
|
||||||
then icon="%PROGRAMFILES%\\WindowsApps\\$instdir\\$executable"
|
then icon="%PROGRAMFILES%\\WindowsApps\\$instdir\\$executable"
|
||||||
else icon="%LOCALAPPDATA%/wsltty/wsl.ico"
|
else icon="%LOCALAPPDATA%/wsltty/wsl.ico"
|
||||||
fi
|
else
|
||||||
|
icon="%LOCALAPPDATA%/lxss/bash.ico"
|
||||||
minttyargs='--wsl --rootfs="'"$root"'" --configdir="%APPDATA%\wsltty" -o Locale=C -o Charset=UTF-8 /bin/wslbridge '
|
root="$basepath"
|
||||||
minttyargs='--WSL="'"$distro"'" --configdir="%APPDATA%\wsltty"'
|
fi
|
||||||
#if [ -z "$launch" ]
|
|
||||||
#then bridgeargs='-t /bin/bash'
|
minttyargs='--wsl --rootfs="'"$root"'" --configdir="%APPDATA%\wsltty" -o Locale=C -o Charset=UTF-8 /bin/wslbridge '
|
||||||
#else bridgeargs='-l "'"$launch"'" -t /bin/bash'
|
minttyargs='--WSL="'"$distro"'" --configdir="%APPDATA%\wsltty"'
|
||||||
#fi
|
#if [ -z "$launch" ]
|
||||||
bridgeargs='--distro-guid "'"$guid"'" -t /bin/bash'
|
#then bridgeargs='-t /bin/bash'
|
||||||
bridgeargs='--distro-guid "'"$guid"'" -t'
|
#else bridgeargs='-l "'"$launch"'" -t /bin/bash'
|
||||||
|
#fi
|
||||||
ok=true;;
|
bridgeargs='--distro-guid "'"$guid"'" -t /bin/bash'
|
||||||
"") # WSL default installation
|
bridgeargs='--distro-guid "'"$guid"'" -t'
|
||||||
distro=
|
|
||||||
name=WSL
|
ok=true;;
|
||||||
icon="%LOCALAPPDATA%/wsltty/wsl.ico"
|
"") # WSL default installation
|
||||||
minttyargs='--WSL= --configdir="%APPDATA%\wsltty"'
|
distro=
|
||||||
bridgeargs='-t'
|
name=WSL
|
||||||
|
icon="%LOCALAPPDATA%/wsltty/wsl.ico"
|
||||||
ok=true;;
|
minttyargs='--WSL= --configdir="%APPDATA%\wsltty"'
|
||||||
esac
|
bridgeargs='-t'
|
||||||
echoc "distro '$distro'"
|
|
||||||
echoc "- name '$name'"
|
ok=true;;
|
||||||
echoc "- guid $guid"
|
esac
|
||||||
echoc "- (launcher $launcher)"
|
echoc "distro '$distro'"
|
||||||
echoc "- icon $icon"
|
echoc "- name '$name'"
|
||||||
echoc "- root $root"
|
echoc "- guid $guid"
|
||||||
target='%LOCALAPPDATA%\wsltty\bin\mintty.exe'
|
echoc "- (launcher $launcher)"
|
||||||
bridgeargs=" "
|
echoc "- icon $icon"
|
||||||
|
echoc "- root $root"
|
||||||
if $ok && $config
|
target='%LOCALAPPDATA%\wsltty\bin\mintty.exe'
|
||||||
then
|
bridgeargs=" "
|
||||||
export target minttyargs bridgeargs icon
|
|
||||||
|
if $ok && $config
|
||||||
if $contextmenu
|
then
|
||||||
then
|
export target minttyargs bridgeargs icon
|
||||||
# context menu entries
|
|
||||||
#cmd /C mkcontext "$name"
|
if $contextmenu
|
||||||
direckey='HKEY_CURRENT_USER\Software\Classes\Directory'
|
then
|
||||||
if $remove
|
# context menu entries
|
||||||
then
|
#cmd /C mkcontext "$name"
|
||||||
reg delete "$direckey\\shell\\$name" /f
|
direckey='HKEY_CURRENT_USER\Software\Classes\Directory'
|
||||||
reg delete "$direckey\\Background\\shell\\$name" /f
|
if $remove
|
||||||
else
|
then
|
||||||
reg add "$direckey\\shell\\$name" /d "$name Terminal" /f
|
reg delete "$direckey\\shell\\$name" /f
|
||||||
reg add "$direckey\\shell\\$name" /v Icon /d "$icon" /f
|
reg delete "$direckey\\Background\\shell\\$name" /f
|
||||||
cmd /C reg add "$direckey\\shell\\$name\\command" /d "\"$target\" -i \"$icon\" --dir \"%1\" $minttyargs $bridgeargs" /f
|
else
|
||||||
reg add "$direckey\\Background\\shell\\$name" /d "$name Terminal" /f
|
reg add "$direckey\\shell\\$name" /d "$name Terminal" /f
|
||||||
reg add "$direckey\\Background\\shell\\$name" /v Icon /d "$icon" /f
|
reg add "$direckey\\shell\\$name" /v Icon /d "$icon" /f
|
||||||
cmd /C reg add "$direckey\\Background\\shell\\$name\\command" /d "\"$target\" -i \"$icon\" $minttyargs $bridgeargs" /f
|
cmd /C reg add "$direckey\\shell\\$name\\command" /d "\"$target\" -i \"$icon\" --dir \"%1\" $minttyargs $bridgeargs" /f
|
||||||
fi
|
reg add "$direckey\\Background\\shell\\$name" /d "$name Terminal" /f
|
||||||
else
|
reg add "$direckey\\Background\\shell\\$name" /v Icon /d "$icon" /f
|
||||||
# invocation shortcuts and scripts
|
cmd /C reg add "$direckey\\Background\\shell\\$name\\command" /d "\"$target\" -i \"$icon\" $minttyargs $bridgeargs" /f
|
||||||
if $remove
|
fi
|
||||||
then
|
else
|
||||||
cmd /C del "%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\$name Terminal.lnk"
|
# invocation shortcuts and scripts
|
||||||
cmd /C del "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name.bat"
|
if $remove
|
||||||
cmd /C del "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name~.bat"
|
then
|
||||||
else
|
cmd /C del "%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\$name Terminal.lnk"
|
||||||
# desktop shortcut in %USERPROFILE% -> Start Menu - WSLtty
|
cmd /C del "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name.bat"
|
||||||
cscript /nologo mkshortcut.vbs "/name:$name Terminal %"
|
cmd /C del "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name~.bat"
|
||||||
cmd /C copy "$name Terminal %.lnk" "%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\WSLtty"
|
else
|
||||||
|
# desktop shortcut in %USERPROFILE% -> Start Menu - WSLtty
|
||||||
# launch script in . -> WSLtty home, WindowsApps launch folder
|
cscript /nologo mkshortcut.vbs "/name:$name Terminal %"
|
||||||
cmd /C mkbat.bat "$name"
|
cmd /C copy "$name Terminal %.lnk" "%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\WSLtty"
|
||||||
cmd /C copy "$name.bat" "%LOCALAPPDATA%\\wsltty\\$name.bat"
|
|
||||||
cmd /C copy "$name.bat" "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name.bat"
|
# launch script in . -> WSLtty home, WindowsApps launch folder
|
||||||
|
cmd /C mkbat.bat "$name"
|
||||||
# prepare versions to target WSL home directory
|
cmd /C copy "$name.bat" "%LOCALAPPDATA%\\wsltty\\$name.bat"
|
||||||
#bridgeargs="-C~ $bridgeargs"
|
cmd /C copy "$name.bat" "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name.bat"
|
||||||
minttyargs="$minttyargs -~"
|
|
||||||
|
# prepare versions to target WSL home directory
|
||||||
# desktop shortcut in ~ -> Start Menu
|
#bridgeargs="-C~ $bridgeargs"
|
||||||
cscript /nologo mkshortcut.vbs "/name:$name Terminal"
|
minttyargs="$minttyargs -~"
|
||||||
cmd /C copy "$name Terminal.lnk" "%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs"
|
|
||||||
|
# desktop shortcut in ~ -> Start Menu
|
||||||
# default desktop shortcut in ~ -> Desktop
|
cscript /nologo mkshortcut.vbs "/name:$name Terminal"
|
||||||
if [ "$name" = "WSL" ]
|
cmd /C copy "$name Terminal.lnk" "%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs"
|
||||||
then cmd /C copy "$name Terminal.lnk" "%USERPROFILE%\\Desktop"
|
|
||||||
fi
|
# default desktop shortcut in ~ -> Desktop
|
||||||
|
if [ "$name" = "WSL" ]
|
||||||
# launch script in ~ -> WSLtty home, WindowsApps launch folder
|
then cmd /C copy "$name Terminal.lnk" "%USERPROFILE%\\Desktop"
|
||||||
cmd /C mkbat.bat "$name~"
|
fi
|
||||||
cmd /C copy "$name~.bat" "%LOCALAPPDATA%\\wsltty\\$name~.bat"
|
|
||||||
cmd /C copy "$name~.bat" "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name~.bat"
|
# launch script in ~ -> WSLtty home, WindowsApps launch folder
|
||||||
fi
|
cmd /C mkbat.bat "$name~"
|
||||||
|
cmd /C copy "$name~.bat" "%LOCALAPPDATA%\\wsltty\\$name~.bat"
|
||||||
fi
|
cmd /C copy "$name~.bat" "%LOCALAPPDATA%\\Microsoft\\WindowsApps\\$name~.bat"
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user