├── img ├── dot_cd.png ├── dot_add.png ├── dot_check.png ├── dot_list.png ├── dot_pull.png ├── dot_set.png └── dot_unlink.png ├── lib ├── dot_cd.sh ├── dot_list.sh ├── dot_update.sh ├── dot_clear.sh ├── dot_pull.sh ├── dot_unlink.sh ├── dot_edit.sh ├── dot_check.sh ├── dot_config.sh ├── dot_clone.sh ├── dot_add.sh ├── common.sh └── dot_set.sh ├── examples ├── dotrc.local ├── dotlink ├── dotlink.local └── dotrc ├── LICENSE ├── Makefile ├── _dot ├── dot.sh ├── doc ├── dot.pod └── dot.1 ├── README_ja.md └── README.md /img/dot_cd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_cd.png -------------------------------------------------------------------------------- /img/dot_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_add.png -------------------------------------------------------------------------------- /img/dot_check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_check.png -------------------------------------------------------------------------------- /img/dot_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_list.png -------------------------------------------------------------------------------- /img/dot_pull.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_pull.png -------------------------------------------------------------------------------- /img/dot_set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_set.png -------------------------------------------------------------------------------- /img/dot_unlink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssh0/dot/HEAD/img/dot_unlink.png -------------------------------------------------------------------------------- /lib/dot_cd.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_cd() { 3 | builtin cd "${dotdir}" 4 | unset -f $0 5 | } 6 | -------------------------------------------------------------------------------- /examples/dotrc.local: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dotlinklocal="$HOME/.config/dot/dotlink.local" 3 | linkfiles=("${dotlink}" "${dotlinklocal}") 4 | -------------------------------------------------------------------------------- /lib/dot_list.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_list() { 3 | _dot_list() { 4 | echo $1,$2 5 | } 6 | 7 | parse_linkfiles _dot_list 8 | 9 | unset -f _dot_list $0 10 | } 11 | -------------------------------------------------------------------------------- /lib/dot_update.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_update() { 3 | source "$DOT_SCRIPT_ROOTDIR/lib/dot_pull.sh" 4 | source "$DOT_SCRIPT_ROOTDIR/lib/dot_set.sh" 5 | dot_pull 6 | dot_set $@ 7 | 8 | unset -f $0 9 | } 10 | -------------------------------------------------------------------------------- /lib/dot_clear.sh: -------------------------------------------------------------------------------- 1 | # vim:ft=sh 2 | dot_clear() { 3 | 4 | _dot_clear() { #{{{ 5 | local orig 6 | 7 | orig="$2" 8 | 9 | if [ -L "${orig}" ]; then 10 | unlink "${orig}" 11 | echo "$(prmpt 1 unlink)${orig}" 12 | fi 13 | } #}}} 14 | 15 | parse_linkfiles _dot_clear 16 | 17 | unset -f _dot_clear $0 18 | } 19 | -------------------------------------------------------------------------------- /lib/dot_pull.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_pull() { 3 | if [ "$1" = "--self" ]; then 4 | echo $(prmpt 4 "Update dot") 5 | git -C "${DOT_SCRIPT_ROOTDIR}" pull 6 | else 7 | # git pull 8 | echo "$(prmpt 4 "Update dotfiles")git -C "${dotdir}" pull" 9 | git -C "${dotdir}" pull 10 | if ${dotpull_update_submodule} && test -s "${dotdir}/.gitmodules"; then 11 | echo "$(prmpt 4 "Update the submodules ...")" 12 | git -C "${dotdir}" submodule init 13 | git -C "${dotdir}" submodule update 14 | fi 15 | fi 16 | 17 | unset -f $0 18 | } 19 | -------------------------------------------------------------------------------- /lib/dot_unlink.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_unlink() { 3 | local f 4 | 5 | for f in "$@"; do 6 | if [ ! -L "$f" ]; then 7 | echo "$(prmpt 1 error)$(bd_ $f) is not the symbolic link." 8 | continue 9 | fi 10 | 11 | # get the file's path 12 | local currentpath="$(get_fullpath "$f")" 13 | 14 | # get the absolute path 15 | local abspath="$(readlink "$f")" 16 | 17 | # unlink the file 18 | unlink "$currentpath" 19 | 20 | # copy the file 21 | cp -r "$abspath" "$currentpath" 22 | 23 | echo "$(prmpt 1 unlink)$f" 24 | echo "$(prmpt 2 copy)$abspath" 25 | done 26 | 27 | unset -f $0 28 | } 29 | -------------------------------------------------------------------------------- /lib/dot_edit.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_edit() { 3 | # init 4 | if [ ! -e "${dotlink}" ]; then 5 | echo "$(prmpt 1 empty)$(bd_ ${dotlink})" 6 | if __confirm y "make dotlink file ? " ; then 7 | echo "cp ${DOT_SCRIPT_ROOTDIR}/examples/dotlink ${dotlink}" 8 | cp "${DOT_SCRIPT_ROOTDIR}/examples/dotlink" "${dotlink}" 9 | else 10 | echo "Aborted."; return 1 11 | fi 12 | fi 13 | 14 | # open dotlink file 15 | if [ -n "${dot_edit_default_editor}" ];then 16 | eval ${dot_edit_default_editor} "${dotlink}" 17 | elif hash "$EDITOR" 2>/dev/null; then 18 | $EDITOR "${dotlink}" 19 | else 20 | xdg-open "${dotlink}" 21 | fi 22 | 23 | unset -f $0 24 | } 25 | -------------------------------------------------------------------------------- /lib/dot_check.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_check() { 3 | 4 | _dot_check() { #{{{ 5 | local dotfile orig origdir linkto message 6 | local delimiter="," 7 | dotfile="$1" 8 | orig="$2" 9 | message="${dotfile}${delimiter}${orig}" 10 | 11 | # if dotfile doesn't exist 12 | if ! [[ -e "${dotfile}" || -e "${orig}" || -L "${orig}" ]]; then 13 | echo "$(prmpt 1 ✘)${message}" 14 | return 1 15 | fi 16 | 17 | linkto="$(readlink "${orig}")" 18 | 19 | if [ "${linkto}" = "${dotfile}" ]; then 20 | echo "$(prmpt 2 ✔)${message}" 21 | else 22 | echo "$(prmpt 1 ✘)${message}" 23 | fi 24 | return 0 25 | } #}}} 26 | 27 | parse_linkfiles _dot_check 28 | 29 | unset -f _dot_check $0 30 | } 31 | -------------------------------------------------------------------------------- /lib/dot_config.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_config() { 3 | # init 4 | if [ ! -e "${dotrc}" ]; then 5 | echo "$(prmpt 1 error)$(bd_ ${dotrc}) doesn't exist." 6 | if __confirm y "make configuration file ? "; then 7 | printf "mkdir -p ${dotrc//dotrc} ... " 8 | mkdir -p "${dotrc//dotrc}" 9 | if [ -d "${dotrc//dotrc}" ]; then echo "$(grn_ Success.)"; else echo "$(rd_ Failure. Aborted.)"; return 1; fi 10 | printf "cp ${DOT_SCRIPT_ROOTDIR}/examples/dotrc ${dotrc} ... " 11 | cp "${DOT_SCRIPT_ROOTDIR}/examples/dotrc" "${dotrc}" 12 | if [ -e "${dotrc}" ]; then echo "$(grn_ Success.)"; else echo "$(rd_ Failure. Aborted.)"; return 1; fi 13 | else 14 | echo "Aborted."; return 1 15 | fi 16 | fi 17 | 18 | # open dotrc file 19 | if [ ! "${dot_edit_default_editor}" = "" ];then 20 | eval ${dot_edit_default_editor} "${dotrc}" 21 | elif hash "$EDITOR"; then 22 | $EDITOR "${dotrc}" 23 | else 24 | xdg-open "${dotrc}" 25 | fi 26 | 27 | unset -f $0 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Shotaro Fujimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /lib/dot_clone.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_clone() { 3 | local cloneto clonecmd 4 | local arg 5 | local dotclone_force=false 6 | 7 | for arg in "$@"; do 8 | shift 9 | case "$arg" in 10 | "--force" ) dotclone_force=true ;; 11 | "-f" ) dotclone_force=true ;; 12 | * ) set -- "$@" "$arg" ;; 13 | esac 14 | done 15 | 16 | cloneto="${1:-"${dotdir}"}" 17 | 18 | if ${dot_clone_shallow}; then 19 | clonecmd="git clone --recursive --depth 1 ${clone_repository} ${cloneto}" 20 | else 21 | clonecmd="git clone --recursive ${clone_repository} ${cloneto}" 22 | fi 23 | 24 | echo "$(prmpt 3 try): ${clonecmd}" 25 | if ! ${dotclone_force}; then 26 | if ! __confirm y "Continue? "; then 27 | echo "Aborted." 28 | echo "" 29 | echo "If you want to clone other repository, change environment variable DOT_REPO." 30 | echo " export DOT_REPO=https://github.com/Your_Username/dotfiles.git" 31 | echo "Set the directory to clone by:" 32 | echo " dot clone ~/dotfiles" 33 | echo " export DOT_DIR=\$HOME/dotfiles" 34 | return 1 35 | fi 36 | fi 37 | 38 | eval "${clonecmd}" 39 | 40 | if [ -s "${cloneto}/.gitmodules" ]; then 41 | echo "$(prmpt 4 "Initialize the submodules")" 42 | git -C "${cloneto}" submodule init 43 | git -C "${cloneto}" submodule update 44 | fi 45 | 46 | unset -f $0 47 | } 48 | -------------------------------------------------------------------------------- /examples/dotlink: -------------------------------------------------------------------------------- 1 | # vim: ft=conf 2 | ############################################################################### 3 | # _ _ __ _ _ # 4 | # __| | ___ | |_ / _(_) | ___ ___ # 5 | # / _` |/ _ \| __| |_| | |/ _ \/ __| # 6 | # | (_| | (_) | |_| _| | | __/\__ \ # 7 | # \__,_|\___/ \__|_| |_|_|\___||___/ # 8 | # # 9 | ############################################################################### 10 | # This file contains dotfiles linksets. 11 | # You can comment out by adding "#" at the beginning of the line. 12 | # And an empty line is ignored by dot. 13 | # 14 | # Format: 15 | # , 16 | # 17 | # the script automatically add directory information to the file path. 18 | # So, you should write like below: 19 | # .vimrc,.vimrc 20 | # 21 | # You can load from outside of the dotfiles directory: 22 | # ~/Dropbox/.netrc,.netrc 23 | # 24 | # You can easily copy the existing file to the dotfiles repository 25 | # and add new link list by 26 | # dot add [-m "some comment"] original_file dotfiles_path 27 | # or, just 28 | # dot add original_file 29 | # In the second example, the script automatically completes the second 30 | # arguments and confirm whether or not to execute that command. 31 | # 32 | #------------------------------------------------------------------------------ 33 | -------------------------------------------------------------------------------- /examples/dotlink.local: -------------------------------------------------------------------------------- 1 | # vim: ft=conf 2 | ############################################################################### 3 | # _ _ __ _ _ # 4 | # __| | ___ | |_ / _(_) | ___ ___ # 5 | # / _` |/ _ \| __| |_| | |/ _ \/ __| # 6 | # | (_| | (_) | |_| _| | | __/\__ \ # 7 | # \__,_|\___/ \__|_| |_|_|\___||___/ # 8 | # # 9 | ############################################################################### 10 | # This file is local config file for dot. 11 | # You can comment out by adding "#" at the beginning of the line. 12 | # And an empty line is ignored by dot. 13 | # 14 | # Format: 15 | # , 16 | # 17 | # the script automatically add directory information to the file path. 18 | # So, you should write like below: 19 | # .vimrc,.vimrc 20 | # 21 | # You can load from outside of the dotfiles directory: 22 | # ~/Dropbox/.netrc,.netrc 23 | # 24 | # You can easily copy the existing file to the dotfiles repository 25 | # and add new link list by 26 | # dot add [-m "some comment"] original_file dotfiles_path 27 | # or, just 28 | # dot add original_file 29 | # In the second example, the script automatically completes the second 30 | # arguments and confirm whether or not to execute that command. 31 | # 32 | #------------------------------------------------------------------------------ 33 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | NAME := dot 3 | VERSION := $(shell grep -m 1 -o '[0-9][0-9.]\+' README.md) 4 | 5 | # Paths 6 | PREFIX ?= /usr/local 7 | MANPREFIX ?= $(PREFIX)/share/man 8 | DOCDIR ?= $(PREFIX)/share/doc/dot 9 | 10 | INSTALLDIR := $(DESTDIR)$(PREFIX) 11 | MANPREFIX := $(DESTDIR)$(MANPREFIX) 12 | DOCDIR := $(DESTDIR)$(DOCDIR) 13 | 14 | DOTDIR := $(HOME)/.dotfiles 15 | USERCONFDIR := $(HOME)/.config/dot 16 | 17 | # Operatios 18 | default: help 19 | 20 | help: 21 | @echo 'Help message' 22 | @echo '' 23 | @echo 'make Do nothing and show help message.' 24 | @echo 'make options Show some options for installation.' 25 | @echo 'make copy-config Copy default configuration to $(USERCONFDIR).' 26 | @echo 'make copy-local-config Copy local configuration template to $(USERCONFDIR).' 27 | @echo 'make man Compile the manpage with "pod2man".' 28 | 29 | options: 30 | @echo 'Options' 31 | @echo 32 | @echo 'INSTALLDIR = $(INSTALLDIR)' 33 | @echo 'MANPREFIX = $(MANPREFIX)' 34 | @echo 'DOCDIR = $(DOCDIR)' 35 | @echo 'DOTDIR = $(DOTDIR)' 36 | @echo 'USERCONFDIR = $(USERCONFDIR)' 37 | 38 | copy-config: 39 | @echo 'Copy the default configuration files to user config directory.' 40 | @echo 41 | install -d $(USERCONFDIR) 42 | cp -i examples/dotrc --target-directory=$(USERCONFDIR) 43 | 44 | copy-local-config: 45 | @echo 'Copy the default local configuration files to user config directory.' 46 | @echo 47 | install -d $(USERCONFDIR) 48 | cp -i examples/dotrc.local examples/dotlink.local --target-directory=$(USERCONFDIR) 49 | 50 | man: 51 | pod2man --stderr -center='dot manual' --date='$(NAME)-$(VERSION)' \ 52 | --release=$(shell date +%x) doc/dot.pod doc/dot.1 53 | 54 | .PHONY: default help options copy-config copy-local-config man 55 | -------------------------------------------------------------------------------- /_dot: -------------------------------------------------------------------------------- 1 | #compdef dot_main 2 | 3 | _dot() { 4 | local context curcontext="$curcontext" state line cmds 5 | cmds=(${(f)"$(dot_main -h | 6 | sed -n '/^Commands:/,/^$/p' | 7 | sed -e '1d;$d' | 8 | cut -b3- | 9 | sed -e 's/ */\:/' 10 | )"}) 11 | _arguments -C \ 12 | '1: :->cmds' \ 13 | {-h,--help}'[Show help message.]: :' \ 14 | {-H,--help-all}'[Show manpage.]: :' \ 15 | {-c,--config}'[Specify the configuration to load]:specify configuration file:_files' \ 16 | '*::arg:->args' \ 17 | && ret=0 18 | 19 | case $state in 20 | cmds) 21 | _describe -t cmds "$DOT_COMMAND []" cmds \ 22 | && ret=0 23 | ;; 24 | args) 25 | local subcmd=$line[1] 26 | case $subcmd in 27 | "clone"|"unlink") 28 | _path_files && ret=0 29 | ;; 30 | "pull") 31 | _values "$DOT_COMMAND pull [--self]" \ 32 | '--self[Update $DOT_COMMAND framework from repository.]' \ 33 | '[Update the dotfiles directory by `git pull`.]' \ 34 | && ret=0 35 | ;; 36 | "add") 37 | _arguments \ 38 | '*: :_path_files -X "$DOT_COMMAND add [] 39 | Select the file to move to DOT_DIR (or an arbitrary path). 40 | (And this command makes its symbolic link.)"' \ 41 | && ret=0 42 | ;; 43 | "set"|"update") 44 | _values "$DOT_COMMAND (set | update) [options]"\ 45 | {-i,--ignore}'[No interaction mode(skip all conflicts).]' \ 46 | {-f,--force}'[Ignore conflicts and force make symbolic links.]' \ 47 | {-b,--backup}'[Ignore conflicts, make symbolic links and create its original backup.]' \ 48 | {-v,--verbose}'[Print verbose messages.]' \ 49 | && ret=0 50 | ;; 51 | esac 52 | ;; 53 | esac 54 | 55 | return ret 56 | } 57 | -------------------------------------------------------------------------------- /examples/dotrc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This is config file for dot. 3 | # If you want to know all the description, see README. 4 | #============================================================================== 5 | # General Settings {{{ 6 | #============================================================================== 7 | 8 | # You can change the dotfiles to clone 9 | clone_repository='https://github.com/username/dotfiles.git' 10 | 11 | # Set the directory that the script regard as dotfiles directory. 12 | #dotdir="$HOME/.dotfiles" 13 | 14 | # Set the path to your dotlink which describes the correspondence relation. 15 | #dotlink="$dotdir/dotlink" 16 | #linkfiles=("${dotlink}") 17 | 18 | # If you want to load additional local setting, add its path to $linkfiles. 19 | # (But it doesn't affect to `dot edit` and `dot add` command, so you should 20 | # edit these files manually.) 21 | #dotlinklocal="$HOME/.config/dot/dotlink.local" 22 | #linkfiles=("${dotlink}" "${dotlinklocal}") 23 | 24 | # You can switch the dotlinklocal by its OS type like below: 25 | 26 | # (In zsh) 27 | 28 | #case ${OSTYPE} in 29 | # *linux*) 30 | # dotlinklocal="${dotdir}/dotlink.linux" 31 | # ;; 32 | # *darwin*) 33 | # dotlinklocal="${dotdir}/dotlink.mac" 34 | # ;; 35 | # *cygwin*|*msys*) 36 | # dotlinklocal="${dotdir}/dotlink.windows" 37 | # ;; 38 | #esac 39 | #linkfiles=("${dotlink}" "${dotlinklocal}") 40 | 41 | # (In bash) 42 | 43 | #if [ "$(uname)" == 'Darwin' ]; then 44 | # dotlinklocal="${dotdir}/dotlink.linux" 45 | #elif [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then 46 | # dotlinklocal="${dotdir}/dotlink.mac" 47 | #elif [ "$(expr substr $(uname -s) 1 10)" == 'MINGW32_NT' ]; then 48 | # dotlinklocal="${dotdir}/dotlink.windows" 49 | #fi 50 | #linkfiles=("${dotlink}" "${dotlinklocal}") 51 | 52 | #===========================================================================}}} 53 | # Options {{{ 54 | #============================================================================== 55 | 56 | # "dot" uses "shallow clone". 57 | # You can clone the only latest commit of the project if set to true. 58 | #dotclone_shallow=false 59 | 60 | # You can choose the action interactively if the file to link is already exist. 61 | # If you set it false, just show message but do nothing (provided option -i). 62 | #dotset_interactive=true 63 | 64 | # Toggle the verbosity for output of `dot set` (option -v). 65 | #dotset_verbose=false 66 | 67 | # You can update submodule in your repository if you set the option below true. 68 | #dotpull_update_submodule=true 69 | 70 | # You can choose diff command as you want. 71 | #diffcmd="colordiff -u" 72 | 73 | # Command to edit two files with diff highlights. 74 | #edit2filecmd='vimdiff' 75 | 76 | # Set your favorite editor. 77 | # (setting priority: this option > $EDITOR (default) > xdg-open) 78 | #dot_edit_default_editor='vim +' 79 | 80 | #===========================================================================}}} 81 | # Load other config file {{{ 82 | #============================================================================== 83 | # If you want to load a machine specific configuration, source that file here. 84 | # `dotbundle file` source the file if it exists. 85 | 86 | #dotbundle "$HOME/.config/dot/dotrc.local" 87 | 88 | #===========================================================================}}} 89 | -------------------------------------------------------------------------------- /dot.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=zsh 2 | # dot - dotfiles management framework 3 | 4 | # Version: 1.2.2 5 | # Repository: https://github.com/ssh0/dot 6 | # Author: ssh0 (Shotaro Fujimoto) 7 | # License: MIT 8 | 9 | DOT_SCRIPT_ROOTDIR="$(builtin cd "$(dirname "${BASH_SOURCE:-${(%):-%N}}")" && builtin pwd)" 10 | readonly DOT_SCRIPT_ROOTDIR 11 | export DOT_SCRIPT_ROOTDIR 12 | 13 | dot_main() { 14 | 15 | dot_usage() { #{{{ 16 | cat << EOF 17 | $DOT_COMMAND - Simplest dotfiles manager 18 | 19 | Usage: $DOT_COMMAND [options] [] 20 | $DOT_COMMAND pull [--self] 21 | $DOT_COMMAND (set | update) [-i | --ignore] [-f | --force] [-b | --backup] [-v | --verbose] 22 | $DOT_COMMAND add ( [$DOT_DIR/path/to/the/file]) | ... 23 | $DOT_COMMAND unlink ... 24 | $DOT_COMMAND clear 25 | $DOT_COMMAND clone [-f | --force] [/dir/to/clone] 26 | $DOT_COMMAND (-h | --help) 27 | 28 | Commands: 29 | clone Clone dotfile repository on your computer with git. 30 | pull Pull the directory from the remote dotfiles repository. 31 | cd Change directory to 'dotdir'. 32 | list Show the list which files will be managed by $DOT_COMMAND. 33 | check Check the files are correctly linked to the right places. 34 | set Set the symbolic links interactively. 35 | update Combined command of 'pull' and 'set' commands. 36 | add Move the file to the dotfiles directory and make its symbolic link to that place. 37 | edit Edit dotlink file. 38 | unlink Unlink the selected symbolic links and copy from its original. 39 | clear Remove the all symbolic links in 'dotlink'. 40 | config Edit (or create if it does not exist) rcfile 'dotrc'. 41 | 42 | Options: 43 | -h, --help Show this help message. 44 | -H, --help-all Show man page. 45 | -c , --config 46 | Specify the configuration file to load. 47 | default: \$HOME/.config/dot/dotrc 48 | 49 | EOF 50 | 51 | } #}}} 52 | 53 | # Option handling {{{ 54 | local arg 55 | for arg in "$@"; do 56 | shift 57 | case "$arg" in 58 | "--help") set -- "$@" "-h" ;; 59 | "--help-all") set -- "$@" "-H" ;; 60 | "--config") set -- "$@" "-c" ;; 61 | *) set -- "$@" "$arg" ;; 62 | esac 63 | done 64 | 65 | OPTIND=1 66 | local dotrc 67 | while getopts "c:hH" OPT 68 | do 69 | case $OPT in 70 | "c") 71 | dotrc="$OPTARG" 72 | ;; 73 | "h") 74 | dot_usage 75 | unset -f dot_usage 76 | return 0 77 | ;; 78 | "H") 79 | man "${DOT_SCRIPT_ROOTDIR}/doc/dot.1" 80 | unset -f dot_usage 81 | return 0 82 | ;; 83 | * ) 84 | dot_usage 85 | unset -f dot_usage 86 | return 1 87 | ;; 88 | esac 89 | done 90 | 91 | shift $((OPTIND-1)) 92 | # }}} 93 | 94 | # Load common.sh {{{ 95 | source "$DOT_SCRIPT_ROOTDIR/lib/common.sh" 96 | trap cleanup_namespace EXIT 97 | # }}} 98 | 99 | # main command handling {{{ 100 | case "$1" in 101 | clone|pull|update|list|check|set|add|edit|unlink|clear|config|cd) 102 | subcommand="$1" 103 | source "$DOT_SCRIPT_ROOTDIR/lib/dot_${subcommand}.sh" 104 | shift 1 105 | dot_${subcommand} "$@" 106 | ;; 107 | *) 108 | echo -n "[$(tput bold)$(tput setaf 1)error$(tput sgr0)] " 109 | echo "command $(tput bold)$1$(tput sgr0) not found." 110 | return 1 111 | ;; 112 | esac 113 | 114 | # }}} 115 | 116 | } 117 | 118 | eval "alias ${DOT_COMMAND:="dot"}=dot_main" 119 | export DOT_COMMAND 120 | 121 | -------------------------------------------------------------------------------- /lib/dot_add.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_add() { 3 | # default message 4 | local message="" 5 | 6 | # option handling 7 | while getopts m:h OPT 8 | do 9 | case $OPT in 10 | "m" ) message="${OPTARG}";; 11 | esac 12 | done 13 | 14 | shift $((OPTIND-1)) 15 | 16 | if [ ! -e "$1" ]; then 17 | echo "$(prmpt 1 error)$(bd_ $1) doesn't exist." 18 | return 1 19 | fi 20 | 21 | orig_to_dot() { #{{{ 22 | # mv from original path to dotdir 23 | local orig dot 24 | 25 | orig="$(get_fullpath "$1")" 26 | dot="$(get_fullpath "$2")" 27 | 28 | mv -i "${orig}" "${dot}" 29 | 30 | # link to orig path from dotfiles 31 | ln -siv "${dot}" "${orig}" 32 | } #}}} 33 | 34 | add_to_dotlink() { #{{{ 35 | local dotfile linkto 36 | # add the configration to the config file. 37 | [ -n "${message}" ] && echo "# ${message}" >> "${dotlink}" 38 | 39 | dotfile="$(path_without_dotdir "$2")" 40 | if [ "${dotfile}" = "" ]; then 41 | dotfile="$(path_without_home "$2")" 42 | if [ -n ${dotfile} ]; then 43 | dotfile="\$HOME/${dotfile}" 44 | else 45 | dotfile="$(get_fullpath "$2")" 46 | fi 47 | fi 48 | 49 | linkto="$(path_without_home "$1")" 50 | linkto="${linkto:="$(get_fullpath "$1")"}" 51 | 52 | echo "${dotfile},${linkto}" >> "${dotlink}" 53 | 54 | if [ $? = 0 ]; then 55 | echo "Successfully added the new file to dotfiles" 56 | echo "To edit the links manually, execute \`${DOT_COMMAND} edit\`" 57 | fi 58 | } #}}} 59 | 60 | if_islink() { #{{{ 61 | # write to dotlink 62 | local f abspath 63 | 64 | for f in "$@"; do 65 | if [ ! -L "$f" ]; then 66 | echo "$(prmpt 1 error)$(bd_ $1) is not the symbolic link." 67 | continue 68 | fi 69 | 70 | # get the absolute path 71 | abspath="$(readlink "$f")" 72 | 73 | if [ ! -e "${abspath}" ]; then 74 | echo -n "$(prmpt 1 error)Target path $(bd_ ${abspath}) doesn't exist." 75 | return 1 76 | fi 77 | 78 | # write to dotlink 79 | add_to_dotlink "$f" "${abspath}" 80 | done 81 | } #}}} 82 | 83 | suggest() { #{{{ 84 | echo "$(prmpt 6 suggestion)" 85 | echo " dot add -m '${message}' $1 ${dotdir}/$(path_without_home "$1")" 86 | __confirm n "Continue? " || return 1 87 | 88 | dot_add_main "$1" "${dotdir}/$(path_without_home $1)" 89 | } #}}} 90 | 91 | check_dir() { #{{{ 92 | if [ -d "${1%/*}" ]; then 93 | return 0 94 | fi 95 | 96 | echo "$(prmpt 1 error)$(bd_ ${1%/*}) doesn't exist." 97 | if __confirm y "make directory $(bd_ ${1%/*}) ? "; then 98 | mkdir -p "${1%/*}" 99 | return 0 100 | fi 101 | 102 | return 1 103 | 104 | } #}}} 105 | 106 | dot_add_main() { #{{{ 107 | # if the first arugument is a symbolic link 108 | if [ -L "$1" ]; then 109 | if_islink "$@" || return 1 110 | return 0 111 | fi 112 | 113 | # if the second arguments is provided (default action) 114 | if [ $# = 2 ]; then 115 | 116 | # if the targeted directory doesn't exist, 117 | # ask whether make directory or not. 118 | check_dir "$2" || return 1 119 | 120 | orig_to_dot "$1" "$2" 121 | add_to_dotlink "$1" "$2" 122 | 123 | return 0 124 | fi 125 | 126 | # if the second arugument isn't provided, provide suggestion 127 | if [ $# = 1 ];then 128 | suggest "$1" && return 0 || return 1 129 | fi 130 | 131 | # else 132 | echo "$(prmpt 1 error)Aborted." 133 | echo "Usage: 'dot add file'" 134 | echo " 'dot add file ${dotdir}/any/path/to/the/file'" 135 | 136 | return 1 137 | } #}}} 138 | 139 | dot_add_main "$@" 140 | 141 | unset -f orig_to_dot add_to_dotlink if_islink suggest check_dir 142 | unset -f $0 143 | } 144 | -------------------------------------------------------------------------------- /doc/dot.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | dot - manages symbolic links for dotfiles 4 | 5 | 6 | 7 | 8 | =head1 SYNOPSIS 9 | 10 | B [B<-h>|B<--help>][B<-c> I] I [I] 11 | 12 | 13 | 14 | 15 | =head1 DESCRIPTION 16 | 17 | This script makes it easy to manage your dotfiles. 18 | 19 | Script is written in bash, and very configurable. 20 | 21 | 22 | 23 | 24 | =head1 COMMANDS 25 | 26 | =over 10 27 | 28 | =item B 29 | 30 | Clone dotfile repository on your computer with git. 31 | 32 | =item B 33 | 34 | Pull the repository from the remote dotfiles repository. 35 | 36 | =item B 37 | 38 | Combined command of B and B commands. 39 | 40 | =item B 41 | 42 | Change directory to F. 43 | 44 | =item B 45 | 46 | Show the list which files will be managed by B. 47 | 48 | =item B 49 | 50 | Check the files are correctly linked to the right places. 51 | 52 | =item B 53 | 54 | Set the symbolic links interactively. This command sets symbolic links configured in F. 55 | 56 | =item B 57 | 58 | Move the file to the dotfile dir and make its symbolic link to that place. 59 | 60 | =item B 61 | 62 | Edit dotlink file F. 63 | 64 | =item B 65 | 66 | Unlink the selected symbolic links and copy from its original files in the dotfiles repository. 67 | 68 | =item B 69 | 70 | Remove the all symbolic links in F. 71 | 72 | =item B 73 | 74 | Edit (or create if the file doesn't exist) rcfile F. 75 | 76 | =back 77 | 78 | 79 | =head1 OPTION 80 | 81 | =over 10 82 | 83 | =item B<-h>, B<--help> 84 | 85 | Show the help message. 86 | 87 | =item B<-H>, B<--help-all> 88 | 89 | Show man page. 90 | 91 | =item B<-c> I, B<--config> I 92 | 93 | Specify configuration file to overload. (default: I<~/.config/dot/dotrc>) 94 | 95 | =back 96 | 97 | 98 | =head1 COMMAND OPTIONS 99 | 100 | =over 4 101 | 102 | =item B [I] 103 | 104 | Clone I onto the specified direction. (default: I<~/.dotfiles>) 105 | 106 | =over 6 107 | 108 | =item B<-f>, B<--force> 109 | 110 | Never prompt. 111 | 112 | =back 113 | 114 | =item B [B<--self>] 115 | 116 | With --self option, update B itself. 117 | 118 | =item B 119 | 120 | =over 6 121 | 122 | =item B<-i>, B<--ignore> 123 | 124 | No interaction mode (skip all conflicts and do nothing). 125 | 126 | =item B<-f>, B<--force> 127 | 128 | Ignore conflicts and force make symbolic links. 129 | 130 | =item B<-b>, B<--backup> 131 | 132 | Ignore conflicts, make symbolic links and create its original backup. 133 | 134 | =item B<-v>, B<--verbose> 135 | 136 | Print verbose messages. 137 | 138 | =back 139 | 140 | =item B 141 | 142 | Combined command of B and B commands. Options are same as B commnad ones. 143 | 144 | =item B [B<-m> I] I [I] 145 | 146 | =over 12 147 | 148 | =item B<-m> I 149 | 150 | Add your comment for dotlink file. 151 | 152 | =back 153 | 154 | =back 155 | 156 | 157 | =head1 ENVIRONMENT VARIABLE 158 | 159 | =over 10 160 | 161 | =item B 162 | 163 | Dotfiles repository to manage with this program. You may should change this environment variable. (default: I) 164 | 165 | =item B 166 | 167 | Directory for dotfiles (default: I<$HOME/.dotfiles>) 168 | 169 | =item B 170 | 171 | Text file to save symbolic links information (default: I<$DOT_DIR/dotlink>) 172 | 173 | =back 174 | 175 | =head1 CONFIGURATION 176 | 177 | Configuration file is B<$HOME/.config/dot/dotrc> and symbolic information is in B<$DOT_DIR/dotlink>. 178 | 179 | =head1 AUTHOR 180 | 181 | ssh0 (Shotaro Fujimoto L) 182 | 183 | Report bugs here: L 184 | 185 | 186 | =head1 LICENSE 187 | 188 | This is free software; you may redistribute it and/or modify it under the MIT Lisence. 189 | 190 | 191 | -------------------------------------------------------------------------------- /lib/common.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | # Local variables {{{ 3 | # ----------------------------------------------------------------------------- 4 | 5 | local clone_repository dotdir dotlink linkfiles home_pattern dotdir_pattern 6 | local dotclone_shallow dotset_interactive dotset_verbose diffcmd edit2filecmd 7 | local dot_edit_default_editor columns hrule tp_bold tp_reset 8 | local dotpull_update_submodule 9 | 10 | # --------------------------------------------------------------------------}}} 11 | # Default settings {{{ 12 | # ----------------------------------------------------------------------------- 13 | 14 | clone_repository="${DOT_REPO:-"https://github.com/ssh0/dotfiles.git"}" 15 | 16 | dotdir="${DOT_DIR:-"$HOME/.dotfiles"}" 17 | dotlink="${DOT_LINK:-"$dotdir/dotlink"}" 18 | linkfiles=("${dotlink}") 19 | 20 | home_pattern="s@$HOME/@@p" 21 | dotdir_pattern="s@${dotdir}/@@p" 22 | 23 | dotclone_shallow=false 24 | dotset_interactive=true 25 | dotset_verbose=false 26 | dotpull_update_submodule=true 27 | 28 | if hash colordiff 2>/dev/null; then 29 | diffcmd='colordiff -u' 30 | else 31 | diffcmd='diff -u' 32 | fi 33 | 34 | if hash vimdiff 2>/dev/null; then 35 | edit2filecmd='vimdiff' 36 | else 37 | edit2filecmd="${diffcmd}" 38 | fi 39 | 40 | # --------------------------------------------------------------------------}}} 41 | # Load user configuration {{{ 42 | # ----------------------------------------------------------------------------- 43 | 44 | dotbundle() { 45 | if [ -e "$1" ]; then 46 | source "$1" 47 | fi 48 | } 49 | 50 | # path to the config file 51 | dotrc="${dotrc:-"$HOME/.config/dot/dotrc"}" 52 | dotbundle "${dotrc}" 53 | 54 | # --------------------------------------------------------------------------}}} 55 | 56 | # makeline {{{ 57 | 58 | columns=$(tput cols) 59 | hrule="$( printf '%*s\n' "$columns" '' | tr ' ' - )" 60 | 61 | #}}} 62 | 63 | # tput {{{ 64 | 65 | tp_bold="$(tput bold)" 66 | tp_green=$(tput setaf 2) 67 | tp_red=$(tput setaf 1) 68 | tp_reset="$(tput sgr0)" 69 | 70 | #}}} 71 | 72 | get_fullpath() { #{{{ 73 | echo "$(builtin cd "$(dirname "$1")" && builtin pwd)"/"$(basename "$1")" 74 | } #}}} 75 | 76 | path_without_home() { #{{{ 77 | get_fullpath "$1" | sed -ne "${home_pattern}" 78 | } #}}} 79 | 80 | path_without_dotdir() { #{{{ 81 | get_fullpath "$1" | sed -ne "${dotdir_pattern}" 82 | } #}}} 83 | 84 | __confirm() { #{{{ 85 | # __confirm [ y | n ] [] 86 | local yn YN confirm ret 87 | if [ "$1" = "y" ]; then 88 | yn="y" 89 | YN="Y/n" 90 | ret=0 91 | shift 92 | elif [ "$1" = "n" ]; then 93 | yn="n" 94 | YN="y/N" 95 | ret=1 96 | shift 97 | else 98 | YN="y/n" 99 | ret=-1 100 | fi 101 | 102 | echo -n "$@($YN)> " 103 | read confirm 104 | confirm=$(echo $confirm | tr '[:upper:]' '[:lower:]') 105 | case $confirm in 106 | y|yes) return 0 ;; 107 | n|no) return 1 ;; 108 | "") if [ $ret -eq -1 ]; then 109 | echo "Please answer with 'y' or 'n'." 110 | __confirm $@ 111 | else 112 | return $ret 113 | fi 114 | ;; 115 | *) echo "Please answer with 'y' or 'n'." 116 | __confirm $yn $@;; 117 | esac 118 | 119 | } #}}} 120 | 121 | prmpt() { #{{{ 122 | echo "${tp_bold}$(tput setaf $1)$2${tp_reset} " 123 | } #}}} 124 | 125 | bd_() { #{{{ 126 | echo "${tp_bold}$@${tp_reset}" 127 | } #}}} 128 | 129 | rd_() { #{{{ 130 | echo "${tp_red}$@${tp_reset}" 131 | } #}}} 132 | 133 | grn_() { #{{{ 134 | echo "${tp_green}$@${tp_reset}" 135 | } #}}} 136 | 137 | cleanup_namespace() { #{{{ 138 | unset -f dotbundle get_fullpath path_without_home path_without_dotdir 139 | unset -f __confirm prmpt bd_ grn_ rd_ dot_usage parse_linkfiles $0 140 | } #}}} 141 | 142 | parse_linkfiles() { # {{{ 143 | local linkfile l 144 | local command 145 | local IFS_BACKUP=$IFS 146 | IFS=$'\n' 147 | 148 | command="$1" 149 | 150 | for linkfile in "${linkfiles[@]}"; do 151 | echo "$(prmpt 4 "Loading ${linkfile} ...")" 152 | for l in $(grep -Ev '^\s*#|^\s*$' "${linkfile}"); do 153 | # extract environment variables 154 | dotfile="$(echo $l | cut -d, -f1)" 155 | dotfile="$(eval echo ${dotfile})" 156 | orig="$(echo $l | cut -d, -f2)" 157 | orig="$(eval echo ${orig})" 158 | 159 | # path completion 160 | [ "${dotfile:0:1}" = "/" ] || dotfile="${dotdir}/$dotfile" 161 | [ "${orig:0:1}" = "/" ] || orig="$HOME/$orig" 162 | 163 | $command "$dotfile" "$orig" 164 | done 165 | done 166 | 167 | IFS=$IFS_BACKUP 168 | 169 | } # }}} 170 | -------------------------------------------------------------------------------- /lib/dot_set.sh: -------------------------------------------------------------------------------- 1 | # vim: ft=sh 2 | dot_set() { 3 | # option handling 4 | local arg 5 | local dotset_ignore=false 6 | local dotset_force=false 7 | local dotset_backup=false 8 | local dotset_verbose=false 9 | 10 | for arg in "$@"; do 11 | shift 12 | case "$arg" in 13 | "--ignore" ) set -- "$@" "-i" ;; 14 | "--force" ) set -- "$@" "-f" ;; 15 | "--backup" ) set -- "$@" "-b" ;; 16 | "--verbose") set -- "$@" "-v" ;; 17 | *) set -- "$@" "$arg" ;; 18 | esac 19 | done 20 | 21 | OPTIND=1 22 | 23 | while getopts ifbv OPT; do 24 | case $OPT in 25 | "i" ) dotset_ignore=true ;; 26 | "f" ) dotset_force=true ;; 27 | "b" ) dotset_backup=true ;; 28 | "v" ) dotset_verbose=true ;; 29 | esac 30 | done 31 | 32 | check_dir() { #{{{ 33 | local orig="$1" 34 | 35 | origdir="${orig%/*}" 36 | 37 | [ -d "${origdir}" ] && return 0 38 | 39 | echo "$(prmpt 1 error)$(bd_ ${origdir}) doesn't exist." 40 | 41 | ${dotset_ignore} && return 1 42 | 43 | if ! ${dotset_force}; then 44 | __confirm y "make directory $(bd_ ${origdir}) ? " || return 1 45 | fi 46 | mkdir -p "${origdir}" && return 0 47 | } #}}} 48 | 49 | replace() { #{{{ 50 | # replace "${orig}" "${dotfile}" 51 | if [ -d "$1" ]; then 52 | rm -rf -- "$1" 53 | else 54 | rm -f -- "$1" 55 | fi 56 | ln -s "$2" "$1" 57 | echo "$(prmpt 2 done)$1" 58 | } #}}} 59 | 60 | replace_and_backup() { #{{{ 61 | # replace_and_backup "${orig}" "${dotfile}" 62 | backuped="$1$(date +'_%Y%m%d_%H%M%S')" 63 | mv -i "$1" "${backuped}" 64 | ln -s "$2" "$1" 65 | echo "$(prmpt 2 done)$1" 66 | echo "$(prmpt 2 "make backup")${backuped}" 67 | } #}}} 68 | 69 | if_islink() { #{{{ 70 | local orig="$1" 71 | local dotfile="$2" 72 | local linkto="$(readlink "${orig}")" 73 | 74 | # if the link has already be set: do nothing 75 | if [ "${linkto}" = "${dotfile}" ]; then 76 | ${dotset_verbose} && echo "$(prmpt 2 exists)${orig}" 77 | return 0 78 | fi 79 | 80 | echo "$(prmpt 1 conflict)Other link already exists at $(bd_ ${orig})" 81 | 82 | ${dotset_ignore} && return 0 83 | 84 | if ! ${dotset_force}; then 85 | echo -n " $(prmpt 2 now)" 86 | echo "${orig} $(tput setaf 5)<--$(tput sgr0) ${linkto}" 87 | echo -n " $(prmpt 3 try)" 88 | echo "${orig} $(tput setaf 5)<--$(tput sgr0) ${dotfile}" 89 | __confirm n "Unlink and re-link for $(bd_ ${orig}) ? " || return 0 90 | fi 91 | unlink "${orig}" 92 | ln -s "${dotfile}" "${orig}" 93 | echo "$(prmpt 2 done)${orig}" 94 | 95 | return 0 96 | } #}}} 97 | 98 | if_exist() { #{{{ 99 | # local line 100 | local orig="$1" 101 | local dotfile="$2" 102 | 103 | if ${dotset_ignore}; then 104 | echo "$(prmpt 1 conflict)File already exists at $(bd_ ${orig})." 105 | return 0 106 | fi 107 | 108 | if ${dotset_force}; then 109 | replace "${orig}" "${dotfile}" 110 | return 0 111 | fi 112 | 113 | if ${dotset_backup}; then 114 | replace_and_backup "${orig}" "${dotfile}" 115 | return 0 116 | fi 117 | 118 | while true; do 119 | echo "$(prmpt 1 conflict)File already exists at $(bd_ ${orig})." 120 | echo "Choose the operation:" 121 | echo " ($(bd_ d)):show diff" 122 | echo " ($(bd_ e)):edit files" 123 | echo " ($(bd_ f)):replace" 124 | echo " ($(bd_ b)):replace and make backup" 125 | echo " ($(bd_ n)):do nothing" 126 | echo -n ">>> "; read line 127 | case $line in 128 | [Dd] ) 129 | eval "${diffcmd}" "${dotfile}" "${orig}" 130 | echo "" 131 | ;; 132 | [Ee] ) 133 | eval "${edit2filecmd}" "${dotfile}" "${orig}" 134 | ;; 135 | [Ff] ) 136 | replace "${orig}" "${dotfile}" 137 | break 138 | ;; 139 | [Bb] ) 140 | replace_and_backup "${orig}" "${dotfile}" 141 | break 142 | ;; 143 | [Nn] ) 144 | break 145 | ;; 146 | *) 147 | echo "Please answer with [d/e/f/b/n]." 148 | ;; 149 | esac 150 | done 151 | 152 | return 0 153 | } #}}} 154 | 155 | _dot_set() { #{{{ 156 | local dotfile orig 157 | dotfile="$1" 158 | orig="$2" 159 | 160 | # if dotfile doesn't exist, print error message and pass 161 | if [ ! -e "${dotfile}" ]; then 162 | echo "$(prmpt 1 "not found")${dotfile}" 163 | return 1 164 | fi 165 | 166 | # if the targeted directory doesn't exist, 167 | # ask whether make directory or not. 168 | check_dir "${orig}" || return 1 169 | 170 | if [ -e "${orig}" ]; then # if the file already exists: 171 | if [ -L "${orig}" ]; then # if it is a symbolic-link: 172 | if_islink "${orig}" "${dotfile}" # do nothing or relink 173 | else # if it is a file or a dir: 174 | if_exist "${orig}" "${dotfile}" # ask user what to do 175 | fi # 176 | else # else: 177 | readlink "${orig}" 1>/dev/null && unlink "${orig}" 178 | ln -s "${dotfile}" "${orig}" # make symbolic link 179 | test $? && echo "$(prmpt 2 done)${orig}" 180 | fi 181 | 182 | } #}}} 183 | 184 | parse_linkfiles _dot_set 185 | 186 | unset -f check_dir if_islink if_exist _dot_set replace replace_and_backup $0 187 | } 188 | -------------------------------------------------------------------------------- /doc/dot.1: -------------------------------------------------------------------------------- 1 | .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) 2 | .\" 3 | .\" Standard preamble: 4 | .\" ======================================================================== 5 | .de Sp \" Vertical space (when we can't use .PP) 6 | .if t .sp .5v 7 | .if n .sp 8 | .. 9 | .de Vb \" Begin verbatim text 10 | .ft CW 11 | .nf 12 | .ne \\$1 13 | .. 14 | .de Ve \" End verbatim text 15 | .ft R 16 | .fi 17 | .. 18 | .\" Set up some character translations and predefined strings. \*(-- will 19 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left 20 | .\" double quote, and \*(R" will give a right double quote. \*(C+ will 21 | .\" give a nicer C++. Capital omega is used to do unbreakable dashes and 22 | .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, 23 | .\" nothing in troff, for use with C<>. 24 | .tr \(*W- 25 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' 26 | .ie n \{\ 27 | . ds -- \(*W- 28 | . ds PI pi 29 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch 30 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch 31 | . ds L" "" 32 | . ds R" "" 33 | . ds C` "" 34 | . ds C' "" 35 | 'br\} 36 | .el\{\ 37 | . ds -- \|\(em\| 38 | . ds PI \(*p 39 | . ds L" `` 40 | . ds R" '' 41 | . ds C` 42 | . ds C' 43 | 'br\} 44 | .\" 45 | .\" Escape single quotes in literal strings from groff's Unicode transform. 46 | .ie \n(.g .ds Aq \(aq 47 | .el .ds Aq ' 48 | .\" 49 | .\" If the F register is >0, we'll generate index entries on stderr for 50 | .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index 51 | .\" entries marked with X<> in POD. Of course, you'll have to process the 52 | .\" output yourself in some meaningful fashion. 53 | .\" 54 | .\" Avoid warning from groff about undefined register 'F'. 55 | .de IX 56 | .. 57 | .if !\nF .nr F 0 58 | .if \nF>0 \{\ 59 | . de IX 60 | . tm Index:\\$1\t\\n%\t"\\$2" 61 | .. 62 | . if !\nF==2 \{\ 63 | . nr % 0 64 | . nr F 2 65 | . \} 66 | .\} 67 | .\" 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. 70 | . \" fudge factors for nroff and troff 71 | .if n \{\ 72 | . ds #H 0 73 | . ds #V .8m 74 | . ds #F .3m 75 | . ds #[ \f1 76 | . ds #] \fP 77 | .\} 78 | .if t \{\ 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) 80 | . ds #V .6m 81 | . ds #F 0 82 | . ds #[ \& 83 | . ds #] \& 84 | .\} 85 | . \" simple accents for nroff and troff 86 | .if n \{\ 87 | . ds ' \& 88 | . ds ` \& 89 | . ds ^ \& 90 | . ds , \& 91 | . ds ~ ~ 92 | . ds / 93 | .\} 94 | .if t \{\ 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' 101 | .\} 102 | . \" troff and (daisy-wheel) nroff accents 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] 110 | .ds ae a\h'-(\w'a'u*4/10)'e 111 | .ds Ae A\h'-(\w'A'u*4/10)'E 112 | . \" corrections for vroff 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' 115 | . \" for low resolution devices (crt and lpr) 116 | .if \n(.H>23 .if \n(.V>19 \ 117 | \{\ 118 | . ds : e 119 | . ds 8 ss 120 | . ds o a 121 | . ds d- d\h'-1'\(ga 122 | . ds D- D\h'-1'\(hy 123 | . ds th \o'bp' 124 | . ds Th \o'LP' 125 | . ds ae ae 126 | . ds Ae AE 127 | .\} 128 | .rm #[ #] #H #V #F C 129 | .\" ======================================================================== 130 | .\" 131 | .IX Title "DOT 1" 132 | .TH DOT 1 "dot-1.2.2" "01/07/2018" "dot manual" 133 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 134 | .\" way too many mistakes in technical documents. 135 | .if n .ad l 136 | .nh 137 | .SH "NAME" 138 | dot \- manages symbolic links for dotfiles 139 | .SH "SYNOPSIS" 140 | .IX Header "SYNOPSIS" 141 | \&\fBdot\fR [\fB\-h\fR|\fB\-\-help\fR][\fB\-c\fR \fIconfigfile\fR] \fIcommand\fR [\fIargs\fR] 142 | .SH "DESCRIPTION" 143 | .IX Header "DESCRIPTION" 144 | This script makes it easy to manage your dotfiles. 145 | .PP 146 | Script is written in bash, and very configurable. 147 | .SH "COMMANDS" 148 | .IX Header "COMMANDS" 149 | .IP "\fBclone\fR" 10 150 | .IX Item "clone" 151 | Clone dotfile repository on your computer with git. 152 | .IP "\fBpull\fR" 10 153 | .IX Item "pull" 154 | Pull the repository from the remote dotfiles repository. 155 | .IP "\fBupdate\fR" 10 156 | .IX Item "update" 157 | Combined command of \fBpull\fR and \fBset\fR commands. 158 | .IP "\fBcd\fR" 10 159 | .IX Item "cd" 160 | Change directory to \fIdotdir\fR. 161 | .IP "\fBlist\fR" 10 162 | .IX Item "list" 163 | Show the list which files will be managed by \fBdot\fR. 164 | .IP "\fBcheck\fR" 10 165 | .IX Item "check" 166 | Check the files are correctly linked to the right places. 167 | .IP "\fBset\fR" 10 168 | .IX Item "set" 169 | Set the symbolic links interactively. This command sets symbolic links configured in \fIdotlink\fR. 170 | .IP "\fBadd\fR" 10 171 | .IX Item "add" 172 | Move the file to the dotfile dir and make its symbolic link to that place. 173 | .IP "\fBedit\fR" 10 174 | .IX Item "edit" 175 | Edit dotlink file \fIdotlink\fR. 176 | .IP "\fBunlink\fR" 10 177 | .IX Item "unlink" 178 | Unlink the selected symbolic links and copy from its original files in the dotfiles repository. 179 | .IP "\fBclear\fR" 10 180 | .IX Item "clear" 181 | Remove the all symbolic links in \fIdotlink\fR. 182 | .IP "\fBconfig\fR" 10 183 | .IX Item "config" 184 | Edit (or create if the file doesn't exist) rcfile \fIdotrc\fR. 185 | .SH "OPTION" 186 | .IX Header "OPTION" 187 | .IP "\fB\-h\fR, \fB\-\-help\fR" 10 188 | .IX Item "-h, --help" 189 | Show the help message. 190 | .IP "\fB\-H\fR, \fB\-\-help\-all\fR" 10 191 | .IX Item "-H, --help-all" 192 | Show man page. 193 | .IP "\fB\-c\fR \fIconfigfile\fR, \fB\-\-config\fR \fIconfigfile\fR" 10 194 | .IX Item "-c configfile, --config configfile" 195 | Specify configuration file to overload. (default: \fI~/.config/dot/dotrc\fR) 196 | .SH "COMMAND OPTIONS" 197 | .IX Header "COMMAND OPTIONS" 198 | .IP "\fBclone\fR [\fIdir\fR]" 4 199 | .IX Item "clone [dir]" 200 | Clone \fIclone_repository\fR onto the specified direction. (default: \fI~/.dotfiles\fR) 201 | .RS 4 202 | .IP "\fB\-f\fR, \fB\-\-force\fR" 6 203 | .IX Item "-f, --force" 204 | Never prompt. 205 | .RE 206 | .RS 4 207 | .RE 208 | .IP "\fBpull\fR [\fB\-\-self\fR]" 4 209 | .IX Item "pull [--self]" 210 | With \-\-self option, update \fBdot\fR itself. 211 | .IP "\fBset\fR" 4 212 | .IX Item "set" 213 | .RS 4 214 | .PD 0 215 | .IP "\fB\-i\fR, \fB\-\-ignore\fR" 6 216 | .IX Item "-i, --ignore" 217 | .PD 218 | No interaction mode (skip all conflicts and do nothing). 219 | .IP "\fB\-f\fR, \fB\-\-force\fR" 6 220 | .IX Item "-f, --force" 221 | Ignore conflicts and force make symbolic links. 222 | .IP "\fB\-b\fR, \fB\-\-backup\fR" 6 223 | .IX Item "-b, --backup" 224 | Ignore conflicts, make symbolic links and create its original backup. 225 | .IP "\fB\-v\fR, \fB\-\-verbose\fR" 6 226 | .IX Item "-v, --verbose" 227 | Print verbose messages. 228 | .RE 229 | .RS 4 230 | .RE 231 | .IP "\fBupdate\fR" 4 232 | .IX Item "update" 233 | Combined command of \fBpull\fR and \fBset\fR commands. Options are same as \fBset\fR commnad ones. 234 | .IP "\fBadd\fR [\fB\-m\fR \fImessage\fR] \fIoriginal_file\fR [\fIdotfile_direction\fR]" 4 235 | .IX Item "add [-m message] original_file [dotfile_direction]" 236 | .RS 4 237 | .PD 0 238 | .IP "\fB\-m\fR \fImessage\fR" 12 239 | .IX Item "-m message" 240 | .PD 241 | Add your comment for dotlink file. 242 | .RE 243 | .RS 4 244 | .RE 245 | .SH "ENVIRONMENT VARIABLE" 246 | .IX Header "ENVIRONMENT VARIABLE" 247 | .IP "\fB\s-1DOT_REPO\s0\fR" 10 248 | .IX Item "DOT_REPO" 249 | Dotfiles repository to manage with this program. You may should change this environment variable. (default: \fIhttps://github.com/ssh0/dotfiles.git\fR) 250 | .IP "\fB\s-1DOT_DIR\s0\fR" 10 251 | .IX Item "DOT_DIR" 252 | Directory for dotfiles (default: \fI\f(CI$HOME\fI/.dotfiles\fR) 253 | .IP "\fB\s-1DOT_LINK\s0\fR" 10 254 | .IX Item "DOT_LINK" 255 | Text file to save symbolic links information (default: \fI\f(CI$DOT_DIR\fI/dotlink\fR) 256 | .SH "CONFIGURATION" 257 | .IX Header "CONFIGURATION" 258 | Configuration file is \fB\f(CB$HOME\fB/.config/dot/dotrc\fR and symbolic information is in \fB\f(CB$DOT_DIR\fB/dotlink\fR. 259 | .SH "AUTHOR" 260 | .IX Header "AUTHOR" 261 | ssh0 (Shotaro Fujimoto ) 262 | .PP 263 | Report bugs here: 264 | .SH "LICENSE" 265 | .IX Header "LICENSE" 266 | This is free software; you may redistribute it and/or modify it under the \s-1MIT\s0 Lisence. 267 | -------------------------------------------------------------------------------- /README_ja.md: -------------------------------------------------------------------------------- 1 | [English](./README.md) 2 | 3 | # dot v1.2.2 4 | 5 | `dot`はシェルスクリプトで書かれたdotfiles管理フレームワークです。 6 | 7 | ## 説明 8 | 9 | このスクリプトを使うとdotfilesの管理が簡単になります。 10 | 11 | 日常的に複数マシンを使う人,新しいPCのセットアップするとき,毎日dotfilesでcontributionに草を生やし続けている人におすすめです。 12 | 13 | ## インストール 14 | 15 | ### 必要なもの 16 | 17 | * bash (or zsh) 18 | * git 19 | 20 | ### 手動でインストール 21 | 22 | このリポジトリを自分のPCにforkかcloneし,`bashrc`や`zshrc`から`source`コマンドでファイルを読み込んでください。 23 | 24 | 25 | **COMMAND LINE** 26 | 27 | ``` 28 | git clone https://github.com/ssh0/dot $HOME/.zsh/dot 29 | ``` 30 | 31 | **in {bash,zsh}rc** 32 | 33 | ``` 34 | export DOT_REPO="https://github.com/your_username/dotfiles.git" 35 | export DOT_DIR="$HOME/.dotfiles" 36 | fpath=($HOME/.zsh/dot $fpath) # <- for completion 37 | source $HOME/.zsh/dot/dot.sh 38 | ``` 39 | 40 | これでインストールは完了です。 41 | 42 | shellrcを読み込みなおして、 43 | 44 | ``` 45 | dot --help-all 46 | ``` 47 | 48 | と打ち込んでみてください。manページが表示されます。 49 | 50 | ### プラグインマネージャを利用する場合 51 | 52 | zshを利用していて,プラグインマネージャを利用している場合(ex. [zplug](https://github.com/b4b4r07/zplug), [zgen](https://github.com/tarjoilija/zgen), etc.)には,`zshrc`でプラグインとして読み込んでください。 53 | 54 | ``` 55 | zplug "ssh0/dot", use:"*.sh" 56 | ``` 57 | 58 | ``` 59 | zgen load ssh0/dot 60 | ``` 61 | 62 | {bash,zsh}rcに以下を書きます。 63 | 64 | ``` 65 | export DOT_REPO="https://github.com/your_username/dotfiles.git" 66 | export DOT_DIR="$HOME/.dotfiles" 67 | ``` 68 | 69 | ## 使い方 70 | 71 | ユーザーの設定ファイルは'[dotrc](./examples/dotrc)'。 72 | シンボリックリンクの対応表は'[dotlink](./examples/dotlink)'に書きます。 73 | 74 | **サブコマンド** 75 | 76 | | サブコマンド名 | 説明 | オプション or 引数 | 77 | | --- | --- | --- | 78 | | [pull](#dot_pull) | dotfiesをpullしてくる(by git). | `[--self]` | 79 | | [list](#dot_list) | `dot`で管理するファイルを一覧を表示 | | 80 | | [check](#dot_check) | ファイルにリンクが張られているかどうかチェックする | | 81 | | [cd](#dot_cd) | ディレクトリ`dotdir`に移動 | | 82 | | [set](#dot_set) | `dotlink`に書かれたシンボリックリンクを貼る | `[-i\|--ignore][-f\|--force][-b\|--backup][-v\|--verbose]` | 83 | | [update](#dot_update) | 'pull'コマンドと'set'コマンドの組み合わせ | `[-i\|--ignore][-f\|--force][-b\|--backup][-v\|--verbose]` | 84 | | [add](#dot_add) | 新たなファイルをdotfilesに追加,シンボリックリンクを貼り,対応関係を`dotlink`に追記 | `some_file [$DOT_DIR/path/to/the/file]` or `link1 [link2 link3 ... ]` | 85 | | [edit](#dot_edit) | `dotlink`を手動で編集 | | 86 | | [config](#dot_config) | 設定ファイル`dotrc`を編集 | | 87 | | [unlink](#dot_unlink) | 選択したシンボリックリンクをunlinkし,dotfilesから元ファイルをコピー | `link1 [link2 link3 ... ]` | 88 | | [clear](#dot_clear) | `dotlink`ファイルに記載された**すべての**シンボリックリンクをunlink | | 89 | | [clone](#dot_clone) | gitコマンドを使ってdotfilesを自分のPCにクローン | `[-f\|--force] [/directory/to/clone/]` | 90 | 91 | **オプション** 92 | 93 | |オプション |説明 |引数 | 94 | |--- |--- |--- | 95 | | -h, --help |ヘルプを表示 | | 96 | | -c, --config|読み込む設定ファイルを指定| `dotrc` | 97 | 98 | ### dot pull 99 | 100 | dotfiesをpullしてくる(by git)。 101 | 102 | ![dot pull](./img/dot_pull.png) 103 | 104 | `--self`オプションをつけると,`dot`自身を最新の状態に更新します。 105 | 106 | ``` 107 | dot pull --self 108 | ``` 109 | 110 | ### dot list 111 | 112 | ![dot list](./img/dot_list.png) 113 | 114 | `dot`で管理するファイルを一覧表示する。 115 | 116 | ### dot check 117 | 118 | ファイルにリンクが張られているかどうかチェックする。 119 | 120 | ![dot check](./img/dot_check.png) 121 | 122 | * "✘" は現在dotで管理されていないが`dotlink`に対応が書かれているものを表す。 123 | * "✔" はdotで管理されているものを表す。 124 | 125 | ### dot cd 126 | 127 | ![dot cd](./img/dot_cd.png) 128 | 129 | ディレクトリ`dotdir`に移動します。 130 | 131 | ### dot set 132 | 133 | このコマンドは,`dotlink`に書かれたシンボリックリンクを貼っていきます。 134 | 135 | もし既にファイルが存在する場合には, 136 | 137 | * 差分表示 138 | * 2ファイルを編集 139 | * 既存ファイルに上書き 140 | * バックアップを作成して上書き 141 | * 何もしない 142 | 143 | の操作を選ぶことができます。 144 | 145 | オプション`-i`または`--ignore`をつけると、競合するファイルが存在する場合に対話メニューを開かず、何も操作しません。 146 | 147 | オプション`-f`または`--force`をつけた場合は、競合するファイルがある場合に対話メニューを開くことなく、すべて新たなシンボリックリンクに置き換えます。 148 | 149 | オプション`-b`または`--backup`をつけると、競合するファイルが存在する場合に対話メニューを開かず、新たなシンボリックを張りますが、オリジナルのファイルは`file.bak`のようにしてバックアップファイルとして残されます。 150 | 151 | `-v`または`--verbose`オプションをつけると、すでにリンクが張られているものについて等、より冗長なメッセージを表示します。 152 | 153 | ![dot set](./img/dot_set.png) 154 | 155 | ### dot update 156 | 157 | 'pull'コマンドと'set'コマンドを組み合わせた機能を提供します。 158 | オプションは`set`コマンドと同じものを受け取ることができます。 159 | 160 | ### dot add 161 | 162 | 新たなファイルをdotfilesに追加,シンボリックリンクを貼り,対応関係を`dotlink`に追記 163 | 164 | ![dot add](./img/dot_add.png) 165 | 166 | ### dot edit 167 | 168 | `dotlink`を手動で編集する。 169 | 170 | ``` 171 | dot edit 172 | ``` 173 | 174 | ### dot config 175 | 176 | 設定ファイル`dotrc`を編集する。 177 | 178 | ``` 179 | dot config 180 | ``` 181 | 182 | ### dot unlink 183 | 184 | 選択したシンボリックリンクをunlinkし,dotfilesから元ファイルのコピーを持ってくる。 185 | 186 | ![dot unlink](./img/dot_unlink.png) 187 | 188 | ### dot clear 189 | 190 | `dotlink`ファイルに記載された**すべての**シンボリックリンクをunlinkする 191 | 192 | ``` 193 | dot clear 194 | ``` 195 | 196 | ### dot clone 197 | 198 | gitコマンドを使ってdotfilesを自分のPCにクローンする 199 | 200 | `-f`または`--force`オプションをつけると確認プロンプトを表示しません。 201 | 202 | ``` 203 | dot clone [-f|--force] [] 204 | ``` 205 | 206 | ## ユースケース 207 | 208 | ### 複数マシン間での設定共有,非共有 209 | 210 | `dotrc.local`や`dotlink.local`をそれぞれのPCに作成し,そこに固有のリンクを記載すれば,マシンそれぞれについてdotfilesをつくる必要はなくなります。 211 | 212 | 共有したい設定はいつでも共有でき,共有したくない設定も,gitで管理しながら独立に扱えます。 213 | 214 | PCを立ち上げて`dot pull`コマンドを実行すれば,すぐに最新の設定環境になります。 215 | 216 | ### 新しいPCのセットアップ 217 | 218 | dotfilesをGitHubなどで管理していて, `dot`を既に使っていれば,以下のように簡単にセットアップが行えます。 219 | 220 | * gitとdotを新PCにインストール 221 | * ターミナルで以下の環境変数を自分のリポジトリにあわせて変更: 222 | ``` 223 | DOT_REPO="https://github.com/username/dotfiles.git" 224 | DOT_DIR="$HOME/.dotfiles" 225 | ``` 226 | * 以下のコマンドを実行: 227 | ``` 228 | dot clone && dot set -v 229 | ``` 230 | 231 | これでdotfilesからクローンしてきて、シンボリックリンクを作成します。 232 | 233 | ### 普段使い 234 | 235 | 新しい設定ファイルをdotfilesに追加したいときは, 236 | 237 | ``` 238 | dot add newfile 239 | ``` 240 | 241 | とすれば良いです。 242 | 243 | こうすると,スクリプト側から: 244 | 245 | ``` 246 | [suggestion] 247 | dot add -m '' newfile /home/username/.dotfiles/newfile 248 | Continue? [y/N]> 249 | ``` 250 | 251 | のように訊かれるので`y`を押して`Enter`キーを押すと,`newfile`が`/home/username/.dotfiles/newfile`に移動され,`newfile`のあった場所にシンボリックリンクが貼られ,この対応関係が`dotlink`に追記されます。 252 | 253 | あとは`git commit`して`git push`するだけです。 254 | (もしDropboxなどを使っていれば,この操作もいりません。) 255 | 256 | 既にdotfilesからリンクが貼られているものをリンク対応表に追記するには, 257 | 258 | ``` 259 | dot add ... 260 | ``` 261 | 262 | とするだけで良いです。 263 | 264 | 265 | ## 設定 266 | 267 | まず,`dot`で管理するdotfilesのリポジトリと,ローカルにおけるディレクトリ名を設定します。 268 | 269 | `~/.zshrc`に以下のように書いてください: 270 | 271 | ``` 272 | export DOT_REPO="https://github.com/username/dotfiles.git" 273 | export DOT_DIR="$HOME/.dotfiles" 274 | ``` 275 | 276 | ### コマンド名を好きな名前に変更する 277 | 278 | "dot"という名前はあまりに一般的すぎて,他のスクリプトやアプリケーションで既に使われているかもしれません。 279 | 280 | もしくは,さらに短いタイプ数で呼び出したいと考えるかもしれません。 281 | 282 | `dot`コマンドに対してaliasを登録することはもちろんできますが, 283 | `dot`という名前を無効にして,他の名前をつけることも可能です。 284 | 285 | `bashrc`や`zshrc`に,以下のように記述してください。 286 | 287 | ``` 288 | export DOT_COMMAND=DOOOOOOOOOOOOT 289 | ``` 290 | 291 | このようにすると,このコマンドは`dot`という名前をもちません。 292 | 293 | (当然本体の関数名である`dot_main`でもスクリプトを実行することができます。) 294 | 295 | ### 設定ファイルの編集 296 | 297 | 設定ファイルは 298 | 299 | ``` 300 | dot config 301 | ``` 302 | 303 | で編集することができ,また設定ファイルが存在しなければ,デフォルトの設定ファイルが`$HOME/.config/dot/dotrc`にコピーされます。 304 | 305 | ### 読み込む設定ファイルを指定する 306 | 307 | オプション`-c, --config`を使えば,指定したファイルを設定ファイルとして読み込んでコマンドを実行できます。 308 | 309 | **使用例** 310 | 311 | * 各アプリケーション毎の設定ファイルを違うリポジトリで管理している場合 312 | * 他の人のdotfilesの一部を引用してくる場合 313 | * など ... 314 | 315 | 具体的に他の人のdotfilesを使用する場合,以下のようなファイルを作成しておきます(このファイル自体を自分のdotfilesリポジトリ内で管理しておくと便利かもしれません)。 316 | 317 | ファイル名: `~/.config/dot/dotrc-someone` 318 | 319 | ```bash 320 | clone_repository=https://github.com/someone/dotfiles.git 321 | dotdir=$HOME/.dotfiles-someone 322 | dotlink=$HOME/.config/dot/dotlink-someone 323 | linkfiles=("$HOME/.config/dot/dotlink-someone") 324 | ``` 325 | 326 | `bashrc`や`zshrc`などに以下のように書いておき,`dot-someone`コマンドを実行すると上に書いた設定ファイルが読み込まれるようにしておくと便利です。 327 | 328 | ```bash 329 | alias dot-someone="dot -c $HOME/.config/dot/dotrc-someone" 330 | ``` 331 | 332 | あとは通常の`dot`コマンドと同じように使うことができます。 333 | 334 | `dot-someone edit`を実行してシンボリックリンクの対応を書き,`dot-someone set`を実行して実際にシンボリックリンクを張ってください。 335 | 336 | `set`コマンドや`pull`コマンドなど,すべての設定ファイルをそれぞれ読み込んで実行したい場合もあると思うので,以下のような関数を用意すると便利かもしれません。 337 | 338 | ```bash 339 | dotconfigs=("file1" "file2" "file3") 340 | 341 | dotall() { 342 | for dotconfig in ${dotconfigs[@]}; do 343 | dot -c "${dotconfig}" "$@" 344 | done 345 | } 346 | 347 | ``` 348 | 349 | zshで補完を有効にするには 350 | 351 | ```zsh 352 | compdef dotall=dot_main 353 | ``` 354 | 355 | の行を追加することを忘れないようにしてください。 356 | 357 | ### dotlinkファイルを編集する 358 | 359 | `dotlink`ファイルは 360 | 361 | ``` 362 | dot edit 363 | ``` 364 | 365 | で編集することができます。 366 | 367 | **設定例** 368 | 369 | `dotlink` 370 | 371 | ``` 372 | 373 | # コメントアウトされた行は無視されます。 374 | 375 | # 空行も同様です。 376 | 377 | # フォーマット: 378 | # , 379 | # 380 | # スクリプトによってホームの位置やdotfilesのパスが補完されるので, 381 | # すべてのパスを記述する必要はありません。 382 | # したがって,以下のように書けます: 383 | myvimrc,.vimrc 384 | 385 | # このようにすると,`$DOT_DIR/myvimrc`から`$HOME/.vimrc`にシンボリックリンクが 386 | # 張られることになります。 387 | 388 | 389 | # "/"で始まる場合には,それはパスとして正しく認識されます。 390 | # また、環境変数も正しく解釈されます。 391 | # これはプライベートな情報を含んだファイルを管理したいときに役立ちます。 392 | # 例えばファイルをdotfilesにアップロードすることなく,以下のようにできます。 393 | $HOME/Dropbox/briefcase/netrc,.netrc 394 | 395 | ``` 396 | 397 | 私の`dotlink`は[ここ](https://github.com/ssh0/dotfiles/blob/master/dotlink)にあるので,ご参考にどうぞ。 398 | 399 | 400 | ### マシン固有の設定ファイル 401 | 402 | 403 | マシン固有の設定をする場合には,`dotrc.local`,`dotlink.local`なども必要に応じてコピーします。 404 | 405 | ``` 406 | cp ~/.zsh/dot/examples/dotrc ~/.config/dot/dotrc.local 407 | ``` 408 | 409 | `dotrc`内で忘れずにsourceしてください。 410 | 411 | ## TODO 412 | 413 | * 他OSでのテスト (いくつかのUbuntu 14.04搭載マシンでテストしただけなので...) 414 | 415 | ## ライセンス 416 | 417 | このプロジェクトは[MIT](./LICENSE)ライセンスで公開します。 418 | 419 | ## 連絡先 420 | 421 | もっと改善できるよとかバグ見つけたとか質問などあればお気軽にご連絡ください。 422 | 423 | * [ssh0(Shotaro Fujimoto) - GitHub](https://github.com/ssh0) 424 | 425 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [日本語](./README_ja.md) 2 | 3 | # dot v1.2.2 4 | 5 | dotfiles management framework with shell (bash, zsh) 6 | 7 | ## Description 8 | 9 | This script makes it easy to manage your dotfiles. 10 | 11 | Script is written in shell script, and very configurable. 12 | 13 | You can use it for multi-machines usage, setup for new machine, daily watering to your dotfiles repository, etc... 14 | 15 | ## Installation 16 | 17 | ### Requirements 18 | 19 | * bash (or zsh) 20 | * git 21 | 22 | ### Install manually 23 | 24 | Clone this repository on your computer and source from your `bashrc` or `zshrc`. 25 | 26 | **COMMAND LINE** 27 | 28 | ``` 29 | git clone https://github.com/ssh0/dot $HOME/.zsh/dot 30 | ``` 31 | 32 | **in {bash,zsh}rc** 33 | 34 | ``` 35 | export DOT_REPO="https://github.com/your_username/dotfiles.git" 36 | export DOT_DIR="$HOME/.dotfiles" 37 | fpath=($HOME/.zsh/dot $fpath) # <- for completion 38 | source $HOME/.zsh/dot/dot.sh 39 | ``` 40 | 41 | Reload shellrc and try: 42 | 43 | ``` 44 | dot --help-all 45 | ``` 46 | 47 | then, man page will open. 48 | 49 | ### With plugin manager 50 | 51 | If you use some zsh plugin manager (ex. [zplug](https://github.com/b4b4r07/zplug), 52 | [zgen](https://github.com/tarjoilija/zgen), etc.), load from `zshrc` like: 53 | 54 | ``` 55 | zplug "ssh0/dot", use:"*.sh" 56 | ``` 57 | 58 | ``` 59 | zgen load ssh0/dot 60 | ``` 61 | 62 | And write below line in {bash,zsh}rc 63 | 64 | ``` 65 | export DOT_REPO="https://github.com/your_username/dotfiles.git" 66 | export DOT_DIR="$HOME/.dotfiles" 67 | ``` 68 | 69 | ## Usage 70 | 71 | Configuration file is in '[dotrc](./examples/dotrc)'. 72 | Link relation table is in '[dotlink](./examples/dotlink)'. 73 | 74 | **subcommand** 75 | 76 | | subcommand | description | option or arguments | 77 | | --- | --- | --- | 78 | | [pull](#dot_pull) | Pull from dotfile repository (by git) | `[--self]` | 79 | | [list](#dot_list) | Show the list which files will be managed by dot. | | 80 | | [check](#dot_check) | Check the files are correctly linked to the right places. | | 81 | | [cd](#dot_cd) | Change directory to 'dotdir'. | | 82 | | [set](#dot_set) | Set symbolic links configured in `dotlink`. | `[-i\|--ignore][-f\|--force][-b\|--backup][-v\|--verbose]` | 83 | | [update](#dot_update) | Combined command of 'pull' and 'set' commands. | `[-i\|--ignore][-f\|--force][-b\|--backup][-v\|--verbose]` | 84 | | [add](#dot_add) | Move the new file to the dotfile dir, make the link, and add the link information to `dotlink` automatically. | `some_file [$DOT_DIR/path/to/the/file]` or `link1 [link2 link3 ... ]` | 85 | | [edit](#dot_edit) | Edit `dotlink` | | 86 | | [config](#dot_config) | Edit configuration file 'dotrc' | | 87 | | [unlink](#dot_unlink) | Unlink the selected symbolic links and copy its original files from the dotfile directory. | `link1 [link2 link3 ... ]` | 88 | | [clear](#dot_clear) | Remove the *all* symbolic link written in the dotlink file `dotlink`. | | 89 | | [clone](#dot_clone) | Clone dotfile repository on your computer with git. | `[-f\|--force] [/directory/to/clone/]` | 90 | 91 | **option** 92 | 93 | |option |description |arguments| 94 | |--- |--- |--- | 95 | | -h, --help |Show help message. | | 96 | | -c, --config|Specify the configuration file to load.| `dotrc` | 97 | 98 | ### dot pull 99 | 100 | Pull from remote dotfile repository (by git) 101 | 102 | ![dot pull](./img/dot_pull.png) 103 | 104 | With `--self` option, then git pull for `dot` and it will be up to date. 105 | 106 | ``` 107 | dot pull --self 108 | ``` 109 | 110 | ### dot list 111 | 112 | ![dot list](./img/dot_list.png) 113 | 114 | Show the list which files be managed by dot. 115 | 116 | ### dot check 117 | 118 | Check the files are correctly linked to the right places. 119 | 120 | ![dot check](./img/dot_check.png) 121 | 122 | * "✘" means this file is not managed by dot now but is written in `dotlink`. 123 | * "✔" means this file is managed by dot now. 124 | 125 | ### dot cd 126 | 127 | ![dot cd](./img/dot_cd.png) 128 | 129 | Change directory to `dotdir`. 130 | 131 | ### dot set 132 | 133 | Set symbolic links configured in `dotlink`. 134 | 135 | If you have your file already, you can choose the operation interactively: 136 | 137 | * show diff 138 | * edit file 139 | * replace 140 | * replace and make backup 141 | * do nothing 142 | 143 | With option `-i` or `--ignore`, this script ignores conflict files and links. 144 | 145 | With option `-f` or `--force`, this script ignores all conflicts and force make symbolic links. 146 | 147 | With option `-b` or `--backup`, this script ignores all conflicts and force make symbolic links but make it original backup named `file.bak`. 148 | 149 | With `-v` or `--verbose`, this script shows verbose messages. 150 | 151 | ![dot set](./img/dot_set.png) 152 | 153 | ### dot update 154 | 155 | Combined command of 'pull' and 'set' commands. 156 | 157 | Same option of `set` command. 158 | 159 | ### dot add 160 | 161 | Move the new file to the dotfile dir, make the link, and add the link information to `dotlink` automatically. 162 | 163 | ![dot add](./img/dot_add.png) 164 | 165 | ### dot edit 166 | 167 | Edit `dotlink` 168 | 169 | ``` 170 | dot edit 171 | ``` 172 | 173 | ### dot config 174 | 175 | Edit configuration file 'dotrc' 176 | 177 | ``` 178 | dot config 179 | ``` 180 | 181 | ### dot unlink 182 | 183 | Unlink the selected symbolic links and copy its original files from the dotfile directory. 184 | 185 | ![dot unlink](./img/dot_unlink.png) 186 | 187 | ### dot clear 188 | 189 | Remove the *all* symbolic link written in the dotlink file `dotlink`. 190 | 191 | ``` 192 | dot clear 193 | ``` 194 | 195 | ### dot clone 196 | 197 | Clone dotfile repository on your computer with git. 198 | 199 | With option `-f` or `--force`, never prompt. 200 | 201 | ``` 202 | dot clone [-f|--force] [] 203 | ``` 204 | 205 | ## Use case 206 | 207 | ### Multi-machine configuration 208 | 209 | You can add `dotrc.local` and `dotlink.local` on each computers and don't have to divide dotfiles repository. 210 | 211 | Share or don't share the configuration what you want. 212 | 213 | `dot update` provides you fresh dotfiles anywhere. 214 | 215 | ### New machine setup 216 | 217 | If you have your own dotfiles already and managed with `dot`, just: 218 | 219 | * Install git and dot. 220 | * Set environment variables in your terminal: 221 | ``` 222 | DOT_REPO="https://github.com/username/dotfiles.git" 223 | DOT_DIR="$HOME/.dotfiles" 224 | ``` 225 | * And just run 226 | ``` 227 | dot clone && dot set 228 | ``` 229 | 230 | ### For daily use 231 | 232 | If you want to add your new configuration file to your dotfiles repository, just run 233 | 234 | ``` 235 | dot add newfile 236 | ``` 237 | 238 | Then the script asks you like: 239 | 240 | ``` 241 | [suggestion] 242 | dot add -m '' newfile /home/username/.dotfiles/newfile 243 | Continue? [y/N]> 244 | ``` 245 | 246 | Type `y` and `Enter`, then move `newfile` to `/home/username/.dotfiles/newfile` 247 | and make symbolic link to `newfile` and this link information is written in `dotlink`. 248 | 249 | Other things you should do is `git commit` and `git push` to your repository. 250 | (Or if you use Dropbox or so, you can skip these steps.) 251 | 252 | In order to add link-relation-table already exists, just 253 | 254 | ``` 255 | dot add ... 256 | ``` 257 | 258 | ## Configuration 259 | 260 | First, you should set the dotfiles repository to manage and the dotfiles directory. 261 | 262 | In `~/.zshrc`, 263 | 264 | ``` 265 | export DOT_REPO="https://github.com/username/dotfiles.git" 266 | export DOT_DIR="$HOME/.dotfiles" 267 | ``` 268 | 269 | ### Change the command name 270 | 271 | The name "dot" is too common and may be used in other script or application. 272 | 273 | Or, you may want to change it more short name. 274 | 275 | You can set the alias for `dot` of cource, but you can also disable the name `dot` for this script and give a different name you want by writting like below in your `bashrc` or `zshrc`: 276 | 277 | ``` 278 | export DOT_COMMAND=DOOOOOOOOOOOOT 279 | ``` 280 | 281 | then the command `dot` is no longer the name of this script. 282 | 283 | (You can call the main function by `dot_main` of cource.) 284 | 285 | ### Edit your configuratoin file 286 | 287 | ``` 288 | dot config 289 | ``` 290 | 291 | will edit `$HOME/.config/dot/dotrc`(if it doesn't exist, copy the template one). 292 | 293 | ### Specify the configuration file to load 294 | 295 | With `-c, --config` option, you can execute dot command specifing the configuration file to load. 296 | 297 | **Usage example** 298 | 299 | * If you divide some configuration files for each application to different repositories 300 | * If you borrow from other people's dotfiles 301 | * etc. 302 | 303 | If you want to borrow other person's dotfiles repository, create a configuration file like below. 304 | (It is useful that this file will be managed in *your* dotfiles.) 305 | 306 | filename: `~/.config/dot/dotrc-someone` 307 | 308 | ```bash 309 | clone_repository=https://github.com/someone/dotfiles.git 310 | dotdir=$HOME/.dotfiles-someone 311 | dotlink=$HOME/.config/dot/dotlink-someone 312 | linkfiles=("$HOME/.config/dot/dotlink-someone") 313 | ``` 314 | 315 | It is useful to define a function in your `bashrc` or `zshrc` like below in order to run the `dot` command with loading the config file above. 316 | 317 | ```bash 318 | alias dot-someone="dot -c $HOME/.config/dot/dotrc-someone" 319 | ``` 320 | 321 | Then, you can use `dot-someone` command in the same way. 322 | 323 | Run `dot-someone edit` to write the link relations and execute `dot-someone set` to deploy symbolic links. 324 | 325 | It's also helpful that you define a function to run `dot` command loading each dot-config files (especially `set` command or `pull`) like below. 326 | 327 | In your `bashrc` or `zshrc`: 328 | 329 | ```bash 330 | dotconfigs=("file1" "file2" "file3") 331 | 332 | dotall() { 333 | for dotconfig in ${dotconfigs[@]}; do 334 | dot -c "${dotconfig}" "$@" 335 | done 336 | } 337 | 338 | ``` 339 | 340 | In Zsh, to enable completion add the line: 341 | 342 | ```zsh 343 | compdef dotall=dot_main 344 | ``` 345 | 346 | ### Edit your dotlink manually 347 | 348 | ``` 349 | dot edit 350 | ``` 351 | 352 | will open `dotlink` and you can edit this file manually. 353 | 354 | **EXAMPLE** 355 | 356 | `dotlink` 357 | 358 | ``` 359 | 360 | # script ignore commented out line 361 | 362 | # and empty line 363 | 364 | # Format: 365 | # , 366 | # 367 | # the script automatically add root directory to the file path. 368 | # So, you should write like below: 369 | myvimrc,.vimrc 370 | 371 | # Then the script will make the symbolic link from `$DOT_DIR/myvimrc` to `$HOME/.vimrc`. 372 | 373 | # The path start from slash "/" is correctly understood by the script. 374 | # And you can use environment variables in it. 375 | # It is useful when the file contains some private information and 376 | # you wouldn't upload it to your dotfiles repository. 377 | $HOME/Dropbox/briefcase/netrc,.netrc 378 | 379 | ``` 380 | 381 | My `dotlink` is [in my dotfiles repository](https://github.com/ssh0/dotfiles/blob/master/dotlink). 382 | 383 | ### [optional] Copy local settings 384 | 385 | ``` 386 | cp ~/.zsh/dot/examples/dotrc ~/.config/dot/dotrc.local 387 | ``` 388 | 389 | and source this file from your configuration file `dotrc`: 390 | 391 | ``` 392 | dotbundle "$HOME/.config/dot/dotrc.local" 393 | ``` 394 | 395 | ## TODO 396 | 397 | * test in other OS (I use some Ubuntu 14.04 machines and only tested in there) 398 | 399 | ## LICENSE 400 | 401 | This project is under [MIT](./LICENSE) license. 402 | 403 | ## Contact 404 | 405 | If you improve this project, find bugs or have a question, feel free to contact me. 406 | 407 | * [ssh0(Shotaro Fujimoto) - GitHub](https://github.com/ssh0) 408 | 409 | --------------------------------------------------------------------------------