Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Dec 9, 2023
1 parent 7456980 commit 2a99bac
Show file tree
Hide file tree
Showing 38 changed files with 577 additions and 482 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/CI.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
. $PSScriptRoot/../../src/main.ps1

try{
. $PSScriptRoot/../../opt/install.ps1 -Force -StartEsh no

. $PSScriptRoot/../../src/main.ps1
$EshellUI.Init($MyInvocation)
$EshellUI.Start()
}
catch{

. $PSScriptRoot/../../opt/uninstall.ps1 -Force -RemoveDir no
}catch{}

if($error){
$error | ForEach-Object {
Write-Output "::error file=$($_.InvocationInfo.ScriptName),line=$($_.InvocationInfo.ScriptLineNumber),col=$($_.InvocationInfo.OffsetInLine),endColumn=$($_.InvocationInfo.OffsetInLine),tittle=error::script error"
Write-Output "::group::script stack trace"
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

## 快速开始

运行`opt/install`以快速开始(你甚至不需要clone这个项目):
运行[`esh.exe`](https://github.com/steve02081504/esh/releases/latest/download/esh.exe)以在不进行安装的情况下开始
对于单文件exe 你可以通过`esh -Command $EshellUI.RunInstall()`来安装esh到系统环境中

或者运行`opt/install`以快速开始(你甚至不需要clone这个项目):

```powershell
& { (Invoke-WebRequest https://bit.ly/EshInstall).Content | Invoke-Expression }
Expand Down Expand Up @@ -116,6 +119,7 @@ rm -rf superhavyrock
│ │ └───special #特殊命令脚本
│ ├───opt #安装 卸载 启动脚本 基础文件
│ └───scripts #收录脚本工具
├───runner #exe文件编译文件夹 包含源码和构建脚本
├───img #图片资源
├───opt #安装 卸载 启动脚本
└───path #用于加入环境变量的文件夹
Expand Down
2 changes: 2 additions & 0 deletions data/git_icon.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=..\img\git.ico,0
2 changes: 1 addition & 1 deletion desktop.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[.ShellClassInfo]
IconResource=C:\WINDOWS\System32\SHELL32.dll,267
IconResource=.\img\esh.ico,0
Binary file removed img/cmd.ico
Binary file not shown.
Binary file added img/esh.ico
Binary file not shown.
Binary file added img/git.ico
Binary file not shown.
19 changes: 6 additions & 13 deletions opt/install.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env pwsh
[CmdletBinding()]param([switch]$FromScript=$false)
[CmdletBinding()]param(
[switch]$Force=$false,
[ValidateSet('yes', 'no', 'ask', 'auto')][string]$StartEsh='auto',
[parameter(DontShow)][switch]$FromScript=$false
)

function illusionlimb($path) {
Invoke-Expression $(if (Test-Path $PSScriptRoot/../path/esh) { Get-Content "$PSScriptRoot/$path" -Raw }
Expand Down Expand Up @@ -31,15 +35,4 @@ else {
if ($EshellUI) { Write-Host "(并且你正在使用它 :))" }
}

. $eshDir/src/opt/install.ps1

if (-not (Get-Command pwsh -ErrorAction Ignore)) {
$Host.UI.WriteErrorLine("esh的运行需要PowerShell 6或以上`n访问 https://aka.ms/pscore6 来获取PowerShell 6+ 并使得``pwsh``命令在环境中可用以使得esh能够正常工作")
}
elseif ((-not $EshellUI) -and (YorN "要使用 Eshell 吗?")) {
if ($FromScript -or ($PSVersionTable.PSVersion.Major -lt 6)) {
. $eshDir/opt/run
[System.Environment]::Exit($LastExitCode)
}
else { . $eshDir/opt/run.ps1 -Invocation $MyInvocation }
}
. $eshDir/src/opt/install.ps1 -Force:$Force -StartEsh:$StartEsh -FromScript:$FromScript
25 changes: 22 additions & 3 deletions opt/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ while [[ $# -gt 0 ]]; do
command="$2"
shift 2
else
echo "Error: Missing argument after -Command"
echo "Error: Missing argument after -Command" >&2
exit 1
fi
;;
-File)
if [[ $# -gt 1 ]]; then
File="$2"
shift 2
else
echo "Error: Missing argument after -File" >&2
exit 1
fi
;;
Expand All @@ -29,9 +38,19 @@ if [[ -d "/c/Windows" ]]; then
fi

if [[ -z "$command" ]]; then
pwsh $parsed_args -nologo -NoExit -File "$SCRIPT_DIR/run.ps1"
if [[ -z "$File" ]]; then
pwsh $parsed_args -nologo -NoExit -File "$SCRIPT_DIR/run.ps1"
else
File=$(echo "$File" | sed -e 's/"/`"/g')
pwsh $parsed_args -nologo -NoExit -Command ". $SCRIPT_DIR/run.ps1 ; . $File"
fi
else
command=$(echo "$command" | sed -e 's/"/`"/g')
pwsh $parsed_args -nologo -Command ". $SCRIPT_DIR/run.ps1 ; Invoke-Expression $command"
if [[ -z "$File" ]]; then
pwsh $parsed_args -nologo -Command ". $SCRIPT_DIR/run.ps1 ; Invoke-Expression $command"
else
File=$(echo "$File" | sed -e 's/"/`"/g')
pwsh $parsed_args -nologo -Command ". $SCRIPT_DIR/run.ps1 ; . $File ; Invoke-Expression $command"
fi
fi
exit $?
33 changes: 28 additions & 5 deletions opt/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,42 @@ for %%i in (%*) do (
set "command=%%i"
set "hasCommand="
) else (
if "%%i"=="-Command" (
set "hasCommand=true"
) else (
if defined hasFile (
set "hasFile="
set "remainingArgs=!remainingArgs! %%i"
) else (
if "%%i"=="-Command" (
set "hasCommand=true"
) else (
if "%%i"=="-File" (
set "hasFile=true"
) else (
set "remainingArgs=!remainingArgs! %%i"
)
)
)
)
)

if defined command (
set "command=!command:"=""!"
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; Invoke-Expression !command!"
)
if defined File (
set "File=!File:"=""!"
)

if defined command (
if defined File (
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; . !File!; Invoke-Expression !command!"
) else (
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; Invoke-Expression !command!"
)
) else (
pwsh !remainingArgs! -nologo -NoExit -File "%~dp0\run.ps1"
if defined File (
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; . !File!"
) else (
pwsh !remainingArgs! -nologo -NoExit -File "%~dp0\run.ps1"
)
)

@echo on
Expand Down
7 changes: 5 additions & 2 deletions opt/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env pwsh

[CmdletBinding()]param(
[switch]$Force=$false,
[ValidateSet('no', 'yes', 'ask', 'auto')][string]$RemoveDir='auto'
)
function illusionlimb($path) {
Invoke-Expression $(if (Test-Path $PSScriptRoot/../path/esh) { Get-Content "$PSScriptRoot/$path" -Raw }
else { (Invoke-WebRequest "https://github.com/steve02081504/esh/raw/master/opt/$path").Content })
Expand All @@ -17,4 +20,4 @@ else {
if ($EshellUI) { Write-Host "(并且你正在使用它 :()" }
}

. $eshDir/src/opt/uninstall.ps1
. $eshDir/src/opt/uninstall.ps1 -Force:$Force -RemoveDir:$RemoveDir
1 change: 1 addition & 0 deletions runner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/esh.exe
6 changes: 6 additions & 0 deletions runner/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[CmdletBinding()]param ($OutputFile = "$PSScriptRoot/esh.exe")

if (-not (Get-Module -ListAvailable ps2exe)) {
Install-Module ps2exe
}
Invoke-ps2exe $PSScriptRoot/main.ps1 $OutputFile -NoConsole -iconFile $PSScriptRoot/../img/esh.ico -title 'E-Shell' -description 'E-Shell' -version '1960.7.17.13' -company 'E-tek' -product 'E-Sh' -copyright '(c) E-tek Corporation. All rights reserved.'
2 changes: 2 additions & 0 deletions runner/desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=C:\WINDOWS\System32\SHELL32.dll,214
66 changes: 66 additions & 0 deletions runner/main.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
param(
[switch]$RunInstall=$false,
[Parameter(ValueFromRemainingArguments = $true)]
$RemainingArguments
)
if((Get-ExecutionPolicy) -eq 'Restricted'){ Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force }
$env:Path.Split(";") | ForEach-Object {
if ($_ -and (-not (Test-Path $_ -PathType Container))) {
Write-Warning "检测到无效的环境变量于$_,请考虑删除"
}
elseif ($_ -like "*[\\/]esh[\\/]path*") {
$eshDir = $_ -replace "[\\/]path[\\/]*$", ''
$eshDirFromEnv = $true
}
}
if (-not $eshDir) {
$eshDir = if (Test-Path $env:LOCALAPPDATA/esh) { "$env:LOCALAPPDATA/esh" }
}

if (-not $eshDir) {
Remove-Item $env:LOCALAPPDATA/esh -Confirm -ErrorAction Ignore -Recurse
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止程序")
exit 1
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
$eshDir = "$env:LOCALAPPDATA/esh"
try { Invoke-WebRequest 'https://bit.ly/SAO-lib' -OutFile "$eshDir/data/SAO-lib.txt" }
catch {
Write-Host "啊哦 SAO-lib下载失败了`n这不会影响什么,不过你可以在Esh启动后使用``Update-SAO-lib``来让Esh有机会显示更多骚话"
}
}

if ($RunInstall){
. $eshDir/src/opt/install.ps1 $RemainingArguments
exit
}
if (-not (Get-Command pwsh -ErrorAction Ignore)) {
$Host.UI.WriteErrorLine("esh的运行需要PowerShell 6或以上`n访问 https://aka.ms/pscore6 来获取PowerShell 6+ 并使得``pwsh``命令在环境中可用以使得esh能够正常工作")
do {
$response = $Host.UI.PromptForChoice("未找到可用的pwsh", "尝试自动安装PowerShell吗?", @("自动安装","带我到下载页面","退出"), 0)
} until ($response -ne -1)
switch ($response) {
0 {
if (-not (Get-Command winget -ErrorAction Ignore)) {
Import-Module Appx
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
}
Invoke-Expression "winget install --id Microsoft.Powershell $(
if([System.Environment]::OSVersion.Version.Major -le 7){'-v 7.2.15'}
)"
}
1 { Start-Process https://aka.ms/pscore6 }
2 { exit 1 }
}
}
if (Get-Command pwsh -ErrorAction Ignore) {
if (Get-Command wt -ErrorAction Ignore) {
wt $eshDir/path/esh.cmd $RemainingArguments
}
else{ & $eshDir/path/esh $RemainingArguments }
}
4 changes: 1 addition & 3 deletions src/commands/copilot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ function global:Install-Copilot {
if (-not (Test-Command gh)) {
#github cli not found
if (Test-Command winget) {
try {
winget install GitHub.cli
}
try { winget install GitHub.cli }
catch {
Out-Error 'Install github cli failed.'
throw
Expand Down
6 changes: 2 additions & 4 deletions src/commands/special/linux_bins.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ function global:cd {
#所以我们只能通过Set-Location来模拟cd的行为
$IsLinuxBin = $Path.Length -eq 0
function baseCD ($Path, [switch]$IsFollowSymbolicLink = $true) {
if ($Path.Length -eq 0) {
Set-Location ~
}
elseif (-not $IsFollowSymbolicLink) {
$Path ??= '~'
if (-not $IsFollowSymbolicLink) {
#循环分割路径,检查每一级路径是否是符号链接
$PreviousPath = ""
while ($Path) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function global:Update-EShell {
if (Test-Path "$espath/.git/config") {
$pathNow = $PWD
Set-Location $espath
git pull
git pull --rebase
Set-Location $pathNow
reload
return
Expand All @@ -41,8 +41,8 @@ function global:Update-EShell {
try {
#下载最新的EShell
Invoke-WebRequest 'https://github.com/steve02081504/esh/archive/refs/heads/master.zip' -OutFile "$datapath/master.zip"
#删除旧的src以确保干净
Remove-Item "$espath/src" -Recurse -Force
#删除除了data和desktop.ini文件夹以外的所有文件
Get-ChildItem "$espath" -Force | Where-Object { $_.Name -notin @('data', 'desktop.ini') } | Remove-Item -Recurse -Force
#更新文件
Rename-Item "$espath" "$praentpath/esh-master"
Expand-Archive "$praentpath/esh-master/data/master.zip" "$praentpath" -Force
Expand Down
19 changes: 7 additions & 12 deletions src/fixers/CodePageFixer.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# 假如在win8以下的系统上运行,那么我们需要检查和修复输出编码
if ($IsWindows -and ([System.Environment]::OSVersion.Version.Major -le 7)) {
if ($IsWindows -and ([Console]::OutputEncoding -ne [System.Text.Encoding]::UTF8)) {
$CursorPosBackUp = $host.UI.RawUI.CursorPosition
$CodingBackUp = [Console]::OutputEncoding
$TestText = '中文测试你好小笼包我是冰激凌'
function TestAndSet ($Encoding) {
try { Write-Host $TestText }
catch { $error.RemoveAt(0); [Console]::OutputEncoding = $Encoding }
$host.UI.RawUI.CursorPosition = $CursorPosBackUp
foreach ($Encoding in [System.Text.Encoding]::GetEncodings()) {
try { Write-Host $TestText;break }
catch { $error.RemoveAt(0);[Console]::OutputEncoding = $Encoding }
try{ $host.UI.RawUI.CursorPosition = $CursorPosBackUp } catch { $Error.RemoveAt(0) }
}
TestAndSet ([System.Text.Encoding]::GetEncoding(936))
TestAndSet $CodingBackUp
Write-Host $(' ' * $TestText.Length * 2)
$host.UI.RawUI.CursorPosition = $CursorPosBackUp
Remove-Variable @('CursorPosBackUp', 'CodingBackUp', 'TestText')
Remove-Item function:TestAndSet
try{ $host.UI.RawUI.CursorPosition = $CursorPosBackUp } catch { $Error.RemoveAt(0) }
Remove-Variable @('CursorPosBackUp', 'TestText')
}
8 changes: 4 additions & 4 deletions src/fixers/VSCodeBackgroundJobsDisAbler.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if ($EshellUI.Im.VSCodeExtension -and ($host.Version -le [version]'2023.8.0')) {
$EshellUI.BackgroundJobs.Add({
Unregister-Event -SubscriptionId $EshellUI.OtherData.IdleEvent.SubscriptionId -Force
$EshellUI.OtherData.Remove('IdleEvent')
}) | Out-Null
$EshellUI.BackgroundJobs | ForEach-Object { & $_ }
$EshellUI.BackgroundJobs.Clear()
Unregister-Event -SubscriptionId $EshellUI.RegisteredEvents.IdleEvent.RawData.SubscriptionId -Force
$EshellUI.RegisteredEvents.Remove('IdleEvent')
$EshellUI.LoadingLog.AddWarning(
"EshellUI's BackgroundJobs has been disabled due to a bug of PowerShell VSCode Extension.
See $(
Expand Down
Loading

0 comments on commit 2a99bac

Please sign in to comment.