Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(powershell): fix powershell prompt #101

Merged
merged 3 commits into from
Mar 13, 2024

Conversation

LordHumphrey
Copy link
Contributor

  1. Fix powershell prompt has been replaced, just using the original prompt.
  2. 获取到原prompt后,先尝试匹配是否是默认prompt,如果是则适用默认方式生成prompt,否则适用自定义方式。
  3. 为什么没有直接使用原始prompt?
    "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; 这里的>似乎会变化,如果直接返回原始prompt就出现不一致。

internal/shell/powershell.go Outdated Show resolved Hide resolved
internal/shell/powershell.go Outdated Show resolved Hide resolved
@@ -33,16 +33,22 @@ const hook = `
{{.EnvContent}}

$__VFOX_PID=$pid;
$originalPrompt = & $function:prompt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一步为什么要执行呢, 我们可以不执行啊, 对不对? 直接放到我们自己的prompt最后 去执行不就行啦?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我试了,必须在进入prompt函数之前执行& $function:prompt,如果按照您的写法,会出现一下错误

Line |
 334 |   Invoke-Expression "$(vfox activate pwsh)"
     |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unexpected token 'function' in expression or statement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

报错是因为你没有加;吧, 我本地试了一下没问题.

@aooohan
Copy link
Member

aooohan commented Mar 12, 2024

思路是对的, 就是写的有些复杂了.

$originalPrompt = $function:prompt;
function prompt {
    $export = &'{{.SelfPath}}' env -s pwsh;
    if ($export) {
        Invoke-Expression -Command $export;
    }
    &$originalPrompt;
}

@LordHumphrey
Copy link
Contributor Author

思路是对的, 就是写的有些复杂了.

$originalPrompt = $function:prompt;
function prompt {
    $export = &'{{.SelfPath}}' env -s pwsh;
    if ($export) {
        Invoke-Expression -Command $export;
    }
    &$originalPrompt;
}

好的,感谢您的指导,请问我接下来是再发起一个pr吗

@aooohan
Copy link
Member

aooohan commented Mar 12, 2024

思路是对的, 就是写的有些复杂了.

$originalPrompt = $function:prompt;
function prompt {
    $export = &'{{.SelfPath}}' env -s pwsh;
    if ($export) {
        Invoke-Expression -Command $export;
    }
    &$originalPrompt;
}

好的,感谢您的指导,请问我接下来是再发起一个pr吗

在这个上面修改就行,把代码回退,重新修改就可以

1. Fix powershell prompt has been replaced, just using the original prompt.
internal/shell/powershell.go Outdated Show resolved Hide resolved
internal/shell/powershell.go Outdated Show resolved Hide resolved
@aooohan aooohan merged commit 9a77ef5 into version-fox:main Mar 13, 2024
@aooohan
Copy link
Member

aooohan commented Mar 13, 2024

@LordHumphrey 感谢贡献 👍

@LordHumphrey
Copy link
Contributor Author

@LordHumphrey 感谢贡献 👍

您太客气了,是我谢谢您,第一次给开源项目提PR,您给的帮助很大~

ShizheChang pushed a commit to ShizheChang/vfox that referenced this pull request Mar 14, 2024
…function (version-fox#101)


fix powershell hook script override original prompt function.
---------

Co-authored-by: taowong <tao6wong@gmail.com>
Co-authored-by: Han Li <aooohan@gmail.com>
@LordHumphrey LordHumphrey deleted the fix-powershell-prompt branch March 17, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants