Skip to content

Instantly share code, notes, and snippets.

@kentork
kentork / Wsl.ps1
Last active June 11, 2018 20:34
functions for WSL
function w2l($in) {
if ( $in -match "(^[a-zA-Z]:(\\{1,2})?$|^[a-zA-Z]:\\{1,2}[^\\])") {
$in = "/mnt/" + $in.Substring(0, 1).ToLower() + $in.Substring(2).Replace('\\', '/').Replace('\', '/')
} elseif ( $in -match "(^\.(\\{1,2})?$|^\.\\{1,2}[^\\])") {
$in = $in.Replace('\\', '/').Replace('\', '/')
}
return $in
}
function l2w($in) {
if ( $in -match "(^/mnt/[a-z]/?|^/mnt/[a-z]/[^/])") {
@kentork
kentork / Caddyfile
Last active January 23, 2018 12:54
CA for localhost
localhost {
tls {$USERPROFILE}/.local-ca/devserver.crt {$USERPROFILE}/.local-ca/devserver.key
}
@kentork
kentork / OverwriteExecutePath.reg
Last active January 31, 2018 10:04
Overwrite Cmder Explorer Integration
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Cmder Here\command]
@="\"C:\\<<application path>>\\Cmder64.exe\" -here -run {powershell} -cur_console:n:d:\"%V\""
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LxssManager]
"DistributionFlags"=dword:fffffffd
@kentork
kentork / Path-Buckup.ps1
Created November 29, 2017 05:53
Path Backup
Get-Date | Add-Content ~/.path -Encoding utf8
[environment]::getEnvironmentVariable("PATH", "User") | Add-Content ~/.path -Encoding utf8
[environment]::getEnvironmentVariable("PATH", "Machine") | Add-Content ~/.path -Encoding utf8
"`r`n" | Add-Content ~/.path -Encoding utf8
$saving = 20
$maxline = 5 * $saving
$contents = Get-Content ~/.path
if ($contents.length -gt $maxline) {
$contents | Select-Object -Skip ($contents.length - $maxline) | Set-Content -Encoding utf8 ~/.path
@kentork
kentork / profile.ps1
Last active July 15, 2019 06:46
Environment operation for powershell
function setenv($key, $value, $target) {
if (! $target) {
$target = "User"
}
if (($target -eq "Process") -Or ($target -eq "User") -Or ($target -eq "Machine")) {
$now = [environment]::getEnvironmentVariable($key, $target)
if ($now) {
$tChoiceDescription = "System.Management.Automation.Host.ChoiceDescription"
$result = $host.ui.PromptForChoice("", "Already Exists. Overwrite ?", @(
New-Object $tChoiceDescription ("&Yes")
@kentork
kentork / profile.ps1
Last active May 5, 2023 17:22
Github operation on powershell
## article - https://qiita.com/drafts/f500f261d1292ebe2941
function gh {
Param(
[ValidateSet("show","open","clone","find","grep","get","rm","cd","pushd","dir","edit","pwd","list","ls","register","create")][Parameter(Mandatory=$false)][string]$subcommand,
[Parameter(Mandatory=$false)][switch]$g, # globally (public)
[Parameter(Mandatory=$false)][switch]$e, # edit
[Parameter(Mandatory=$false)][switch]$d, # directory
[Parameter(Mandatory=$false)][switch]$r, # remote
[Parameter(Mandatory=$false)][switch]$p, # purge