Skip to content

Instantly share code, notes, and snippets.

@marcoandre1
Last active September 25, 2020 22:10
Show Gist options
  • Save marcoandre1/ae150961f15d89f1320b2561a5802938 to your computer and use it in GitHub Desktop.
Save marcoandre1/ae150961f15d89f1320b2561a5802938 to your computer and use it in GitHub Desktop.
Powershell configuration with Dracula theme (No admin access)

Preferred setup with powershell (No admin access)

For PowerShell 5.1, the Microsoft.PowerShell_profile.ps1 file should be located in:

C:\Users\<username>\Documents\WindowsPowerShell

Index

PSReadLine
Hub
BellStyle
Posh-Git
Dracula-Theme-PowerShell
Figlet (with Scoop)
PowerShell 7 upgrade (Not recommended)

PSReadLine

  • The PSReadLine module contains cmdlets that let you customize the command-line editing environment in PowerShell.
  • To my knowledge, PSReadLine is only available for Powershell 5.x and above. It should be shipped with PowerShell so no installation needed.
  • If PSReadLine is correctly installed, the following command in PowerShell should return without error.
Import-Module PSReadLine
  • If your get an error like below running the previous command, it means that PSReadLine is not installed.
Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Windows\System32\WindowsPowerShell\v1.0> $Error
Import-Module : The specified module 'PSReadline' was not loaded because no valid module file was found in any
module directory.
  + CategoryInfo          : ResourceUnavailable: (PSReadline:String) [Import-Module], FileNotFoundException
  + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
  • Quick fix as stated in this StackExchange answer is to run the following command in PowerShell as an administrator (Probably works in PowerShell without high privileges too, but I haven't try).
Install-Module -Name PSReadLine

Hub

  • An extension you can install from hub
  • Main use is to create repo from commandline or powershell

BellStyle

  • To avoid the bell ringing when backspacing on powershell

Posh-Git

  • Posh-Git is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt, e.g.:

C:\Users\Keith\GitHub\posh-git [master ≡ +0 ~1 -0 | +0 ~1 -0 !]>

Dracula Theme PowerShell

  • A PowerShell theme you can install from Dracula-PowerShell
  • If you are running PowerShell 5.1 you will need to use Set-PSReadLineOption -TokenKind as below instead of Set-PSReadlineOption -Color as stated in their PowerShell Configuration
  • To determine your PowerShell version use
$PSVersionTable.PSVersion
  • If you get an error for using $GitPromptSettings.DefaultPromptPrefix.Text, it means you are running posh git v0.7.3 or previous. This setting was only introduced in v1.0.0-beta1
  • If you get an error for using $GitPromptSettings.BeforeStatus.ForegroundColor = [ConsoleColor]::Blue, it means you are running posh git v1.0.0-beta1 or previous. This setting was only introduced in v1.0.0-beta2
  • The configuration settings are only going to work with posh-git v1.0.0-beta2 and further. You should try updating with the following command.
PowerShellGet\Update-Module posh-git
  • If it's not working, try updating PowerShellGet. If you can, try running the following commands from an elevated PowerShell session.
    • Get the latest Nuget provider before updating PowerShellGet.
    Install-PackageProvider Nuget –Force
    Exit
    • Install the module.
    Install-Module –Name PowerShellGet –Force
    Exit
    • Get the newest possible version.
    Update-Module -Name PowerShellGet
    Exit
    • Try to update posh-git again.
    PowerShellGet\Update-Module posh-git
    If you have gone through all those steps and you still get errors, try the following commnad.
    Install-Module posh-git -AllowPrerelease -Scope CurrentUser -RequiredVersion 1.0.0-beta2
    You can find the command here - dahlbyk/posh-git#570. The only modification from the original command is the beta version which I changed from beta1 to beta2.

Figlet (with Scoop)

  • From Figlet : Figlet is a program that makes large letters out of ordinary text.
 ,          _   _         __        __         _     _ _
/|   |     | | | |        \ \      / /__  _ __| | __| | |
 |___|  _  | | | |  __     \ \ /\ / / _ \| '__| |/ _` | |
 |   |\|/  |/  |/  /  \_    \ V  V / (_) | |  | | (_| |_|
 |   |/|__/|__/|__/\__/      \_/\_/ \___/|_|  |_|\__,_(_)

  • You can install figlet from Scoop. Depending on your powershell version or desired configuration you might need some workaround to install it but the following command in PowerShell should do it :
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# or shorter
iwr -useb get.scoop.sh | iex
  • If installed correctly, the following command in PowerShell should install figlet scoop install figlet
  • If you get the following message :
fatal: unable to access 'https://github.com/lukesampson/scoop/': SSL certificate problem: self signed certificate in certificate chain
Update failed.
  • you might be trying to go through a firewall. You can deactivate the sslverify in command line or PowerShell with git config --global http.sslverify "false". Try to install Figlet again. Once the operation works don't forget to reactivate the sslverify git config --global http.sslverify "true"

PowerShell 7 Upgrade (Not recommended)

  • If you want to upgrade to the latest version of powershell, run the following command:

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

Be aware that the location of the profile has changed to avoid conflicts with other powershell versions:

C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

You will need to install Posh-Git again via PowerShell 7: Install-Module -Name posh-git -AllowPrerelease -Force.

Finally, you will need to update the Microsoft.PowerShell_profile.ps1.

One of the problems I found was that PowerShell 7 doesn't allow me to change properties. See this r/PowerShell question. The proposed fix worked but I found it was better (for me) to just execute the existing shortcut with admin rights always by default (change properties of shortcut).

  • As a side note, the hub command seems to be broken. This is true for all versions of PowerShell. There is maybe a problem with the hub.ps1 file:
~ $ hub
&: C:\Users\<user>\scoop\shims\hub.ps1:3
Line |
   3 | ... on.expectingInput) { $input | & $path @args } else { & $path @args ...
     |
     | The term
     | 'C:\Users\<user>\scoop\shims\..\apps\hub\current\bin\hub.exe'
     | is not recognized as the name of a cmdlet, function, script
     | file, or operable program. Check the spelling of the name, or
     | if a path was included, verify that the path is correct and
     | try again.

Will try to get a clean install to confirm problem.

Import-Module PSReadLine
Set-Alias git hub
Set-PSReadLineOption -BellStyle None
Import-Module posh-git
Set-Location C:\users\<username>
# Dracula readline configuration. Requires version 2.0, if you have 1.2 convert to `Set-PSReadlineOption -TokenType`
Set-PSReadLineOption -TokenKind Command -ForegroundColor Green
Set-PSReadLineOption -TokenKind Parameter -ForegroundColor Gray
Set-PSReadLineOption -TokenKind Operator -ForegroundColor Magenta
Set-PSReadLineOption -TokenKind Variable -ForegroundColor White
Set-PSReadLineOption -TokenKind String -ForegroundColor Yellow
Set-PSReadLineOption -TokenKind Number -ForegroundColor Blue
Set-PSReadLineOption -TokenKind Type -ForegroundColor Cyan
Set-PSReadLineOption -TokenKind Comment -ForegroundColor DarkCyan
# Dracula Prompt Configuration
$GitPromptSettings.DefaultPromptPrefix.Text = "$([char]0x2192) " # arrow unicode symbol
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Green
$GitPromptSettings.DefaultPromptPath.ForegroundColor =[ConsoleColor]::Cyan
$GitPromptSettings.DefaultPromptSuffix.Text = "$([char]0x203A) " # chevron unicode symbol
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::Magenta
# Dracula Git Status Configuration
$GitPromptSettings.BeforeStatus.ForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.BranchColor.ForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.AfterStatus.ForegroundColor = [ConsoleColor]::Blue
figlet -c -f smslant "Getting started ..." | Write-Host -ForegroundColor Green
figlet -c -f smslant "Welcome" | Write-Host -ForegroundColor Magenta
whoami | figlet -c -f smslant | Write-Host -ForegroundColor Yellow
Get-Date -UFormat "%A" | figlet -c -f smslant | Write-Host -ForegroundColor Blue
Get-Date -UFormat "%e %B %Y" | figlet -c -f smslant | Write-Host -ForegroundColor Cyan
Copy link

ghost commented Dec 2, 2019

Hi. Is figlet available to Win32 systems? I can't find where.

@marcoandre1
Copy link
Author

Hello @joaosantana! The way I install figlet is through scoop. Once you have it, you can run:

scoop install figlet

If you really need the 32bit version you will need to run the following command according to this issue on scoop:

scoop install figlet -a x86

or

scoop install figlet -a 32bit

But I am not sure if the 32bit version of figlet exists. Try it!

Copy link

ghost commented Dec 2, 2019

@marcoandre1 Thank you, I've installed scoop and figlet as you told me how.

I have a friendly fuction to greet users when they do logon, and figlet will make this greeting more friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment