ChrisTitusTech / linutil

Chris Titus Tech's Linux Toolbox - Linutil is a distro-agnostic toolbox designed to simplify everyday Linux tasks.
https://christitus.com
MIT License
1.77k stars 160 forks source link

personel config lost after runnig linutil #109

Open salahoued opened 1 month ago

salahoued commented 1 month ago

Describe the bug

I use stow to manage my dotfiles, so my personel configs under .config are mostly symbolic links , So when setting up (for example) rofi, linutil tries to backup the .config/rofi with .config/rofi.bak, but it will end up as a symlink pointing to the same directory as .config/rofi, resulting in losing any old/previous configurations.

To Reproduce

Steps to reproduce the behavior:

  1. having a symlink in ~/.config pointing to different directory: ~/.config/rofi -> ~/Documents/config/rofi
  2. run linutil
  3. try to set up rofi
  4. see that ~/.config/rofi and ~/.config/rofi.bak are pointing to the same ~/Documents/config/rofi and the old config.rasi is lost

Expected behavior

maybe check if ~/.config/rofi is a symlink or a directory before backing it up.

personally, I prefer the second option this way the user, can still keep his old config and enjoy the new one, while still managing it with dotfiles management solution.

Screenshots

sip

salahoued commented 1 month ago

maybe something like this in rofi-setup.sh

if [ -h "$HOME/.config/rofi" ]; then
        for i in "$HOME/.config/rofi"/*; do
            cp -r "$HOME/.config/rofi/$i" "$HOME/.config/rofi/$i.bak"
        done
elif [ ! -h "$HOME/.config/rofi" -a -d "$HOME/.config/rofi" ]; then
        cp -r "$HOME/.config/rofi" "$HOME/.config/rofi.bak"
fi

or add a checkIsSymlink() in common-script.sh that will be used in any dotfiles set up

lj3954 commented 1 month ago

Can you try adding the -L flag to the cp command? That option should first dereference all symlinks.

salahoued commented 1 month ago

Yes, that works, there is now an actual directory not symlink ~/.config/rofi.bak with the all the files in it,

This is just a personal opinion, but it would be better to have it this way: for example move ~/.config/rasi/config.rasi to ~/.config/rofi/config.rasi.bak and any other files in it be renamed in the same way if it exists in the old and new config. so that it can be managed by dotfiles managers

thanks