Skip to content

Instantly share code, notes, and snippets.

@nickcox
nickcox / pretty-log.sh
Created April 13, 2023 02:54
Gussy up git log
git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
@nickcox
nickcox / .gitconfig
Last active January 2, 2023 23:32
Git alias to show most recently used branches
# http://ses4j.github.io/2020/04/01/git-alias-recent-branches/
[alias]
lb = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | awk -F' ~ HEAD@{' '{printf(\" \\033[33m%s: \\033[37m %s\\033[0m\\n\", substr($2, 1, length($2)-1), $1)}'
@nickcox
nickcox / per-repo-ssh-config.sh
Last active January 2, 2023 23:12
Set git SSH config per repository
# https://www.fabian-keller.de/blog/configuring-a-different-ssh-key-per-git-repository/
git config core.sshCommand "ssh -F ~/.ssh/config-github-client-one" # config file
# or use identity file directly: git config core.sshCommand "ssh -i ~/.ssh/some_id_file"
Get-Process -Id (Get-NetTCPConnection -LocalPort YourPortNumberHere).OwningProcess
Get-Process -Id (Get-NetUDPEndpoint -LocalPort YourPortNumberHere).OwningProcess
# https://stackoverflow.com/a/48199/56151
# lazy load posh-git
Register-ArgumentCompleter -Native -CommandName 'git' -ScriptBlock {
if (!(gmo posh-git)) { Expand-GitCommand ($args[1] -replace '^git\W*', '') }
}
@nickcox
nickcox / Use-LSColors.ps1
Created May 5, 2022 23:22
Apply PowerShell styles to an LSColors format string
Function Use-LSColors {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$LSColors
)
$LSColors -Split ":" | % {
$param, $arg = $_ -Split "="
fd --no-ignore System.Collections.Immutable.dll | gi |% {
[pscustomobject]@{name=$_; version=[Reflection.AssemblyName]::GetAssemblyName($_).Version }}
# set environment variables from a file
cat ./vars.env | ConvertFrom-StringData |? Values -ne @{} |% {ni -Name $_.Keys -Value $_.Values -Path env: -Force}
@nickcox
nickcox / aws-whoami.sh
Last active October 11, 2021 00:49
AWS whoami
aws sts get-caller-identity
@nickcox
nickcox / gitignore.ps1
Created May 25, 2021 21:41
Add a .gitignore file suitable for NodeJS
# https://github.com/github/gitignore
npx gitignore node