From 2d5e8bbce27aac841c6bccd99040967c165af207 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sun, 6 Oct 2019 20:18:50 +0200 Subject: [PATCH] dotfiles script v0.5.1 - diff, edit: add support for host-specific files - bash-completion: add support for host-specific files --- bin/dotfiles | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bin/dotfiles b/bin/dotfiles index 89ddad7..f44e757 100755 --- a/bin/dotfiles +++ b/bin/dotfiles @@ -2,7 +2,7 @@ ## ## binaryDiv's dotfiles management script -## Version 0.5.0 +## Version 0.5.1 ## usage() { @@ -21,7 +21,9 @@ usage() { 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 + (-l: open host-specific files, i.e. ~/.dotfiles/_local/HOSTNAME/DIR) diff FILE use vimdiff to compare ~/FILE to ~/.dotfiles/FILE + (-l: compare host-specific files, i.e. ~/.dotfiles/_local/HOSTNAME/DIR) link FILE... create a symlink from ~/FILE to ~/.dotfiles/FILE (multiple files possible) (-q: be quiet, only print something if an error occurs) (-l: link host-specific files, i.e. ~/FILE to ~/.dotfiles/_local/HOSTNAME/FILE) @@ -187,14 +189,18 @@ case "$cmd" in ;; edit) + basedir=$dotfilesdir + [[ $1 = "-l" ]] && { basedir="$basedir/$dotfiles_local_prefix"; shift; } [[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; } - vim "$dotfilesdir/$1" + vim "$basedir/$1" ;; diff) + basedir=$dotfilesdir + [[ $1 = "-l" ]] && { basedir="$basedir/$dotfiles_local_prefix"; shift; } [[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; } file_A="$homedir/$1" - file_B="$dotfilesdir/$1" + file_B="$basedir/$1" if [[ "$(realpath "$file_A")" -ef "$file_B" ]]; then echo "$file_A is a link to $file_B" @@ -313,6 +319,12 @@ case "$cmd" in files=($(compgen -f -X '*/@(.|..|.git)' .dotfiles/$cur)) COMPREPLY=(${files[@]#.dotfiles/}) } + _dotfiles_filenames_local() { + compopt -o filenames + dotfiles_prefix=.dotfiles/_local/$(hostname) + files=($(compgen -f -X '*/@(.|..|.git)' $dotfiles_prefix/$cur)) + COMPREPLY=(${files[@]#$dotfiles_prefix/}) + } _dotfiles() { COMPREPLY=() local cur="${COMP_WORDS[COMP_CWORD]}" @@ -328,7 +340,11 @@ case "$cmd" in ;; link|linkstatus) - _dotfiles_filenames + if [[ $COMP_CWORD -gt 2 && ${COMP_WORDS[2]} = "-l" ]]; then + _dotfiles_filenames_local + else + _dotfiles_filenames + fi ;; createfrom)