Skip to content

Instantly share code, notes, and snippets.

@rudylattae
Last active February 16, 2020 02:18
Show Gist options
  • Save rudylattae/184e4602e515d1369a30417f9dabf5f6 to your computer and use it in GitHub Desktop.
Save rudylattae/184e4602e515d1369a30417f9dabf5f6 to your computer and use it in GitHub Desktop.
Powershell Profile
function Edit-Profile {
code $profile.CurrentUserAllHosts
}
function Edit-GitConfig {
code $HOME/.gitconfig
}
Function Touch-File
{
<#
.SYNOPSIS
Create file at given path or update it's last updated time if oit already exists
.EXAMPLE
touch c:/foo/bar/baf.txt
#>
$file = $args[0]
if($file -eq $null) {
throw "No filename supplied"
}
if(Test-Path $file)
{
(Get-ChildItem $file).LastWriteTime = Get-Date
}
else
{
echo $null > $file
}
}
Set-Alias touch Touch-File
Import-Module posh-git
function ContainerCommandRunner() {
# [CmdletBinding()]
# Param (
# [Parameter(Mandatory=$false, Position=0)]
# [string] $action = '--help'
# )
$action = $args[0]
$actionArgs = $args[1..($args.Length)]
switch($action) {
hello {
docker run hello-world
}
mvn {
docker run -it --rm `
-v ${PWD}:/opt/build `
-v ${HOME}/.m2:/root/.m2 `
-w /opt/build `
maven:3.3-jdk-8 mvn $actionArgs
}
jre8 {
docker run -it --rm `
-v ${PWD}:/opt/build `
-w /opt/build `
openjdk:8-jre-alpine3.9 java $actionArgs
}
sparkapp {
docker run -it --rm `
-v ${PWD}:/opt/build `
-w /opt/build `
-p 4567:4567 `
openjdk:8-jre-alpine3.9 java $actionArgs
}
{'--help', '-h' -contains $_} {
Write-Host "Actions:"
Write-Host " --help"
Write-Host " hello"
Write-Host " mvn"
Write-Host " jre8"
Write-Host " sparkapp"
Write-Host "`nUsage:"
Write-Host " ccrun <ACTION> <ARGS>"
}
}
}
Set-Alias cc ContainerCommandRunner
Set-Alias d docker
Function DockerNpm { docker run -it --rm -v="$PWD":/usr/src/app -w=/usr/src/app node:12.13-alpine3.10 npm $args }
Set-Alias dknpm DockerNpm
function Kubectl-Context() {
<##>
$action = $args[0]
$actionArgs = $args[1..($args.Length)]
if($null -eq $action) {
kubectl config current-context
return
}
switch($action) {
list {
kubectl config get-contexts
}
{'--help', '-h' -contains $_} {
Write-Host "Usage:"
Write-Host " --help shows this help message"
Write-Host " list list all contexts"
Write-Host " [CONTEXT_NAME] switch to context name"
}
Default {
kubectl config use-context $action
}
}
}
Set-Alias ktx Kubectl-Context
Set-Alias k kubectl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment