commit bf7f6c29be00cb3e2f1d09e20be213217f90f858 Author: Yuri Plashenkov Date: Tue Apr 29 20:54:26 2025 +0300 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..351594a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.ps1] +charset = utf-8-bom +end_of_line = crlf + +[*.{cmd,bat}] +end_of_line = crlf + +[*.md] +trim_trailing_whitespace = false diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0b540a7 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2025 Yuri Plashenkov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4f2d94 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# Powerline scripts for bash, ash, PowerShell, and cmd + +![Powerline for bash, ash, PowerShell, and cmd](powerline.svg) + +Ensure you use a font that supports Powerline characters, such as [JetBrains Mono](https://www.jetbrains.com/lp/mono/). + +## Bash + +Add the contents of the `bash/powerline.sh` script to your `~/.bashrc` file. + +Customize the variables (e.g., label and color). You can use the `bash/colors.sh` script to select a color. + +## Ash (e.g., OpenWrt) + +Add the contents of the `ash/powerline.sh` script to your `~/.profile` file. + +Customize the label and color. You can use the `bash/colors.sh` script to select a color. + +## PowerShell + +First, enable the execution of PowerShell scripts (including profiles) by running the following command as an administrator: + +```powershell +Set-ExecutionPolicy RemoteSigned +``` + +Next, locate your PowerShell profile file by running: + +```powershell +$PROFILE +``` + +Copy the contents of the `powershell\powerline.ps1` file into your PowerShell profile file. + +For older PowerShell versions (e.g., PowerShell 5), ensure the profile script is saved in UTF-8 *with BOM* encoding. + +Customize the variables (e.g., label, color, adminColor). You can run the `powershell\colors.ps1` script to select colors. + +To suppress system information on PowerShell startup, add the `-NoLogo` switch to the command line in your `PowerShell` profiles within your Terminal application: + +```ps1 +pwsh -NoLogo # newer PowerShell +powershell -NoLogo # legacy PowerShell +``` + +## cmd + +Save the `cmd\prompt.cmd` file somewhere on your disk. Then, update the command line in your `cmd` profile within your Terminal application as follows: + +```ps1 +cmd /k "C:\path\to\prompt.cmd" +``` + +## Credits + +- [Yuri Plashenkov](https://plashenkov.com) + +## License + +This package is licensed under the [MIT license](LICENSE.md). diff --git a/ash/powerline.sh b/ash/powerline.sh new file mode 100644 index 0000000..32392c0 --- /dev/null +++ b/ash/powerline.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# 30 is the color you may want to modify, \h is the label + +PS1="\n\[\e[1;48;5;30;38;5;231m\] \h \[\e[;38;5;30;48;5;240m\]\[\e[38;5;252m\] \w \[\e[;38;5;240m\]\[\e[m\] " diff --git a/bash/colors.sh b/bash/colors.sh new file mode 100644 index 0000000..4c484de --- /dev/null +++ b/bash/colors.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +label="localhost" +bold=1 + +prompt_part() { printf "\e[$2;38;5;$3;48;5;${4}m $1 \e[;38;5;$4${5+;48;5;$5}m"; } + +for color in {0..255}; do + printf "\n" + prompt_part "$label" $bold 231 $color 240 + prompt_part "~" 0 252 240 + printf "\e[m $color\n" +done diff --git a/bash/powerline.sh b/bash/powerline.sh new file mode 100644 index 0000000..046c365 --- /dev/null +++ b/bash/powerline.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +prompt() { + local label="\h" + local color=30 # 30 green, 131 red + local bold=1 + + prompt_part() { PS1+="\[\e[$2;38;5;$3;48;5;${4}m\] $1 \[\e[;38;5;$4${5+;48;5;$5}m\]"; } + + PS1="\n" + if [ -n "$MC_SID" ]; then + prompt_part "$label" $bold 231 $color 237 + prompt_part "mc" $bold 231 237 240 + else + prompt_part "$label" $bold 231 $color 240 + fi + prompt_part "\w" 0 252 240 + PS1+="\[\e[m\] " +} + +PROMPT_COMMAND=prompt diff --git a/cmd/prompt.cmd b/cmd/prompt.cmd new file mode 100644 index 0000000..4b3d7b1 --- /dev/null +++ b/cmd/prompt.cmd @@ -0,0 +1,11 @@ +@echo off +chcp 65001 >nul + +set label=cmd +set color=67 +set adminColor=88 +set bold=1 + +net session >nul 2>nul && set color=%adminColor% + +prompt $e[%bold%;48;5;%color%;38;5;231m %label% $e[;38;5;%color%;48;5;240m$e[38;5;252m $p $e[;38;5;240m$e[m diff --git a/powerline.afdesign b/powerline.afdesign new file mode 100644 index 0000000..fd80fad Binary files /dev/null and b/powerline.afdesign differ diff --git a/powerline.svg b/powerline.svg new file mode 100644 index 0000000..e01a491 --- /dev/null +++ b/powerline.svg @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/powershell/Microsoft.PowerShell_profile.ps1 b/powershell/Microsoft.PowerShell_profile.ps1 new file mode 100644 index 0000000..8ffcaf8 --- /dev/null +++ b/powershell/Microsoft.PowerShell_profile.ps1 @@ -0,0 +1,19 @@ +function Prompt { + $label = "PowerShell" + $color = 12 + $adminColor = 88 + $bold = 1 + + $principal = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()) + if ($principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + $color = $adminColor + } + + $path = $pwd.Path + if ($path.StartsWith($HOME)) { + $path = "~" + $path.Substring($HOME.Length) + } + + $e = $([char]27) + return "`n$e[$bold;48;5;$color;38;5;231m $label $e[;38;5;$color;48;5;240m$e[38;5;252m $path $e[;38;5;240m$e[m " +} diff --git a/powershell/colors.ps1 b/powershell/colors.ps1 new file mode 100644 index 0000000..c97f3d4 --- /dev/null +++ b/powershell/colors.ps1 @@ -0,0 +1,7 @@ +$label = "PowerShell" +$bold = 1 + +$e = $([char]27) +foreach ($color in (0..255)) { + Write-Host "`n$e[$bold;48;5;$color;38;5;231m $label $e[;38;5;$color;48;5;240m$e[38;5;252m ~ $e[;38;5;240m$e[m $color" +}