Cuma Eğlencesi: Başka Bir Noel İstemi


Function Prompt {

#only change background color if in December
if ((Get-Date).Month -eq 12 -And (Get-Date).Day -lt 25) {
Switch ($host.ui.RawUI.BackgroundColor) {

"DarkGreen" { $c = "DarkRed" }
"DarkRed"   { $c = "DarkGreen" }
 Default    { 
            #get a random color
            $c = Get-Random -InputObject "DarkRed","DarkGreen"
            }

} #switch

$host.ui.RawUI.BackgroundColor = $c
}

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

}

Özelleştirmemin yalnızca Aralık ayı boyunca ve Noel'den önce gerçekleşmesi için bir mantık ekledim. İstem, konsolunuzun arka plan rengini KoyuKırmızı ve KoyuYeşil arasında değiştirir. İlk çalıştırdığınızda istem rastgele bir renk seçecektir. İstemi yükledikten sonra Clear-Host'u veya CLS'yi çalıştırmak isteyebilirsiniz.

Bundan sonra arka plan rengi değişecek ve aşağıdaki gibi bir efekt elde edeceksiniz:

Farklı komutların konsola nasıl yazıldığını görmek ilginç. Hatta özellikle şenlikli bir ruh halindeyseniz her iki önerimi de birleştirebilirsiniz.

Function Prompt {

#only change background color if in December
if ((Get-Date).Month -eq 12 -And (Get-Date).Day -lt 25) {
Switch ($host.ui.RawUI.BackgroundColor) {

"DarkGreen" { $c = "DarkRed" }
"DarkRed"   { $c = "DarkGreen" }
 Default    { 
            #get a random color
            $c = Get-Random -InputObject "DarkRed","DarkGreen"
            }

} #switch

$host.ui.RawUI.BackgroundColor = $c


#get current year
    $year = (Get-Date).year
    #get a timespan between Christmas for this year and now

    $time=[datetime]"25 December $year" - (Get-Date)
    #turn the timespan into a string and strip off the milliseconds
    $timestring = $time.ToString().Substring(0,11)

    #get random string of decorative characters
    $front = -join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] })
    $back = -join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] })
    $text="[{0}Christmas in {1}{2}]" -f $front,$timestring,$back

    #get each character in the text and randomly assign each a color
    $text.tocharArray() | foreach {

    $i = get-random -Minimum 1 -Maximum 20
    switch ($i) {
      {$i -le 20 -and $i -gt 15} { $color = "Red"}
      {$i -le 16 -and $i -gt 10} { $color = "Green" }
      {$i -le 10 -and $i -gt 5}{ $color = "DarkGreen"}
      default {$color = "White"}
    }

    #write each colorized character
    write-host $_ -nonewline -foregroundcolor $color
    } #foreach

} #if Christmas time

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

} #end prompt function

Bunun muhtemelen biraz eğlenmek ve belki de bazı PowerShell komut dosyası oluşturma kavramlarını anlamak dışında pratik bir değeri yoktur. Umarım tatil alışverişiniz iyi gidiyordur. Harika bir hafta sonu geçirin.

İlgili makaleler