Guest User

Untitled

a guest
Apr 26th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. ln -s /mnt/c/Users/Ryan/Downloads $HOME/Downloads
  2.  
  3. ln -s /mnt/c/Users/%USERNAME%/Downloads $HOME/Downloads
  4.  
  5. ln -s %USERPROFILE%/Downloads $HOME/Downloads
  6.  
  7. # Will return all the environment variables in KEY=VALUE format
  8. function Get-EnvironmentVariables {
  9. return (Get-ChildItem ENV: | foreach { "WIN_$(Get-LinuxSafeValue -Value ($_.Name -replace '(|)','').ToUpper())='$(Convert-ToWSLPath -Path $_.Value)'" })
  10. }
  11.  
  12. # converts the C:foobar path to the WSL counter part of /mnt/c/foo/bar
  13. function Convert-ToWSLPath {
  14. param (
  15. [Parameter(Mandatory=$true)]
  16. $Path
  17. )
  18. (Get-LinuxSafeValue -Value (($Path -split ';' | foreach {
  19. if ($_ -ne $null -and $_ -ne '' -and $_.Length -gt 0) {
  20. (( (Fix-Path -Path $_) -replace '(^[A-Za-z]):(.*)', '/mnt/$1$2') -replace '\','/')
  21. }
  22. } ) -join ':'));
  23. }
  24.  
  25. function Fix-Path {
  26. param (
  27. [Parameter(Mandatory=$true)]
  28. $Path
  29. )
  30. if ( $Path -match '^[A-Z]:' ) {
  31. return $Path.Substring(0,1).ToLower()+$Path.Substring(1);
  32. } else {
  33. return $Path
  34. }
  35. }
  36.  
  37. # Ouputs a string of exports that can be evaluated
  38. function Import-EnvironmentVariables {
  39. return (Get-EnvironmentVariables | foreach { "export $_;" }) | Out-String
  40. }
  41.  
  42. # Just escapes special characters
  43. function Get-LinuxSafeValue {
  44. param (
  45. [Parameter(Mandatory=$true)]
  46. $Value
  47. )
  48. process {
  49. return $Value -replace "(s|'|`"|$|#|&|!|~|``|*|?|(|)||)",'$1';
  50. }
  51. }
  52.  
  53. function winenv() {
  54. echo $(powershell.exe -Command "Import-Module ..env.ps1; Import-EnvironmentVariables") | sed -e 's|r|n|g' -e 's|^[st]*||g';
  55. }
  56.  
  57. eval $(winenv)
  58.  
  59. WIN_ONEDRIVE=/mnt/d/users/rconr/onedrive
  60. PATH=~/bin:/foo:/usr/bin
  61. WIN_PATH=/mnt/c/windows:/mnt/c/windows/system32
  62.  
  63. ln -s $WIN_USERPROFILE/Downloads $HOME/Downloads
  64.  
  65. # gets the lxss path from windows
  66. function lxssdir() {
  67. if [ $# -eq 0 ]; then
  68. if echo "$PWD" | grep "^/mnt/[a-zA-Z]/" > /dev/null 2>&1; then
  69. echo "$PWD";
  70. else
  71. echo "$LXSS_ROOT$PWD";
  72. fi
  73. else
  74. echo "$LXSS_ROOT$1";
  75. fi
  76. }
  77.  
  78. PS_WORKING_DIR=$(lxssdir)
  79. if [ -f "$1" ] && "$1" ~= ".ps1$"; then
  80. powershell.exe -NoLogo -ExecutionPolicy ByPass -Command "Set-Location '${PS_WORKING_DIR}'; Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content $1))) ${*:2}"
  81. elif [ -f "$1" ] && "$1" ~!= ".ps1$"; then
  82. powershell.exe -NoLogo -ExecutionPolicy ByPass -Command "Set-Location '${PS_WORKING_DIR}'; Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content $1))) ${*:2}"
  83. else
  84. powershell.exe -NoLogo -ExecutionPolicy ByPass ${*:1}
  85. fi
  86. unset PS_WORKING_DIR
  87.  
  88. $ cmd.exe /c echo %username%
  89. richturn
  90. $
Add Comment
Please, Sign In to add comment