xdg-user-dirs-update 不适用于多个目录

xdg-user-dirs-update 不适用于多个目录

https://manpages.ubuntu.com/manpages/focal/man1/xdg-user-dirs-update.1.html

为什么文件中只设置了最后一个目录xdg-user-dirs

% xdg-user-dirs-update --dummy-output ~/test \
  --set DOCUMENTS $HOME/Apples \
  --set MUSIC $HOME/Bananas \
  --set PICTURES $HOME/Oranges \
  --set VIDEOS $HOME/Pears

% cat ~/test
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_VIDEOS_DIR="$HOME/Pears"

答案1

% cat ~/.dotfiles/config/.config/user-dirs.dirs
XDG_DESKTOP_DIR=
XDG_DOWNLOAD_DIR=
XDG_TEMPLATES_DIR=
XDG_PUBLICSHARE_DIR=
XDG_DOCUMENTS_DIR=
XDG_MUSIC_DIR=
XDG_PICTURES_DIR=
XDG_VIDEOS_DIR=

看来您需要单独更改每个目录,并且它只更新已经存在的变量(或者仅更新最后一个目录),因此您至少需要在文件中包含您想要的空变量,如上所示。

我试图为使用 Windows WSL 时的自动设置编写脚本,这就是我最终得到的结果:

# Set xdg-user-dirs
xdg-user-dirs-update \
  --dummy-output ~/.dotfiles/config/.config/user-dirs.dirs \
  --set DOCUMENTS $WIN_HOME/Documents
xdg-user-dirs-update \
  --dummy-output ~/.dotfiles/config/.config/user-dirs.dirs \
  --set MUSIC $WIN_HOME/Music
xdg-user-dirs-update \
  --dummy-output ~/.dotfiles/config/.config/user-dirs.dirs \
  --set PICTURES $WIN_HOME/Pictures
xdg-user-dirs-update \
  --dummy-output ~/.dotfiles/config/.config/user-dirs.dirs \
  --set VIDEOS $WIN_HOME/Videos

% cat ~/.dotfiles/config/.config/user-dirs.dirs
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="/mnt/c/Users/jason/Documents"
XDG_MUSIC_DIR="/mnt/c/Users/jason/Music"
XDG_PICTURES_DIR="/mnt/c/Users/jason/Pictures"
XDG_VIDEOS_DIR="/mnt/c/Users/jason/Videos"

相关内容