Skip to content

Instantly share code, notes, and snippets.

@y0mbo
Last active December 30, 2023 23:45

Revisions

  1. y0mbo revised this gist Dec 30, 2023. 1 changed file with 62 additions and 15 deletions.
    77 changes: 62 additions & 15 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -86,21 +86,6 @@ Function Edit-Vimrc
    vim $home\_vimrc
    }

    # to reload your PowerShell profile
    function reload {
    & $profile
    }

    # techie007 post, last comment https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell
    function touch {
    if((Test-Path -Path ($args[0])) -eq $false) {
    Set-Content -Path ($args[0]) -Value ($null)
    }
    else {
    (Get-Item ($args[0])).LastWriteTime = Get-Date
    }
    }

    function grep {
    Write-Output "You're looking for this command: Select-String -Pattern ""error"" -Path ""C:\temp\log\*.log\"""
    if ($args[0]) {
    @@ -113,4 +98,66 @@ function grep {

    Select-String -Pattern ($search) -Path ($path)
    }
    }

    function journal {
    param (
    [string]$date
    )

    if (!$date)
    {
    $date = Get-Date -Format "yyyy-MM-dd"
    }

    $file = "$date-journal.md"
    if (Test-Path -Path $file -PathType Leaf) {
    Write-Host "$file already exists."
    notepad $file
    } else {
    New-Item -Name $file -ItemType File -Force > $null

    $header =
    "---",
    "slug: $date-journal",
    "title: $date",
    "author: John Uhri",
    "description: >-",
    "`t$date Journal Entry",
    "keywords:",
    "`t- journal",
    "banner:",
    "bannerCredit",
    "---`n"

    $header | Set-Content -Path "$file"

    Write-Host "$file created."
    notepad $file
    }
    }

    function notepad {
    Start-Process -FilePath "C:\Program Files (x86)\Notepad++\notepad++.exe" $args[0]
    }

    # to reload your PowerShell profile
    function reload {
    . $profile
    Write-Host "$profile reloaded"
    }

    # techie007 post, last comment https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell
    function touch {
    if(!$args[0])
    {
    Write-Output "You forgot to provide a file name, so I can't create anything."
    continue
    }
    if((Test-Path -Path ($args[0])) -eq $false) {
    Set-Content -Path ($args[0]) -Value ($null)
    }
    else {
    (Get-Item ($args[0])).LastWriteTime = Get-Date
    }
    }
  2. y0mbo revised this gist Dec 30, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Powershell Profile
    #
    # Last change: 2023-12-30
    # Location:
    # > $PROFILE
    # C:\Users\johnu\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  3. y0mbo revised this gist Oct 6, 2022. 1 changed file with 17 additions and 3 deletions.
    20 changes: 17 additions & 3 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    # Select "Y"1
    # https://tecadmin.net/powershell-running-scripts-is-disabled-system/

    $Title = "I am one with the code and the code is with me."
    $Title = "I am one with the code and the code is with me"
    $host.UI.RawUI.WindowTitle = $Title

    function title($value) {
    @@ -43,7 +43,7 @@ Set-Alias -Name gca -Value git-commit-all

    # going to force remove gc from Get-Content and use it for Git instead
    # https://stackoverflow.com/questions/24882210/how-do-i-remove-or-replace-a-built-in-alias-in-powershell
    del alias:gc -Force
    if (Test-Path alias:gc) { del alias:gc -Force }
    function git-commit-m { git commit -m $args }
    Set-Alias -Name gc -Value git-commit-m

    @@ -86,7 +86,7 @@ Function Edit-Vimrc
    vim $home\_vimrc
    }

    # reload your PowerShell profile
    # to reload your PowerShell profile
    function reload {
    & $profile
    }
    @@ -100,3 +100,17 @@ function touch {
    (Get-Item ($args[0])).LastWriteTime = Get-Date
    }
    }

    function grep {
    Write-Output "You're looking for this command: Select-String -Pattern ""error"" -Path ""C:\temp\log\*.log\"""
    if ($args[0]) {
    Write-Output "... but let me 'grep' that for you anyway"

    $search = $args[0]

    $path = "*.*"
    if ($args[1]) { $path = $args[1]}

    Select-String -Pattern ($search) -Path ($path)
    }
    }
  4. y0mbo revised this gist Nov 10, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -86,6 +86,11 @@ Function Edit-Vimrc
    vim $home\_vimrc
    }

    # reload your PowerShell profile
    function reload {
    & $profile
    }

    # techie007 post, last comment https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell
    function touch {
    if((Test-Path -Path ($args[0])) -eq $false) {
  5. y0mbo revised this gist Nov 10, 2021. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -55,6 +55,11 @@ Set-Alias -Name gf -Value git-fetch

    function back-dir { cd .. }
    Set-Alias -Name .. -Value back-dir
    function back-dir2 { cd ../.. }
    Set-Alias -Name ... -Value back-dir2
    function back-dir3 { cd ../../.. }
    Set-Alias -Name .... -Value back-dir3


    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None
    @@ -89,4 +94,4 @@ function touch {
    else {
    (Get-Item ($args[0])).LastWriteTime = Get-Date
    }
    }
    }
  6. y0mbo revised this gist Nov 5, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,7 @@ function git-commit-all { git commit -am $args }
    Set-Alias -Name gca -Value git-commit-all

    # going to force remove gc from Get-Content and use it for Git instead
    # https://stackoverflow.com/questions/24882210/how-do-i-remove-or-replace-a-built-in-alias-in-powershell
    del alias:gc -Force
    function git-commit-m { git commit -m $args }
    Set-Alias -Name gc -Value git-commit-m
  7. y0mbo revised this gist Nov 5, 2021. 1 changed file with 29 additions and 3 deletions.
    32 changes: 29 additions & 3 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -26,14 +26,40 @@ function prompt {

    # git aliases
    # see https://gist.github.com/dunckr/8334213
    function git-branch { git branch $args }
    Set-Alias -Name gb -Value git-branch

    function git-add { git add $args }
    Set-Alias -Name ga -Value git-add

    function git-diff { git diff $args }
    Set-Alias -Name gd -Value git-diff

    function git-status { git status }
    Set-Alias -Name gs -Value git-status

    # turn off that annoying beep
    function git-commit-all { git commit -am $args }
    Set-Alias -Name gca -Value git-commit-all

    # going to force remove gc from Get-Content and use it for Git instead
    del alias:gc -Force
    function git-commit-m { git commit -m $args }
    Set-Alias -Name gc -Value git-commit-m

    function git-checkout { git checkout $args }
    Set-Alias -Name gco -Value git-checkout

    function git-fetch { git fetch }
    Set-Alias -Name gf -Value git-fetch

    function back-dir { cd .. }
    Set-Alias -Name .. -Value back-dir

    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None

    # set up vim for editing
    $VIMPATH = "c:\Program Files (x86)\Vim\vim82\"
    $VIMPATH = "c:\Program Files\Vim\vim82\"

    $VIM = $VIMPATH + "vim.exe"
    $GVIM = $VIMPATH + "gvim.exe"
    @@ -62,4 +88,4 @@ function touch {
    else {
    (Get-Item ($args[0])).LastWriteTime = Get-Date
    }
    }
    }
  8. y0mbo revised this gist Sep 27, 2021. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -53,3 +53,13 @@ Function Edit-Vimrc
    {
    vim $home\_vimrc
    }

    # techie007 post, last comment https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell
    function touch {
    if((Test-Path -Path ($args[0])) -eq $false) {
    Set-Content -Path ($args[0]) -Value ($null)
    }
    else {
    (Get-Item ($args[0])).LastWriteTime = Get-Date
    }
    }
  9. y0mbo revised this gist Apr 13, 2021. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,15 @@
    # Powershell Profile
    #
    # Location:
    # > $PROFILE
    # C:\Users\johnu\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    #
    # If you get the error: "Running scripts is disabled on this system" when loading the Profile:
    # From a PowerShell window opened As Administrator:
    # > Set-ExecutionPolicy RemoteSigned
    # Select "Y"1
    # https://tecadmin.net/powershell-running-scripts-is-disabled-system/

    $Title = "I am one with the code and the code is with me."
    $host.UI.RawUI.WindowTitle = $Title

  10. y0mbo revised this gist Dec 17, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    $Title = "I am one with the code and the code is with me."
    $host.UI.RawUI.WindowTitle = $Title

    function title($value) {
    $host.UI.RawUI.WindowTitle = $value
    }

    Set-Location C:\dev\

    function prompt {
  11. y0mbo revised this gist Dec 15, 2020. 1 changed file with 23 additions and 5 deletions.
    28 changes: 23 additions & 5 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,36 @@
    $host.ui.RawUI.WindowTitle = "Red Caffeine BadAss"
    Set-Location C:\dev\

    function prompt {
    $p = Split-Path -leaf -path (Get-Location)
    "$p> "
    }

    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None

    # git aliases
    # see https://gist.github.com/dunckr/8334213
    function git-status { git status }
    Set-Alias -Name gs -Value git-status

    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None

    # set up vim for editing
    $VIMPATH = "c:\Program Files (x86)\Vim\vim82\"

    # clear-host
    $VIM = $VIMPATH + "vim.exe"
    $GVIM = $VIMPATH + "gvim.exe"

    Set-Alias vi $VIM
    Set-Alias vim $VIM
    Set-Alias gvim $GVIM

    # for editing your PowerShell profile
    Function Edit-Profile
    {
    vim $profile
    }

    # for editing your Vim settings
    Function Edit-Vimrc
    {
    vim $home\_vimrc
    }
  12. y0mbo revised this gist Feb 22, 2020. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,18 @@
    $host.ui.RawUI.WindowTitle = "Red Caffeine BadAss"
    Set-Location C:\dev\

    function prompt {
    $p = Split-Path -leaf -path (Get-Location)
    "$p> "
    }

    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None

    # git aliases
    # see https://gist.github.com/dunckr/8334213
    function git-status { git status }
    Set-Alias -Name gs -Value git-status

    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None

    # clear-host
  13. y0mbo revised this gist Feb 11, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Set-Location C:\dev\dev\
    Set-Location C:\dev\

    function prompt {
    $p = Split-Path -leaf -path (Get-Location)
  14. y0mbo revised this gist Feb 11, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -10,5 +10,5 @@ function prompt {
    function git-status { git status }
    Set-Alias -Name gs -Value git-status

    # turn off that onnoying beep
    # turn off that annoying beep
    Set-PSReadlineOption -BellStyle None
  15. y0mbo revised this gist Feb 11, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -9,3 +9,6 @@ function prompt {
    # see https://gist.github.com/dunckr/8334213
    function git-status { git status }
    Set-Alias -Name gs -Value git-status

    # turn off that onnoying beep
    Set-PSReadlineOption -BellStyle None
  16. y0mbo renamed this gist Feb 6, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.txt → Powershell_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Set-Location C:\dev\dev\

    function prompt {
    $p = Split-Path -leaf -path (Get-Location)
    "$p> "
  17. y0mbo created this gist Feb 6, 2018.
    9 changes: 9 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function prompt {
    $p = Split-Path -leaf -path (Get-Location)
    "$p> "
    }

    # git aliases
    # see https://gist.github.com/dunckr/8334213
    function git-status { git status }
    Set-Alias -Name gs -Value git-status