dotfiles script v0.3.1
- link .bash_completion on 'install' - add option -q to 'link' - modernize bash tests, use [[ ]] instead of [ ]
This commit is contained in:
parent
885c75654f
commit
3bf320f5eb
43
bin/dotfiles
43
bin/dotfiles
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
##
|
##
|
||||||
## binaryDiv's dotfiles management script
|
## binaryDiv's dotfiles management script
|
||||||
## Version 0.3.0
|
## Version 0.3.1
|
||||||
##
|
##
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|
@ -21,6 +21,7 @@ usage() {
|
||||||
ls [DIR] list contents of .dotfiles directory (or DIR relative to it)
|
ls [DIR] list contents of .dotfiles directory (or DIR relative to it)
|
||||||
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)
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -31,7 +32,7 @@ usage() {
|
||||||
|
|
||||||
# Define root dir for dotfiles management (defaults to $HOME, can be overridden
|
# Define root dir for dotfiles management (defaults to $HOME, can be overridden
|
||||||
# with environment variables for debugging)
|
# with environment variables for debugging)
|
||||||
if [ -z "$DOTFILESROOT" ]; then
|
if [[ -z $DOTFILESROOT ]]; then
|
||||||
DOTFILESROOT="$HOME"
|
DOTFILESROOT="$HOME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@ dotfilesdir="$DOTFILESROOT/.dotfiles"
|
||||||
|
|
||||||
|
|
||||||
# Get command
|
# Get command
|
||||||
[ $# -gt 0 ] || { usage; exit 1; }
|
[[ $# -gt 0 ]] || { usage; exit 1; }
|
||||||
cmd=$1
|
cmd=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
|
@ -57,11 +58,11 @@ case "$cmd" in
|
||||||
bin_target="$homedir/bin/dotfiles"
|
bin_target="$homedir/bin/dotfiles"
|
||||||
bin_dir="$homedir/bin"
|
bin_dir="$homedir/bin"
|
||||||
|
|
||||||
if [ ! -e "$bin_target" ]; then
|
if [[ ! -e $bin_target ]]; then
|
||||||
echo "* Installing dotfiles script in $bin_dir/..."
|
echo "* Installing dotfiles script in $bin_dir/"
|
||||||
mkdir -pv "$bin_dir"
|
mkdir -pv "$bin_dir"
|
||||||
ln -sr "$bin_source" "$bin_target" || exit 1
|
ln -sr "$bin_source" "$bin_target" || exit 1
|
||||||
elif [ ! "$(realpath $bin_target)" -ef "$bin_source" ]; then
|
elif [[ ! "$(realpath $bin_target)" -ef "$bin_source" ]]; then
|
||||||
echo "! Warning: File $bin_target already exists but is NOT a link to $bin_source"
|
echo "! Warning: File $bin_target already exists but is NOT a link to $bin_source"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -69,13 +70,20 @@ case "$cmd" in
|
||||||
echo "! Warning: $bin_dir is not in your PATH."
|
echo "! Warning: $bin_dir is not in your PATH."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "* Configuring git settings..."
|
# Activate bash completion
|
||||||
|
if [[ ! -e "$homedir/.bash_completion" ]]; then
|
||||||
|
echo "* Installing user-defined bash completion"
|
||||||
|
"$0" link -q .bash_completion &&
|
||||||
|
echo " Restart bash or run 'source $homedir/.bash_completion' to activate it now"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "* Configuring git settings"
|
||||||
git -C "$dotfilesdir" config merge.ff only
|
git -C "$dotfilesdir" config merge.ff only
|
||||||
;;
|
;;
|
||||||
|
|
||||||
ls)
|
ls)
|
||||||
lsdir="$dotfilesdir"
|
lsdir="$dotfilesdir"
|
||||||
[ -n "$1" ] && lsdir="$lsdir/$1"
|
[[ -n $1 ]] && lsdir="$lsdir/$1"
|
||||||
|
|
||||||
echo "$lsdir:"
|
echo "$lsdir:"
|
||||||
ls -lAh --color=auto "$lsdir"
|
ls -lAh --color=auto "$lsdir"
|
||||||
|
|
@ -84,11 +92,11 @@ case "$cmd" in
|
||||||
# TODO: Command 'status' or 'linkstatus' to show which files are linked and which are not
|
# TODO: Command 'status' or 'linkstatus' to show which files are linked and which are not
|
||||||
|
|
||||||
diff)
|
diff)
|
||||||
[ -n "$1" ] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
||||||
file_A="$homedir/$1"
|
file_A="$homedir/$1"
|
||||||
file_B="$dotfilesdir/$1"
|
file_B="$dotfilesdir/$1"
|
||||||
|
|
||||||
if [ "$(realpath "$file_A")" -ef "$file_B" ]; then
|
if [[ "$(realpath "$file_A")" -ef "$file_B" ]]; then
|
||||||
echo "$file_A is a link to $file_B"
|
echo "$file_A is a link to $file_B"
|
||||||
else
|
else
|
||||||
vimdiff "$file_A" "$file_B"
|
vimdiff "$file_A" "$file_B"
|
||||||
|
|
@ -96,22 +104,27 @@ case "$cmd" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
link)
|
link)
|
||||||
[ -n "$1" ] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
if [[ $1 = '-q' ]]; then
|
||||||
|
QUIET=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
||||||
|
|
||||||
for filename in "$@"; do
|
for filename in "$@"; do
|
||||||
file_home="$homedir/$filename"
|
file_home="$homedir/$filename"
|
||||||
file_dotfiles="$dotfilesdir/$filename"
|
file_dotfiles="$dotfilesdir/$filename"
|
||||||
|
|
||||||
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
|
||||||
elif [ -e "$file_home" ]; then
|
elif [[ -e $file_home ]]; then
|
||||||
if [ ! "$(realpath "$file_home")" -ef "$file_dotfiles" ]; then
|
if [[ ! "$(realpath "$file_home")" -ef "$file_dotfiles" ]]; then
|
||||||
echo "! $file_home already exists but is NOT a link to $file_dotfiles, please fix manually"
|
echo "! $file_home already exists but is NOT a link to $file_dotfiles, please fix manually"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "* Creating link $file_home -> $file_dotfiles"
|
[[ $QUIET ]] || echo "* Creating link $file_home -> $file_dotfiles"
|
||||||
ln -sr "$file_dotfiles" "$file_home" || exit 1
|
ln -sr "$file_dotfiles" "$file_home" || exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue