dotfiles script v0.4.4
- link: check if file already exists and is equal, replace file with link if wanted - install: improve checks for .bash_completion scripts
This commit is contained in:
parent
31ceba56dc
commit
4cc7c408fd
37
bin/dotfiles
37
bin/dotfiles
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
##
|
##
|
||||||
## binaryDiv's dotfiles management script
|
## binaryDiv's dotfiles management script
|
||||||
## Version 0.4.3
|
## Version 0.4.4
|
||||||
##
|
##
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|
@ -78,18 +78,20 @@ case "$cmd" in
|
||||||
|
|
||||||
# Enable user-defined bash completion per directory
|
# Enable user-defined bash completion per directory
|
||||||
bashcompletion_filename=.bash_completion
|
bashcompletion_filename=.bash_completion
|
||||||
if [[ ! -e "$homedir/$bashcompletion_filename" ]]; then
|
if [[ ! -e "$homedir/$bashcompletion_filename" ]] ||
|
||||||
|
[[ ! "$(realpath "$homedir/$bashcompletion_filename")" -ef "$dotfilesdir/$bashcompletion_filename" ]];
|
||||||
|
then
|
||||||
echo "* Installing user-defined bash completion (~/.bash_completion.d/)"
|
echo "* Installing user-defined bash completion (~/.bash_completion.d/)"
|
||||||
"$0" link -q "$bashcompletion_filename" &&
|
"$0" link -q "$bashcompletion_filename" &&
|
||||||
show_bash_restart_info=1
|
show_bash_restart_info=1
|
||||||
elif [[ ! "$(realpath "$homedir/$bashcompletion_filename")" -ef "$dotfilesdir/$bashcompletion_filename" ]]; then
|
|
||||||
echo "! Warning: File $homedir/$bashcompletion_filename already exists but is NOT a link to $dotfilesdir/$bashcompletion_filename"
|
|
||||||
fi
|
fi
|
||||||
mkdir -p "$homedir/.bash_completion.d"
|
mkdir -p "$homedir/.bash_completion.d"
|
||||||
|
|
||||||
# Activate dotfiles bash completion
|
# Activate dotfiles bash completion
|
||||||
bashcompletion_dotfiles_filename=.bash_completion.d/10-dotfiles.sh
|
bashcompletion_dotfiles_filename=.bash_completion.d/10-dotfiles.sh
|
||||||
if [[ ! -e "$homedir/$bashcompletion_dotfiles_filename" ]]; then
|
if [[ ! -e "$homedir/$bashcompletion_dotfiles_filename" ]] ||
|
||||||
|
[[ ! "$(realpath "$homedir/$bashcompletion_dotfiles_filename")" -ef "$dotfilesdir/$bashcompletion_dotfiles_filename" ]];
|
||||||
|
then
|
||||||
echo "* Installing bash completion for dotfiles script"
|
echo "* Installing bash completion for dotfiles script"
|
||||||
"$0" link -q "$bashcompletion_dotfiles_filename" &&
|
"$0" link -q "$bashcompletion_dotfiles_filename" &&
|
||||||
show_bash_restart_info=1
|
show_bash_restart_info=1
|
||||||
|
|
@ -190,15 +192,30 @@ case "$cmd" in
|
||||||
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
|
fi
|
||||||
if [[ ! "$(realpath "$file_home")" -ef "$file_dotfiles" ]]; then
|
|
||||||
|
if [[ -e $file_home ]]; then
|
||||||
|
if [[ "$(realpath "$file_home")" -ef "$file_dotfiles" ]]; then
|
||||||
|
# Target is already a link to the correct file
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if cmp --silent "$file_home" "$file_dotfiles"; then
|
||||||
|
echo "! $file_home already exists and is equal to $file_dotfiles"
|
||||||
|
read -p " Delete $file_home and create link? [y/N] " -r
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
# Don't delete file
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
rm "$file_home" || exit 1
|
||||||
|
else
|
||||||
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
|
|
||||||
[[ $QUIET ]] || echo "* Creating link $file_home -> $file_dotfiles"
|
|
||||||
ln -sr "$file_dotfiles" "$file_home" || exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[[ $QUIET ]] || echo "* Creating link $file_home -> $file_dotfiles"
|
||||||
|
ln -sr "$file_dotfiles" "$file_home" || exit 1
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue