iNNOKENTIY21
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Цвета + Шрифт + Prompt - Для #region PowerShell Readline Option всё, что между, до ближайшего #endregion —
нужен модуль GitHub - PowerShell/PSReadLine (в Windows 10 включен по умолчанию) , а к нему неплох GitHub - omniomi/AdvancedHistory - Цвета (terminal/src/tools/ColorTool · microsoft/terminal · GitHub)
PSConsoleColor.ini Код: [table] DARK_BLACK = 16, 24, 32 DARK_BLUE = 16, 64, 128 DARK_GREEN = 32, 128, 16 DARK_CYAN = 64, 128, 128 DARK_RED = 128, 16, 32 DARK_MAGENTA = 128, 64, 128 DARK_YELLOW = 128, 128, 64 DARK_WHITE = 192, 192, 192 BRIGHT_BLACK = 128, 128, 128 BRIGHT_BLUE = 64, 128, 222 BRIGHT_GREEN = 128, 222, 64 BRIGHT_CYAN = 128, 222, 222 BRIGHT_RED = 255, 64, 128 BRIGHT_MAGENTA = 222, 96, 192 BRIGHT_YELLOW = 222, 222, 128 BRIGHT_WHITE = 255, 255, 255 | - Шрифт DejaVu Sans Mono for Powerline
- Профиль
Код: <# Название: PowerShell Profile Автор: iNNOKENTIY21 Совместимость: Проверялось на Windows 10, PowerShell v5.1 Версия: 0.99 #> #region Variables # Путь к скриптам (папка Scripts в папке профиля) $DirectoryScripts = Join-Path -Path (Split-Path $PROFILE) -ChildPath 'Scripts' # Путь к программам пользователя $DirectoryPrograms = "$env:LocalAppData\Programs" #endregion #region Alias # Псевдоним для редактора текста Set-Alias sublt "$env:ProgramFiles\Sublime Text 3\sublime_text.exe" Set-Alias edit sublt # Псевдоним для архиватора Set-Alias 7z "$env:ProgramFiles\7-Zip\7z.exe" # Псевдоним для аудио плеера Set-Alias foobar2000 "${env:ProgramFiles(x86)}\foobar2000\foobar2000.exe" # Псевдоним для универсального плеера Set-Alias mpv "$DirectoryPrograms\mpv\mpv.exe" # Псевдоним для скрипта управления списком просмотренных сериалов: MySeries Set-Alias MyTVSeries "$DirectoryScripts\MyTVSeries\MyTVSeries.ps1" #endregion #region Functions function IsAdmin { # Определение текущего пользователя $user = [Security.Principal.WindowsIdentity]::GetCurrent() # Определение пользователя с административными правами $admin = [Security.Principal.WindowsBuiltinRole]::Administrator # Определение роли текущего пользователя, администратор или нет (New-Object Security.Principal.WindowsPrincipal $user).IsInRole($admin) } function Prompt { [string] $Path = $PWD.Path # Задать заголовк окна консоли $Host.UI.RawUI.WindowTitle = "{0}: {1} v{2} > {3}" -f ( $env:USERNAME, 'Windows PowerShell', $host.Version.ToString(), $Path ) [string[]] $PathInArray = $PWD.Path.Split('\') if ($PathInArray -and $PathInArray.Count -gt 3) { $Path = "..\{0}" -f (($PathInArray | Select-Object -Last 2) -join "\") } function Write-HistoryID { param ( [consolecolor] $BackgroundColor, [consolecolor] $ForegroundColor ) if ($MyInvocation.HistoryId) { $Params = @{ Object = " $($MyInvocation.HistoryId)" BackgroundColor = $BackgroundColor ForegroundColor = $ForegroundColor NoNewline = $true } Write-Host @Params } } function Write-Delimeters { param ( [consolecolor] $BackgroundColor, [consolecolor] $ForegroundColor ) $Params = @{ Object = "$([char]0xE0B0)$([char]0xE0B1)" BackgroundColor = $BackgroundColor ForegroundColor = $ForegroundColor NoNewline = $true } Write-Host @Params } function Write-Path { param ( [consolecolor] $BackgroundColor, [consolecolor] $ForegroundColor ) $PathParams = @{ Object = " $Path" BackgroundColor = $BackgroundColor ForegroundColor = $ForegroundColor NoNewline = $true } Write-Host @PathParams } if (IsAdmin) { $LockIconParams = @{ Object = "$([char]0xE0A2)" BackgroundColor = [consolecolor]::DarkRed ForegroundColor = [consolecolor]::White NoNewline = $true } Write-Host @LockIconParams Write-Delimeters -BackgroundColor Red -ForegroundColor DarkRed Write-HistoryID -BackgroundColor Red -ForegroundColor White Write-Delimeters -BackgroundColor DarkRed -ForegroundColor Red Write-Path -BackgroundColor DarkRed -ForegroundColor White Write-Delimeters -BackgroundColor Black -ForegroundColor DarkRed } else { Write-HistoryID -BackgroundColor DarkBlue -ForegroundColor White Write-Delimeters -BackgroundColor Blue -ForegroundColor DarkBlue Write-Path -BackgroundColor Blue -ForegroundColor White Write-Delimeters -BackgroundColor Black -ForegroundColor Blue } ' ' } #endregion #region PowerShell Readline Option Set-PSReadlineOption -ShowToolTips Set-PSReadlineOption -HistoryNoDuplicates # Цвета Set-PSReadlineOption -TokenKind Command -ForegroundColor Yellow -BackgroundColor Black Set-PSReadlineOption -TokenKind Parameter -ForegroundColor DarkGray -BackgroundColor Black Set-PSReadlineOption -TokenKind Comment -ForegroundColor DarkGreen -BackgroundColor Black Set-PSReadlineOption -TokenKind Operator -ForegroundColor Blue -BackgroundColor Black Set-PSReadlineOption -TokenKind Variable -ForegroundColor Magenta -BackgroundColor Black Set-PSReadlineOption -TokenKind Keyword -ForegroundColor Magenta -BackgroundColor Black Set-PSReadlineOption -TokenKind String -ForegroundColor Green -BackgroundColor Black Set-PSReadlineOption -TokenKind Type -ForegroundColor DarkCyan -BackgroundColor Black Set-PSReadlineOption -TokenKind None -ForegroundColor White -BackgroundColor Black Set-PSReadlineOption -TokenKind Number -ForegroundColor Yellow -BackgroundColor Black Set-PSReadlineOption -TokenKind Member -ForegroundColor Cyan -BackgroundColor Black # (Tab) Set-PSReadlineKeyHandler -Key Tab -Function Complete # Копирование экрана консоли (F12) Set-PSReadlineKeyHandler -key F12 -Function CaptureScreen # Открытие файла истории в редакторе (Alt+F11) Set-PSReadlineKeyHandler -Chord Alt+F11 -ScriptBlock { [string] $Path = (Get-PSReadlineOption).HistorySavePath # Если alias edit существует, открываем им, иначе блокнотом if (Get-Alias edit) { $Program = "Edit" } else { $Program = notepad.exe } & $Program $Path } # Замена псевдонимов в строке ввода на полное написание команд (Alt+F6) Set-PSReadlineKeyHandler -Chord Alt+F6 -ScriptBlock { param($key, $arg) $ast = $null $tokens = $null $errors = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState( [ref]$ast, [ref]$tokens, [ref]$errors, [ref]$cursor) $startAdjustment = 0 foreach ($token in $tokens) { if ($token.TokenFlags -band [System.Management.Automation.Language.TokenFlags]::CommandName) { $alias = $ExecutionContext.InvokeCommand.GetCommand($token.Extent.Text, 'Alias') if ($alias -ne $null) { $resolvedCommand = $alias.ResolvedCommandName if ($resolvedCommand -ne $null) { $extent = $token.Extent $length = $extent.EndOffset - $extent.StartOffset [Microsoft.PowerShell.PSConsoleReadLine]::Replace( $extent.StartOffset + $startAdjustment, $length, $resolvedCommand) # Our copy of the tokens won't have been updated, so we need to # adjust by the difference in length $startAdjustment += ($resolvedCommand.Length - $length) } } } } } # Вызов справки (F1) Set-PSReadlineKeyHandler -Key F1 -ScriptBlock { param($key, $arg) $ast = $null $tokens = $null $errors = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState( [ref]$ast, [ref]$tokens, [ref]$errors, [ref]$cursor) $commandAst = $ast.FindAll( { $node = $args[0] $node -is [System.Management.Automation.Language.CommandAst] -and $node.Extent.StartOffset -le $cursor -and $node.Extent.EndOffset -ge $cursor }, $true) | Select-Object -Last 1 if ($commandAst -ne $null) { $commandName = $commandAst.GetCommandName() if ($commandName -ne $null) { $command = $ExecutionContext.InvokeCommand.GetCommand($commandName, 'All') if ($command -is [System.Management.Automation.AliasInfo]) { $commandName = $command.ResolvedCommandName } if ($commandName -ne $null) { Get-Help $commandName -ShowWindow } } } } #endregion #region Advanced History Import-Module AdvancedHistory Enable-AdvancedHistory -Unique #endregion | Подсматривал там: My PowerShell profile – Nick James |