Skip to content

Instantly share code, notes, and snippets.

@michaelavila
Created November 11, 2014 00:07
Show Gist options
  • Save michaelavila/25f15a8a39b3372979b9 to your computer and use it in GitHub Desktop.
Save michaelavila/25f15a8a39b3372979b9 to your computer and use it in GitHub Desktop.
# usage: find-dotfiles [directory]
function find-dotfiles() {
# I store my dotfiles in git, therefore I want to ignore
# the following files, and everyone wants to ignore "."
default_excludes=("." "*.git" "*.gitmodules")
exclude=$(printf " -not -iwholename '%s'" ${default_excludes[*]}) # map to -not -iwholename $FILE
eval "find ${1-$PWD} -name '.*' $exclude -maxdepth 1 | xargs -L1 -I {} basename {}"
}
# usage: link-dotfiles [from] [to]
function link-dotfiles() {
find-dotfiles ${1-$PWD} | xargs -L1 -I {} ln -s ${1-$PWD}/{} ${2-$HOME}/{}
}
# usage: unlink-dotfiles [from] [source]
function unlink-dotfiles() {
find-dotfiles ${2-$PWD} | xargs -L1 -I {} rm -rf /tmp/d && mv ${1-$HOME}/{} /tmp/d/{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment