cmplstofB / dotfiles

My dotfiles
Do What The F*ck You Want To Public License
2 stars 0 forks source link

WSL使用時にxdg台録をWindowsに合わせる。 #3

Open cmplstofB opened 3 years ago

cmplstofB commented 3 years ago

https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=netframework-4.0#fields

wslpath -u \
"$(/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe \
-Command '[Environment]::GetFolderPath("MyDocuments")')"
cmplstofB commented 3 years ago

https://cgit.freedesktop.org/xdg/xdg-user-dirs/tree/man/xdg-user-dir.xml

DESKTOP
DOWNLOAD
TEMPLATES
PUBLICSHARE
DOCUMENTS
MUSIC
PICTURES
VIDEOS

PUBLICSHARE台録に対応するのはSpecial Folderにはないかな?

cmplstofB commented 3 years ago
Windows XDG
Desktop DESKTOP
[^1] DOWNLOAD
Templates TEMPLATES
(なし?) PUBLICSHARE
MyDocuments DOCUMENTS
MyMusic MUSIC
MyPictures PICTURES
MyVideos VIDEOS

[^1]:

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe \
-Command 'gpv -Path 'Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' -Name '{374DE290-123F-4565-9164-39C4925E467B}'
cmplstofB commented 3 years ago

うまくいかない

#!/bin/sh

set -v
set -- Desktop=DESKTOP Templates=TEMPLATES MyDocuments=DOCUMENTS \
       MyMusic=MUSIC MyPictures=PICTURES MyVideo=VIDEOS

while [ $# -gt 0 ]; do
    printf '%s="%s"\n' \
      "${1#*=}" \
        "$(/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe \
           -Command '[Environment]::GetFolderPath("'${1%=*}'")')"
    #  "$(wslpath -a -u \
    #   )"
    shift
done
cmplstofB commented 3 years ago

うまくいかない原因は,PowerShellの(既定の?←つまり変更可能かもしれない)改行が送行・復帰で構成されていることだった。

#!/bin/sh

set -- Desktop=DESKTOP Templates=TEMPLATES MyDocuments=DOCUMENTS \
       MyMusic=MUSIC MyPictures=PICTURES MyVideo=VIDEOS

while [ $# -gt 0 ]; do
    printf '%s="%s"\n' \
      "${1#*=}" \
      "$(wslpath -a -u \
        "$(/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe \
           -Command '[Console]::Write([Environment]::GetFolderPath("'"${1%=*}"'"))'
       )")"
    shift
done
cmplstofB commented 3 years ago

https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/known-folder-guids-for-file-dialog-custom-places

cmplstofB commented 2 years ago

Windows側からの例

$ wsl -d Ubuntu -u cmplstofb -e xdg-user-dir DESKTOP
cmplstofB commented 2 years ago

https://docs.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=netframework-4.0#System_Environment_GetEnvironmentVariable_System_String_System_EnvironmentVariableTarget_

powershell.exe -Command '[Environment]::GetEnvironmentVariable("TEMP", 'Machine')'
[System.IO.Path]::GetTempPath() # ←これは `'Machine'` が使えない