gpt4 book ai didi

带有类似 rc 文件的 PowerShell 配置

转载 作者:行者123 更新时间:2023-12-02 22:09:55 33 4
gpt4 key购买 nike

为了定义,我应该写什么脚本和在哪里:

  • alias for ll="ls -l"
  • alias/function cd = "original cd; ll"

  • 所以,我的问题是 Windows 7 上 Power Shell 的 rc 文件在哪里以及如何别名 llls -lcdcd; ll ?

    最佳答案

    在输入 $profile 时 power shell 指向的位置创建一个文件如果不存在,请按 Enter。 (有关更多信息,请查看 here。)

    我还在 powershell.exe 旁边找到了很多很好的例子。在我的系统中有一个示例文件夹,其中有一个名为 profile.ps1 的文件。使用以下代码:

    set-alias cat        get-content
    set-alias cd set-location
    set-alias clear clear-host
    set-alias cp copy-item
    set-alias h get-history
    set-alias history get-history
    set-alias kill stop-process
    set-alias lp out-printer
    set-alias ls get-childitem
    set-alias mount new-mshdrive
    set-alias mv move-item
    set-alias popd pop-location
    set-alias ps get-process
    set-alias pushd push-location
    set-alias pwd get-location
    set-alias r invoke-history
    set-alias rm remove-item
    set-alias rmdir remove-item
    set-alias echo write-output

    set-alias cls clear-host
    set-alias chdir set-location
    set-alias copy copy-item
    set-alias del remove-item
    set-alias dir get-childitem
    set-alias erase remove-item
    set-alias move move-item
    set-alias rd remove-item
    set-alias ren rename-item
    set-alias set set-variable
    set-alias type get-content

    function help
    {
    get-help $args[0] | out-host -paging
    }

    function man
    {
    get-help $args[0] | out-host -paging
    }

    function mkdir
    {
    new-item -type directory -path $args
    }

    function md
    {
    new-item -type directory -path $args
    }

    function prompt
    {
    "PS " + $(get-location) + "> "
    }

    & {
    for ($i = 0; $i -lt 26; $i++)
    {
    $funcname = ([System.Char]($i+65)) + ':'
    $str = "function global:$funcname { set-location $funcname } "
    invoke-expression $str
    }
    }

    还要考虑以下问题。执行位于 $profile 中的文件时,您可能会遇到以下错误:

    "Microsoft.PowerShell_profile.ps" cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.



    解决方案:
    检查当前的执行策略
    PS C:\Windows\System32> Get-ExecutionPolicy
    Restricted
    PS C:\Windows\System32>

    要更改执行策略以允许 PowerShell 从本地文件执行脚本,请运行以下命令:
    PS C:\Windows\System32> Set-Executionpolicy RemoteSigned -Scope CurrentUser

    关于带有类似 rc 文件的 PowerShell 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12143245/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com