基本上,我正在尝试使用GNU Stow
轻松地将我的点文件/配置文件同步到我的主目录。每个配置都存储在相对于我的主目录的命名文件夹中。例如,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
你从哪个目录调用这个脚本?似乎您的cd
不起作用,因为您正在尝试更改为.dotfiles
但是for
循环正在使用名为dotfiles
的目录(无前导.
(。
警告的含义
您的主目录中似乎有普通文件,您希望通过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 包(的目标,那么通常 Stow 会将其注册为冲突并拒绝继续。
TLDR
修复脚本以将
cd
和for
循环指向同一目录:~/.dotfiles/
或~/dotfiles/
如果要将现有配置文件(
~
(移动到dotfiles
请首先使用stow --adopt
(事先检查手册(如果要将配置文件从
dotfiles
移动到~
请移动或删除(备份(个人文件夹中已有的文件
我尝试了与您相同的方法。这是我的尝试。
cd
不适用于脚本。相反,您需要告诉stow
从何处存放,而不是当前目录。
我在自己的点文件中有一堆包,所以我循环浏览它们并收起:
for PACKAGE in shell emacs # ...
do
stow -R -v -d path/to/dotfiles -t ~ $PACKAGE
done