基本上,我正在尝试使用GNU Stow
轻松地将我的dotfiles / config文件同步到我的主目录。每个配置都存储在相对于我的主目录的命名文件夹中。例如,vim/.vimrc
或i3/.config/i3/config
。其中一些文件夹有多个文件。
脚本
#!/usr/bin/env bash
# This script will Stow all the dotfiles located in the ~/dotfiles folder.
# The -R flag is used to force a 'restow' which will remove any existing symlinks before attempting to Stow.
echo "Stowing Dotfiles...";
cd ~/.dotfiles
for file in ~/dotfiles/*; do
# Only run Stow on the directories in the dotfiles folder and not the individual files.
# Using 'basename' strips the filepath from the directory name.
if [ -d ${file} ]; then
stow -R $(basename $file)
echo "$(basename $file) stowed.";
fi
done
# Return back to the your PWD from before you ran the script
cd ~-
echo 'All stowed';
当我运行时,存储~/.config
文件夹中的某些文件或目录。但是,如果文件存在,它似乎没有被存放。此外,我的主目录根目录中的文件似乎没有存放,例如bash/.bashrc
和所述目录中的其他文件。
输出
Stowing Dotfiles...
stow_all.sh: line 8: cd: /home/devon/.dotfiles: No such file or directory
WARNING! unstowing bash would cause conflicts:
* existing target is neither a link nor a directory: .bash_aliases
* existing target is neither a link nor a directory: .bashrc
WARNING! stowing bash would cause conflicts:
* existing target is neither a link nor a directory: .bash_aliases
* existing target is neither a link nor a directory: .bashrc
All operations aborted.
bash stowed.
bin stowed.
compton stowed.
WARNING! unstowing fonts would cause conflicts:
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Bold.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-BoldItalic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Italic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Light.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-LightItalic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Medium.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-MediumItalic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Regular.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Thin.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-ThinItalic.ttf
WARNING! stowing fonts would cause conflicts:
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin Italic for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono for Powerline.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Bold.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-BoldItalic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Italic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Light.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-LightItalic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Medium.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-MediumItalic.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Regular.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Thin.ttf
* existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-ThinItalic.ttf
All operations aborted.
fonts stowed.
WARNING! unstowing git would cause conflicts:
* existing target is neither a link nor a directory: .gitconfig
WARNING! stowing git would cause conflicts:
* existing target is neither a link nor a directory: .gitconfig
All operations aborted.
git stowed.
gtk stowed.
i3 stowed.
WARNING! unstowing ncmpcpp would cause conflicts:
* existing target is neither a link nor a directory: .config/ncmpcpp/config
WARNING! stowing ncmpcpp would cause conflicts:
* existing target is neither a link nor a directory: .config/ncmpcpp/config
All operations aborted.
ncmpcpp stowed.
WARNING! unstowing polybar would cause conflicts:
* existing target is neither a link nor a directory: .config/polybar/config
* existing target is neither a link nor a directory: .config/polybar/launch.sh
* existing target is neither a link nor a directory: .config/polybar/updates.sh
* existing target is neither a link nor a directory: .config/polybar/weather.py
WARNING! stowing polybar would cause conflicts:
* existing target is neither a link nor a directory: .config/polybar/config
* existing target is neither a link nor a directory: .config/polybar/launch.sh
* existing target is neither a link nor a directory: .config/polybar/updates.sh
* existing target is neither a link nor a directory: .config/polybar/weather.py
All operations aborted.
polybar stowed.
ranger stowed.
sound stowed.
WARNING! unstowing termite would cause conflicts:
* existing target is neither a link nor a directory: .config/termite/config
WARNING! stowing termite would cause conflicts:
* existing target is neither a link nor a directory: .config/termite/config
All operations aborted.
termite stowed.
WARNING! unstowing tmux would cause conflicts:
* existing target is neither a link nor a directory: .tmux.conf
WARNING! stowing tmux would cause conflicts:
* existing target is neither a link nor a directory: .tmux.conf
All operations aborted.
tmux stowed.
WARNING! unstowing vim would cause conflicts:
* existing target is neither a link nor a directory: .tern-config
* existing target is neither a link nor a directory: .vimrc
WARNING! stowing vim would cause conflicts:
* existing target is neither a link nor a directory: .tern-config
* existing target is neither a link nor a directory: .vimrc
All operations aborted.
vim stowed.
WARNING! unstowing xorg would cause conflicts:
* existing target is neither a link nor a directory: .Xresources
* existing target is neither a link nor a directory: .xinitrc
WARNING! stowing xorg would cause conflicts:
* existing target is neither a link nor a directory: .Xresources
* existing target is neither a link nor a directory: .xinitrc
All operations aborted.
xorg stowed.
All stowed
答案 0 :(得分:1)
您从哪个目录调用此脚本?您的cd
似乎无效,因为您尝试更改为.dotfiles
,但for
循环使用名为dotfiles
的目录(无前导.
)。
您的主目录中似乎有 plain 文件,您希望stow
管理(链接)。
来自stow
手册页:
--adopt Warning! This behaviour is specifically intended to alter the contents of your stow directory. If you do not want that, this option is not for you. When stowing, if a target is encountered which already exists but is a plain file (and hence not owned by any existing stow package), then normally Stow will register this as a conflict and refuse to proceed. This option changes that behaviour so that the file is moved to the same relative place within the package's installation image within the stow directory, and then stowing proceeds as before. So effectively, the file becomes adopted by the stow package, without its contents changing.
请注意:
当存放时,如果遇到已经存在但是普通文件的目标(因此不属于任何现有的存储包),那么通常Stow会将此注册为冲突并拒绝继续。
修复您的脚本,将cd
和for
循环指向同一目录:~/.dotfiles/
或~/dotfiles/
如果您想将现有配置文件(~
)最初移至dotfiles
使用stow --adopt
(事先查看手册)
如果您要将配置文件从dotfiles
移动到~
移动或删除(备份)主文件夹中已有的文件
答案 1 :(得分:0)
我尝试过与您相同的方法。这是我的尝试。
cd
在脚本上不起作用。相反,您将要告诉stow
存放在哪里,而不是当前目录。
我自己的dotfile中有一堆软件包,所以我遍历它们并存放:
for PACKAGE in shell emacs # ...
do
stow -R -v -d path/to/dotfiles -t ~ $PACKAGE
done