Using bash to automate dotfiles

断了今生、忘了曾经 提交于 2020-01-01 03:29:07

问题


I want to create my own automated dotfiles folder. (I'll be using git to use version control on my dotfiles, but that's irrelevant for the question)

What i simply want is to symbolically link all the files and folders in ~/dotfiles to my home folder. Being not good at all with bash I can't do this. Please help me with this.

I would also appreciate the following features if possible.

  • Folders are only shallowly linked
  • My files could be in the dotfiles folder without the actual dot in the file-name (like ~/dotfiles/vimrc rather than ~/dotfiles/.vimrc)
  • It should be able to ignore some files, like my .git file which are stored in the same folder

Of course if you already know a service providing this, that is at least as good as providing some do-myself commands. Note how I specifically want it to be bash or something that most likely exists on all unix machines (so i guess commands using g++ are fine).


回答1:


Give this a try:

ln -s ~/dotfiles/* ~

There shouldn't be any need for a loop. Of course, you can use find if you need something recursive.

Edit:

To make the destination files hidden:

for f in ~/dotfiles/*
do
    ln -s "$f" "$HOME/.${f##*/}"
done



回答2:


I am not sure if I'm getting the question right, but if you looking for symlinks of dir-content, try

for f in `ls -1 .dotfiles`
do
   ln -s .dotfiles/$f ~/$f
done

maybe that already does the trick




回答3:


For the sake of managing dotfiles, I really like Zach Holman's approach. I've made the same thing with my dotfiles which you can find it here :)

https://github.com/rhacker/dotFiles




回答4:


Maybe you are looking for a dotfiles manager, I will recommend you to check DFM (dotfiles manager). DFM addresses the problem you have in a very clean way:

  • Here is my dotfiles selection using dfm: vicente's dotfiles
  • Github official repository DFM site



回答5:


Atlassian has a tutorial on using a git work tree instead of symlinks. The approach uses:

  1. a bare git repository in a side folder (such as $HOME/.cfg or $HOME/dotfiles), and
  2. a config bash alias to execute git commands that manage the configuration files.

For instance, you can run config status to check which files have been modified, config checkout to get the files in the repository and config commit to update the repository. It requires only git and the bash.



来源:https://stackoverflow.com/questions/5238019/using-bash-to-automate-dotfiles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!