¿Hay alguna manera de hacer que Powershell herede el indicador cmd?

¿Hay alguna manera de hacer que Powershell herede el indicador cmd?

En el shell cmd, es posible configurar (y guardar) el mensaje usando el comando PROMPT y otros. Sin embargo, cuando ingresa a Powershell desde cmd, vuelve al mensaje predeterminado de Windows, generalmente el directorio actual.

¿Hay alguna forma de obligar a Powershell a utilizar el indicador de Windows actual?

Respuesta1

Conseguí que esto funcionara gracias a los comentarios muy útiles. En caso de que alguien más tenga el mismo problema:

$profile

Proporciona la ubicación donde existe (o existiría) el perfil de Powershell. Si senoexiste, el siguiente comando lo crearía:

new-item -itemtype file -path $profile -force

Aquí, podemos simplemente escribir una función de aviso. Generalmente configuro el mío para el usuario actual así:

function prompt {"PS: $(echo 'RobbieDee')>"}

Respuesta2

Promptse establece globalmente a través de%UserProfile%\Documents\WindowsPowerShell\profile.ps1

  • sin color:

    Function set-prompt {
      "$ESC[$($executionContext.SessionState.Path.CurrentLocation)$('$' * ($nestedPromptLevel + 1)) $ESC[0m"
    }
    
  • con color:

    switch ($Action) {
    
        "Default" {
            Function global:prompt {
                if (test-path variable:/PSDebugContext) { '[DBG]: ' }
                    write-host " "
                    write-host ("$ESC[48;2;40;40;40m$ESC[38;2;170;210;0m$(Get-Location) $ESC[0m $ESC[0m")
    
                if ( $host.UI.RawUI.WindowTitle -match "Administrator" ) {
                    $Host.UI.RawUI.ForegroundColor = 'Red'
                    $(if ($nestedpromptlevel -ge 1) {
                        write-host ('PS $$ ') -ForegroundColor Red -NoNewLine
                    } else {
                        write-host ('PS $ ') -ForegroundColor Red -NoNewLine
                    })
                } else {
                    $(if ($nestedpromptlevel -ge 1) {
                        write-host ('PS $$ ') -ForegroundColor Blue -NoNewLine
                    } else {
                        write-host ('PS $ ') -ForegroundColor Blue -NoNewLine
                    })
                }
    
                return " "
            }
        }
    }
    
    set-prompt Default
    
    • Mostrar un mensaje de texto coloreado para el usuario y un mensaje de texto rojo para un administrador
    • Permite cambiar perfiles sobre la marcha:
      • Copie/pegue Defaultla sección debajo de sí misma y edítela en consecuencia(incluido el nombre, es decir Default). Recargar sesión y cambiar de mensaje vía set-prompt Default||set-prompt <name>

información relacionada