dotfiles script v0.4.0

- add 'linkstatus' command
This commit is contained in:
Lexi / Zoe 2019-01-05 05:31:56 +01:00
parent 3bf320f5eb
commit 2b05ae3f30
Signed by: binaryDiv
GPG Key ID: F8D4956E224DA232
1 changed files with 60 additions and 8 deletions

View File

@ -2,7 +2,7 @@
## ##
## binaryDiv's dotfiles management script ## binaryDiv's dotfiles management script
## Version 0.3.1 ## Version 0.4.0
## ##
usage() { usage() {
@ -18,10 +18,12 @@ usage() {
(this will NOT create links for all dotfiles, though) (this will NOT create links for all dotfiles, though)
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)
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)
linkstatus [DIR] list contents of .dotfiles with information about whether there are links to
them in ~/, whether they differ, etc...
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)
@ -89,7 +91,57 @@ case "$cmd" in
ls -lAh --color=auto "$lsdir" ls -lAh --color=auto "$lsdir"
;; ;;
# TODO: Command 'status' or 'linkstatus' to show which files are linked and which are not linkstatus)
subdir=""
if [[ -n $1 ]]; then
subdir="${1%/}"
[[ -e $subdir ]] || { echo "$dotfilesdir/$subdir does not exist"; exit 1; }
[[ -d $subdir ]] && subdir="$subdir/"
fi
shopt -s nullglob dotglob
cd $dotfilesdir
dotdirs=()
for file in $subdir*; do
[[ -e $file ]] || continue
[[ $file = ".git" ]] && continue
file_home="$homedir/$file"
file_dotfiles="$dotfilesdir/$file"
if [[ -e $file_home ]]; then
if [[ "$(realpath "$file_home")" -ef "$file_dotfiles" ]]; then
file_status=" LINKED "
elif [[ -d $file_home ]]; then
dotdirs+=($file)
continue
elif [[ -f $file_home ]] && cmp --silent "$file_home" "$file_dotfiles"; then
file_status="== EQUAL "
else
file_status="<> DIFFERS "
fi
else
if [[ -d $file_dotfiles ]]; then
file_status="++ NEW DIR "
else
file_status="++ NEW FILE"
fi
fi
[[ -d $file_dotfiles ]] && file="$file/"
echo "$file_status $file"
done
if [[ $dotdirs ]]; then
echo
for dir in ${dotdirs[@]}; do
echo "[$dir]"
dotfiles linkstatus "$dir" | grep '\(LINKED\|EQUAL\|DIFFERS\|NEW\)'
echo
done
fi
;;
diff) diff)
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; } [[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
@ -148,7 +200,7 @@ case "$cmd" in
_dotfiles() { _dotfiles() {
COMPREPLY=() COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
local commands="help install ls diff link git pull" local commands="help install ls diff link linkstatus git pull"
local gitcommands="add commit diff fetch log pull push rebase status" local gitcommands="add commit diff fetch log pull push rebase status"
if [[ $COMP_CWORD -eq 1 ]]; then if [[ $COMP_CWORD -eq 1 ]]; then
@ -159,7 +211,7 @@ case "$cmd" in
[[ $COMP_CWORD -eq 2 ]] && _dotfiles_filenames [[ $COMP_CWORD -eq 2 ]] && _dotfiles_filenames
;; ;;
link) link|linkstatus)
_dotfiles_filenames _dotfiles_filenames
;; ;;