Last active
December 30, 2023 23:45
-
-
Save y0mbo/08dd48cb545369918da90b0c9ffae7f6 to your computer and use it in GitHub Desktop.
Powershell_profile.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Powershell Profile | |
# Last change: 2023-12-30 | |
# 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 | |
function title($value) { | |
$host.UI.RawUI.WindowTitle = $value | |
} | |
Set-Location C:\dev\ | |
function prompt { | |
$p = Split-Path -leaf -path (Get-Location) | |
"$p> " | |
} | |
# 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 | |
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 | |
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 | |
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 | |
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 | |
# set up vim for editing | |
$VIMPATH = "c:\Program Files\Vim\vim82\" | |
$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 | |
} | |
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) | |
} | |
} | |
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 | |
} | |
} |
Added additional git command shortcuts
Added function to create a new journal entry in the current folder.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added *nix-like
touch
command.