Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ln -s /mnt/c/Users/Ryan/Downloads $HOME/Downloads
- ln -s /mnt/c/Users/%USERNAME%/Downloads $HOME/Downloads
- ln -s %USERPROFILE%/Downloads $HOME/Downloads
- # Will return all the environment variables in KEY=VALUE format
- function Get-EnvironmentVariables {
- return (Get-ChildItem ENV: | foreach { "WIN_$(Get-LinuxSafeValue -Value ($_.Name -replace '(|)','').ToUpper())='$(Convert-ToWSLPath -Path $_.Value)'" })
- }
- # converts the C:foobar path to the WSL counter part of /mnt/c/foo/bar
- function Convert-ToWSLPath {
- param (
- [Parameter(Mandatory=$true)]
- $Path
- )
- (Get-LinuxSafeValue -Value (($Path -split ';' | foreach {
- if ($_ -ne $null -and $_ -ne '' -and $_.Length -gt 0) {
- (( (Fix-Path -Path $_) -replace '(^[A-Za-z]):(.*)', '/mnt/$1$2') -replace '\','/')
- }
- } ) -join ':'));
- }
- function Fix-Path {
- param (
- [Parameter(Mandatory=$true)]
- $Path
- )
- if ( $Path -match '^[A-Z]:' ) {
- return $Path.Substring(0,1).ToLower()+$Path.Substring(1);
- } else {
- return $Path
- }
- }
- # Ouputs a string of exports that can be evaluated
- function Import-EnvironmentVariables {
- return (Get-EnvironmentVariables | foreach { "export $_;" }) | Out-String
- }
- # Just escapes special characters
- function Get-LinuxSafeValue {
- param (
- [Parameter(Mandatory=$true)]
- $Value
- )
- process {
- return $Value -replace "(s|'|`"|$|#|&|!|~|``|*|?|(|)||)",'$1';
- }
- }
- function winenv() {
- echo $(powershell.exe -Command "Import-Module ..env.ps1; Import-EnvironmentVariables") | sed -e 's|r|n|g' -e 's|^[st]*||g';
- }
- eval $(winenv)
- WIN_ONEDRIVE=/mnt/d/users/rconr/onedrive
- PATH=~/bin:/foo:/usr/bin
- WIN_PATH=/mnt/c/windows:/mnt/c/windows/system32
- ln -s $WIN_USERPROFILE/Downloads $HOME/Downloads
- # gets the lxss path from windows
- function lxssdir() {
- if [ $# -eq 0 ]; then
- if echo "$PWD" | grep "^/mnt/[a-zA-Z]/" > /dev/null 2>&1; then
- echo "$PWD";
- else
- echo "$LXSS_ROOT$PWD";
- fi
- else
- echo "$LXSS_ROOT$1";
- fi
- }
- PS_WORKING_DIR=$(lxssdir)
- if [ -f "$1" ] && "$1" ~= ".ps1$"; then
- powershell.exe -NoLogo -ExecutionPolicy ByPass -Command "Set-Location '${PS_WORKING_DIR}'; Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content $1))) ${*:2}"
- elif [ -f "$1" ] && "$1" ~!= ".ps1$"; then
- powershell.exe -NoLogo -ExecutionPolicy ByPass -Command "Set-Location '${PS_WORKING_DIR}'; Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content $1))) ${*:2}"
- else
- powershell.exe -NoLogo -ExecutionPolicy ByPass ${*:1}
- fi
- unset PS_WORKING_DIR
- $ cmd.exe /c echo %username%
- richturn
- $
Add Comment
Please, Sign In to add comment