dotfiles script v0.5.1
- diff, edit: add support for host-specific files - bash-completion: add support for host-specific files
This commit is contained in:
parent
154d8ea25e
commit
2d5e8bbce2
24
bin/dotfiles
24
bin/dotfiles
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
##
|
##
|
||||||
## binaryDiv's dotfiles management script
|
## binaryDiv's dotfiles management script
|
||||||
## Version 0.5.0
|
## Version 0.5.1
|
||||||
##
|
##
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|
@ -21,7 +21,9 @@ 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)
|
||||||
(-l: list host-specific files, i.e. ~/.dotfiles/_local/HOSTNAME/DIR)
|
(-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
|
||||||
|
(-l: open host-specific files, i.e. ~/.dotfiles/_local/HOSTNAME/DIR)
|
||||||
diff FILE use vimdiff to compare ~/FILE to ~/.dotfiles/FILE
|
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)
|
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)
|
(-l: link host-specific files, i.e. ~/FILE to ~/.dotfiles/_local/HOSTNAME/FILE)
|
||||||
|
|
@ -187,14 +189,18 @@ case "$cmd" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
edit)
|
edit)
|
||||||
|
basedir=$dotfilesdir
|
||||||
|
[[ $1 = "-l" ]] && { basedir="$basedir/$dotfiles_local_prefix"; shift; }
|
||||||
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
[[ -n $1 ]] || { echo "$(basename $0) $cmd: Missing argument."; exit 1; }
|
||||||
vim "$dotfilesdir/$1"
|
vim "$basedir/$1"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
diff)
|
diff)
|
||||||
|
basedir=$dotfilesdir
|
||||||
|
[[ $1 = "-l" ]] && { basedir="$basedir/$dotfiles_local_prefix"; shift; }
|
||||||
[[ -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="$basedir/$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"
|
||||||
|
|
@ -313,6 +319,12 @@ case "$cmd" in
|
||||||
files=($(compgen -f -X '*/@(.|..|.git)' .dotfiles/$cur))
|
files=($(compgen -f -X '*/@(.|..|.git)' .dotfiles/$cur))
|
||||||
COMPREPLY=(${files[@]#.dotfiles/})
|
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() {
|
_dotfiles() {
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
@ -328,7 +340,11 @@ case "$cmd" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
link|linkstatus)
|
link|linkstatus)
|
||||||
_dotfiles_filenames
|
if [[ $COMP_CWORD -gt 2 && ${COMP_WORDS[2]} = "-l" ]]; then
|
||||||
|
_dotfiles_filenames_local
|
||||||
|
else
|
||||||
|
_dotfiles_filenames
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
createfrom)
|
createfrom)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue