4 Commits

Author SHA1 Message Date
  Alejandro Mery f67415e78f files: .local/bin -> ../bin 5 years ago
  Alejandro Mery 7f1bf39549 sync: minimise process spawning 5 years ago
  Alejandro Mery e5d0f7ea75 sync: improve internal symlink handling 5 years ago
  Alejandro Mery 9f7f22a6d7 nvim: share vim config 5 years ago
4 changed files with 71 additions and 29 deletions
Split View
  1. +3
    -0
      files/.config/nvim/init.vim
  2. +1
    -0
      files/.local/bin
  3. +2
    -4
      sync.sh
  4. +65
    -25
      sync2.sh

+ 3
- 0
files/.config/nvim/init.vim

@ -0,0 +1,3 @@
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath=&runtimepath
source ~/.vimrc

+ 1
- 0
files/.local/bin

@ -0,0 +1 @@
../bin

+ 2
- 4
sync.sh

@ -2,9 +2,7 @@
set -e
cd "$(dirname "$0")"
DIR="$PWD"
cd "files"
find ! -type d -exec "$DIR/sync2.sh" '{}' \;
find -H files -print0 | xargs -r0 "$PWD/sync2.sh" -d "files"
exec "$DIR/sync_ssh.sh"
exec "$PWD/sync_ssh.sh"

+ 65
- 25
sync2.sh

@ -3,35 +3,75 @@
info() { echo "$$: $*"; }
err() { echo "E: $$: $*" >&2; }
FILES="$(pwd -P)"
set -u
if [ "x-d" = "x${1:-}" ]; then
BASE="$2"
shift 2
else
BASE=.
fi
FILES="$(readlink -f "$BASE")"
for x; do
if [ -d "$x" ]; then
true # skip dirs
elif [ -L "$HOME/$x" ]; then
d0="$(readlink "$HOME/$x")"
d1="$(echo "$FILES/$x" | sed -e 's,/\./,/,g')"
d1="$(readlink -f "$d1")"
if [ "$d0" != "$d1" ]; then
err "$x: relinking, was [$d0]"
ln -snf "$d1" "$HOME/$x"
fi
# clean
#
case "$x" in
"$BASE") continue ;;
"$BASE"/*) x="${x#$BASE/}" ;;
./*) x="${x#./}" ;;
esac
# find target (d1)
#
if [ -L "$FILES/$x" ]; then
d0="$(readlink "$FILES/$x")"
d1="$(readlink -f "$FILES/$x")"
[ "$d1" = "${d1#$FILES/}" ] || d1="$d0"
elif [ ! -d "$FILES/$x" ]; then
d1="$FILES/$x"
else
d="$(dirname "$x")"
if [ ! -d "$HOME/$d/" ]; then
info "$d: creating dir"
mkdir -p "$HOME/$d/"
fi
continue
fi
d="$(echo "$FILES/$x" | sed -e 's,/\./,/,g')"
if [ -e "$HOME/$x" ]; then
info "$x: importing changes and linking"
rm "$d"
cp -a "$HOME/$x" "$d"
else
info "$x: linking"
d="$(readlink -f "$d")"
# link dir
#
d="${x%/*}"
if [ "$d" = "$x" ]; then
d=
elif [ ! -d "$HOME/$d/" ]; then
info "$d: creating dir"
mkdir -p "$HOME/$d/"
fi
# link
#
if [ -L "$HOME/$x" ]; then
# preexisting link ($d1)
d0="$(readlink "$HOME/$x")"
[ "$d0" != "$d1" ] || continue
err "$x: relinking, was [$d0]"
elif [ ! -e "$HOME/$x" ]; then
# new
info "$x: linking"
elif [ -d "$HOME/$x" ]; then
# preexisting dir
err "$x: importing directory and linking [$d1]"
if ! rmdir "$HOME/$x" 2> /dev/null; then
rm "$FILES/$x"
mv "$HOME/$x" "$FILES/$x"
fi
ln -snf "$d" "$HOME/$x"
else
# preexisting file
info "$x: importing changes and linking [$d1]"
rm "$FILES/$x"
cp -a "$HOME/$x" "$FILES/$x"
fi
ln -snf "$d1" "$HOME/$x"
done

Loading…
Cancel
Save