Last active
June 11, 2018 20:34
-
-
Save kentork/bd85a670302a22852b55652afe59ef47 to your computer and use it in GitHub Desktop.
functions for WSL
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
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]/[^/])") { | |
$in = $in.Substring(5, 1).ToUpper() + $in.Substring(6).Replace('/', '\') | |
} elseif ( $in -match "(^\./?$|^\./[^/])") { | |
$in = $in.Replace('/', '\') | |
} | |
return $in | |
} | |
function w2ls() { $input | %{ w2l($_) } } | |
function l2ws() { $input | %{ l2w($_) } } | |
function wsl_ls() { $input | wsl exa -l $args } | |
function wsl_ll() { $input | wsl exa -l $args } | |
function wsl_la() { $input | wsl exa -l -a $args } | |
function wsl_grep() { $input | wsl rg $args } | |
function wsl_sort() { $input | wsl sort $args } | |
function wsl_cat() { $input | wsl bat $args } | |
function wsl_less() { $input | wsl less $args } | |
function wsl_more() { $input | wsl more $args } | |
function wsl_awk() { $input | wsl awk $args } | |
function wsl_sed() { $input | wsl sed $args } | |
function wsl_jq() { $input | wsl jq $args } | |
function wsl_diff() { $input | wsl diff $args } | |
function wsl_rm() { $input | wsl rm $args } | |
function wsl_cp() { $input | wsl cp $args } | |
function wsl_mv() { $input | wsl mv $args } | |
function wsl_touch() { $input | wsl touch $args } | |
function wsl_tail() { $input | wsl tail $args } | |
function wsl_head() { $input | wsl head $args } | |
function wsl_file() { $input | wsl file $args } | |
function wsl_find() { $input | wsl find $args } | |
function wsl_tree() { $input | wsl tree $args } | |
function wsl_ip() { wsl ip $args } | |
function wsl_curl() { wsl curl $args } | |
function wsl_wget() { wsl wget $args } | |
function wsl_nc() { wsl nc $args } | |
function wsl_ss() { wsl ss $args } | |
function wsl_dig() { wsl dig $args } | |
function wsl_rsync() { wsl rsync $args } | |
function wsl_scp() { wsl scp $args } | |
del alias:sort -Force | |
del alias:diff -Force | |
$commands = @( | |
"ls", "ll", "la", | |
"grep", "sort", "cat", "tail", "head", "less","more", "awk", "sed", "jq", "diff", | |
"mkdir", "rm", "cp", "mv", "touch", "file", "find", "tree", | |
"ip", "curl", "wget", "nc", "ss", "dig", "rsync", "scp" | |
) | |
$commands | ForEach-Object -Process { | |
$method = "wsl_" + $_ | |
Set-Alias -Name:$_ -Value:$method -Option:Allscope | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment