xdg-user-dirs-update is normally run automatically at login, but I suppose it would be possible to add a script to your Autostart with the following content…
!#/bin/sh
xdg-user-dirs-update --force
If I understand the manual correctly, then the above should do what you’re asking for.
➜ ~ cat .config/user-dirs.dirs 17:26
# 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="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"
What about a simple shell script that runs on login? Add the following to your ~/.bashrc, or ~/.zshrc depending on what you use as your login shell…
for folder in Desktop Documents Downloads Music Pictures Public Templates Videos
do
[ ! -d "${HOME}"/"${folder}" ] && mkdir "${HOME}"/"${folder}"
done
unset folder
Are you sure that would be cleaner, since it is apparently not designed to do what you want it to do, and that, as a system-wide service, the file may possibly end up overwritten upon an update?
I’m not sure config files would be overwritten on updating, I think the update is only about the software package.
I tried with - - force and it didn’t restore my deleted folder. This is weird because the man page says that this parameter is meant to do exactly this.
May be a bug?
If - - force was working my plan was to modify the service file, and make it call the function with the - - force parameter.
I think this would survive a package update.
Can some of you check if the command:
xdg-user-dirs-update - - force
Restore a deleted folder?
You should add a disclaimer, this might have (unwanted) side effects for some configurations and could potentially changeuser-dirs.dir. To quote the man page:
xdg-user-dirs-update updates the current state of the users user-dirs.dir
…
If an old configuration exists it is updated with any new default directories.
Yes it says that, but I don’t understand the meaning very well.
It seems it means that if the configuration file already exists it doesn’t create folders, it creates folders only if user-dirs.dir doesn’t exist?
Because I’m experimenting exactly this.
Instead of create folders it just update the configuration file to be coherent to the existing directory.
I don’t understand 2 things:
1.What’s the difference between using --force and not using it?
2. Why do we need the service running every boot?
It does basically nothing. I don’t understand the purpose of the package at all!
The only thing it does it’s updating a configuration file only useful for itself?
I’m confused!
Keep in mind that English is not my native language so it’s possible I didn’t understand some subtlety in the man page.