diff --git a/bin/dotfiles b/bin/dotfiles index fca5d74..4bca5fb 100755 --- a/bin/dotfiles +++ b/bin/dotfiles @@ -2,7 +2,7 @@ ## ## binaryDiv's dotfiles management script -## Version 0.4.0 +## Version 0.4.1 ## usage() { @@ -18,12 +18,14 @@ usage() { (this will NOT create links for all dotfiles, though) Dotfile management: - ls [DIR] list contents of .dotfiles directory (or DIR relative to it) - diff FILE use vimdiff to compare ~/FILE to ~/.dotfiles/FILE - link FILE... create a symlink from ~/FILE to ~/.dotfiles/FILE (multiple files possible) - (-q: be quiet, only print something if an error occurs) - linkstatus [DIR] list contents of .dotfiles with information about whether there are links to - them in ~/, whether they differ, etc... + ls [DIR] list contents of .dotfiles directory (or DIR relative to it) + diff FILE use vimdiff to compare ~/FILE to ~/.dotfiles/FILE + link FILE... create a symlink from ~/FILE to ~/.dotfiles/FILE (multiple files possible) + (-q: be quiet, only print something if an error occurs) + linkstatus [DIR] list contents of .dotfiles with information about whether there are links to + them in ~/, whether they differ, etc... + createfrom FILE... copy ~/FILE to ~/.dotfiles/FILE and symlink the file + (-n: only copy, leave the original, do not create symlink) Synchronization: git ARGS... wrapper for git (all arguments are passed on to git) @@ -181,6 +183,37 @@ case "$cmd" in fi done ;; + + createfrom) + if [[ $1 = '-n' ]]; then + NOLINK=1 + shift + fi + + [[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; } + + for filename in "$@"; do + file_home="$homedir/$filename" + file_dotfiles="$dotfilesdir/$filename" + + if [[ ! -e $file_home ]]; then + echo "! $file_home: source file does not exist" + exit 1 + elif [[ -e $file_dotfiles ]]; then + echo "! $file_dotfiles already exists" + exit 1 + else + mkdir -p "$(dirname "$file_dotfiles")" + [[ $QUIET ]] || echo "* Copy $file_home -> $file_dotfiles" + cp -n "$file_home" "$file_dotfiles" || exit 1 + if [[ ! $NOLINK ]]; then + [[ $QUIET ]] || echo "* Remove original and link $file_home -> $file_dotfiles" + rm "$file_home" || exit 1 + ln -sr "$file_dotfiles" "$file_home" || exit 1 + fi + fi + done + ;; git) git -C "$dotfilesdir" "$@" @@ -200,7 +233,7 @@ case "$cmd" in _dotfiles() { COMPREPLY=() local cur="${COMP_WORDS[COMP_CWORD]}" - local commands="help install ls diff link linkstatus git pull" + local commands="help install ls diff link linkstatus createfrom git pull" local gitcommands="add commit diff fetch log pull push rebase status" if [[ $COMP_CWORD -eq 1 ]]; then @@ -215,6 +248,11 @@ case "$cmd" in _dotfiles_filenames ;; + createfrom) + compopt -o filenames + COMPREPLY=($(compgen -f -- ${cur})) + ;; + git) if [[ $COMP_CWORD -eq 2 ]]; then COMPREPLY=($(compgen -W "$gitcommands" -- ${cur}))