微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PowerShell 中的 Zen 模式

如何解决PowerShell 中的 Zen 模式

下面的 PowerShell 代码可以帮助您有动力为类似 ninja 的活动编写自己的别名

  1. 将 %userprofile% 替换为您的用户名
  2. 将[提示]替换为原始路径

在您的 powershell cli 中键入 $profile,并附加以下代码以开始使用

此活动是否会拖累系统性能

function poweroff_ {
    shutdown -s -f
}
function hibernate_ {
    shutdown -h
}
function restart_ {
    shutdown -r -f
}
function eject_usb($driveletter){
    # safely eject the mention drive eg:- d:\
    $driveEject = New-Object -comObject Shell.Application
    $driveEject.Namespace(17).ParseName($driveletter).InvokeVerb("Eject")
}
function cleanup_ {
    #remove clutter from temp directory
    rm -r -fo "C:\Users\%userprofile%\AppData\Local\Temp" 
    #clear Recycle-bin
    clear-RecycleBin -confirm:$false
}
function pomodoro_timer{
    #Reference: https://en.wikipedia.org/wiki/Pomodoro_Technique
    Write-Host "'f' for Foucs(40 mins),'sb' fo Short Break(10 mins),'lb' for Long Break(30 mins)"
    $logic = Read-Host "Ready? [f/sb/lb]"
    if($logic -eq "f"){
        $minutes = 40
    } elseif ($logic -eq "sb") {
        $minutes = 10
    } elseif ($logic -eq "lb")  {
        $minutes = 30
    }
    #To-Do: Include background music [vlc] for each mode,and upon completing - play alert sound [custom sound,from local path]
    $seconds = $minutes * 60
    $delay = 1 #seconds between ticks
    for ($i = $seconds; $i -gt 0; $i = $i - $delay) {
        $percentComplete = 100 - (($i / $seconds) * 100)
        Write-Progress -SecondsRemaining $i `
            -Activity "Pomodoro Focus sessions" `
            -Status "Time remaining:" `
            -PercentComplete $percentComplete
        if ($i -eq 16){Write-Host "Wrapping up,you will be available in $i seconds" -ForegroundColor Green}
        Start-Sleep -Seconds $delay
    }#Timer ended

}
# Native command renaming
set-alias -Name unzip -Value expand-archive
# Path specific
set-alias -Name np -Value notepad.exe
set-alias -name notes -Value C:\Users\%userprofile%\AppData\Local\[notetaking app.exe]
set-alias -name brave -value C:\Users\%userprofile%\AppData\Local\BraveSoftware\Brave-browser\Application\brave.exe
Set-Alias -name paswdmng -value C:\Users\%userprofile[paswword manager app.exe]
Set-Alias -Name vs -value "C:\Users\%userprofile%\AppData\Local\Programs\Microsoft VS Code\Code.exe"
Set-Alias -Name outlook -Value "C:\Users\%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Brave Apps\Outlook.lnk"
Set-Alias -Name teams -Value "C:\Users\%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft Teams.lnk"
Set-Alias -Name vlc -Value "C:\Program Files\VideoLAN\VLC\vlc.exe"
# Invoking custom fuctions 
New-Alias poweroff poweroff_
New-Alias frezze hibernate_
New-Alias restart restart_
New-Alias eject eject_usb
New-Alias cleanup cleanup_
New-alias focusmode pomodoro_timer

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。