dotfiles script v0.5.0
- add support for host-specific 'local' files in _local/HOSTNAME/ - works with: linkstatus, link, createfrom, ls
This commit is contained in:
parent
14104fc3ac
commit
154d8ea25e
68
bin/dotfiles
68
bin/dotfiles
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
##
|
##
|
||||||
## binaryDiv's dotfiles management script
|
## binaryDiv's dotfiles management script
|
||||||
## Version 0.4.5
|
## Version 0.5.0
|
||||||
##
|
##
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|
@ -19,14 +19,18 @@ usage() {
|
||||||
|
|
||||||
Dotfile management:
|
Dotfile management:
|
||||||
ls [DIR] list contents of .dotfiles directory (or DIR relative to it)
|
ls [DIR] list contents of .dotfiles directory (or DIR relative to it)
|
||||||
|
(-l: list host-specific files, i.e. ~/.dotfiles/_local/HOSTNAME/DIR)
|
||||||
edit FILE open ~/.dotfiles/FILE in vim
|
edit FILE open ~/.dotfiles/FILE in vim
|
||||||
diff FILE use vimdiff to compare ~/FILE to ~/.dotfiles/FILE
|
diff FILE use vimdiff to compare ~/FILE to ~/.dotfiles/FILE
|
||||||
link FILE... create a symlink from ~/FILE to ~/.dotfiles/FILE (multiple files possible)
|
link FILE... create a symlink from ~/FILE to ~/.dotfiles/FILE (multiple files possible)
|
||||||
(-q: be quiet, only print something if an error occurs)
|
(-q: be quiet, only print something if an error occurs)
|
||||||
|
(-l: link host-specific files, i.e. ~/FILE to ~/.dotfiles/_local/HOSTNAME/FILE)
|
||||||
linkstatus [DIR] list contents of .dotfiles with information about whether there are links to
|
linkstatus [DIR] list contents of .dotfiles with information about whether there are links to
|
||||||
them in ~/, whether they differ, etc...
|
them in ~/, whether they differ, etc...
|
||||||
|
(-l: show linkstatus only for host-specific files, i.e. ~/.dotfiles/_local/HOSTNAME)
|
||||||
createfrom FILE... copy ~/FILE to ~/.dotfiles/FILE and symlink the file
|
createfrom FILE... copy ~/FILE to ~/.dotfiles/FILE and symlink the file
|
||||||
(-n: only copy, leave the original, do not create symlink)
|
(-n: only copy, leave the original, do not create symlink)
|
||||||
|
(-l: create host-specific files, i.e. ~/FILE to ~/.dotfiles/_local/HOSTNAME/FILE)
|
||||||
|
|
||||||
Synchronization:
|
Synchronization:
|
||||||
git ARGS... wrapper for git (all arguments are passed on to git)
|
git ARGS... wrapper for git (all arguments are passed on to git)
|
||||||
|
|
@ -45,6 +49,9 @@ fi
|
||||||
homedir="$DOTFILESROOT"
|
homedir="$DOTFILESROOT"
|
||||||
dotfilesdir="$DOTFILESROOT/.dotfiles"
|
dotfilesdir="$DOTFILESROOT/.dotfiles"
|
||||||
|
|
||||||
|
dotfiles_local_base="_local"
|
||||||
|
dotfiles_local_prefix="$dotfiles_local_base/$(hostname)"
|
||||||
|
|
||||||
|
|
||||||
# Get command
|
# Get command
|
||||||
[[ $# -gt 0 ]] || { usage; exit 1; }
|
[[ $# -gt 0 ]] || { usage; exit 1; }
|
||||||
|
|
@ -108,6 +115,7 @@ case "$cmd" in
|
||||||
|
|
||||||
ls)
|
ls)
|
||||||
lsdir="$dotfilesdir"
|
lsdir="$dotfilesdir"
|
||||||
|
[[ $1 = "-l" ]] && { lsdir="$lsdir/$dotfiles_local_prefix"; shift; }
|
||||||
[[ -n $1 ]] && lsdir="$lsdir/$1"
|
[[ -n $1 ]] && lsdir="$lsdir/$1"
|
||||||
|
|
||||||
echo "$lsdir:"
|
echo "$lsdir:"
|
||||||
|
|
@ -115,15 +123,20 @@ case "$cmd" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
linkstatus)
|
linkstatus)
|
||||||
subdir=""
|
cd "$dotfilesdir"
|
||||||
if [[ -n $1 ]]; then
|
|
||||||
subdir="${1%/}"
|
subdir="$1"
|
||||||
|
[[ $subdir = "-l" ]] && { subdir="$dotfiles_local_prefix/$1"; shift; }
|
||||||
|
|
||||||
|
if [[ -n $subdir ]]; then
|
||||||
|
subdir="${subdir%/}"
|
||||||
|
[[ $subdir = $dotfiles_local_base ]] && subdir=$dotfiles_local_prefix
|
||||||
|
|
||||||
[[ -e $subdir ]] || { echo "$dotfilesdir/$subdir does not exist"; exit 1; }
|
[[ -e $subdir ]] || { echo "$dotfilesdir/$subdir does not exist"; exit 1; }
|
||||||
[[ -d $subdir ]] && subdir="$subdir/"
|
[[ -d $subdir ]] && subdir="$subdir/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shopt -s nullglob dotglob
|
shopt -s nullglob dotglob
|
||||||
cd $dotfilesdir
|
|
||||||
dotdirs=()
|
dotdirs=()
|
||||||
|
|
||||||
for file in $subdir*; do
|
for file in $subdir*; do
|
||||||
|
|
@ -133,6 +146,10 @@ case "$cmd" in
|
||||||
file_home="$homedir/$file"
|
file_home="$homedir/$file"
|
||||||
file_dotfiles="$dotfilesdir/$file"
|
file_dotfiles="$dotfilesdir/$file"
|
||||||
|
|
||||||
|
if [[ $subdir == $dotfiles_local_base/* ]]; then
|
||||||
|
file_home="$homedir/${file#$dotfiles_local_prefix/}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -e $file_home ]]; then
|
if [[ -e $file_home ]]; then
|
||||||
if [[ "$(realpath "$file_home")" -ef "$file_dotfiles" ]]; then
|
if [[ "$(realpath "$file_home")" -ef "$file_dotfiles" ]]; then
|
||||||
file_status=" LINKED "
|
file_status=" LINKED "
|
||||||
|
|
@ -144,6 +161,9 @@ case "$cmd" in
|
||||||
else
|
else
|
||||||
file_status="<> DIFFERS "
|
file_status="<> DIFFERS "
|
||||||
fi
|
fi
|
||||||
|
elif [[ $file = $dotfiles_local_base ]]; then
|
||||||
|
dotdirs=("$dotfiles_local_prefix" "${dotdirs[@]}")
|
||||||
|
continue
|
||||||
else
|
else
|
||||||
if [[ -d $file_dotfiles ]]; then
|
if [[ -d $file_dotfiles ]]; then
|
||||||
file_status="++ NEW DIR "
|
file_status="++ NEW DIR "
|
||||||
|
|
@ -184,10 +204,17 @@ case "$cmd" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
link)
|
link)
|
||||||
if [[ $1 = '-q' ]]; then
|
while getopts ":ql" opt; do
|
||||||
QUIET=1
|
case $opt in
|
||||||
shift
|
q) QUIET=1 ;;
|
||||||
fi
|
l) link_local=1 ;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: -$OPTARG"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
||||||
|
|
||||||
|
|
@ -195,6 +222,10 @@ case "$cmd" in
|
||||||
file_home="$homedir/$filename"
|
file_home="$homedir/$filename"
|
||||||
file_dotfiles="$dotfilesdir/$filename"
|
file_dotfiles="$dotfilesdir/$filename"
|
||||||
|
|
||||||
|
if [[ $link_local ]]; then
|
||||||
|
file_dotfiles="$dotfilesdir/$dotfiles_local_prefix/$filename"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -e $file_dotfiles ]]; then
|
if [[ ! -e $file_dotfiles ]]; then
|
||||||
echo "! $file_dotfiles: target file does not exist"
|
echo "! $file_dotfiles: target file does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -226,10 +257,17 @@ case "$cmd" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
createfrom)
|
createfrom)
|
||||||
if [[ $1 = '-n' ]]; then
|
while getopts ":nl" opt; do
|
||||||
NOLINK=1
|
case $opt in
|
||||||
shift
|
n) NOLINK=1 ;;
|
||||||
fi
|
l) create_local=1 ;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: -$OPTARG"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
||||||
|
|
||||||
|
|
@ -237,6 +275,10 @@ case "$cmd" in
|
||||||
file_home="$homedir/$filename"
|
file_home="$homedir/$filename"
|
||||||
file_dotfiles="$dotfilesdir/$filename"
|
file_dotfiles="$dotfilesdir/$filename"
|
||||||
|
|
||||||
|
if [[ $create_local ]]; then
|
||||||
|
file_dotfiles="$dotfilesdir/$dotfiles_local_prefix/$filename"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -e $file_home ]]; then
|
if [[ ! -e $file_home ]]; then
|
||||||
echo "! $file_home: source file does not exist"
|
echo "! $file_home: source file does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue