From 70d65eb39c696969f563d408602592b6e0f18dd9 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sat, 11 May 2019 19:19:59 +0200 Subject: [PATCH] Add symlink and directory support to dotfiles.sh --add --- dotfiles.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/dotfiles.sh b/dotfiles.sh index de92007..832fdf6 100755 --- a/dotfiles.sh +++ b/dotfiles.sh @@ -69,17 +69,18 @@ files() { add() { [ "$1" = "" ] && return 1 - FILE=$(readlink -f "$1") - FILE_CUT_HOME="$(echo "$FILE" | sed -nr 's/^\/home\/'"$USER"'\/(.*)$/\1/p')" + FILE="$(readlink -f $(dirname $1))/$(basename $1)" + FILE_CUT_HOME="$(echo "$FILE" \ + | awk -v m="^$HOME/" '$0 ~ m { print substr($0, length(m)) }')" # /home// if [ -n "$FILE_CUT_HOME" ]; then mkdir -p "$(pwd)/$(dirname "$FILE_CUT_HOME")" - cp "$FILE" "$(pwd)/$FILE_CUT_HOME" + cp -Ppr "$FILE" "$(pwd)/$FILE_CUT_HOME" # / else mkdir -p "$(pwd)/$(dirname "$FILE")" - cp "$FILE" "$(pwd)/$FILE" + cp -PPr "$FILE" "$(pwd)/$FILE" fi } @@ -204,6 +205,4 @@ case $OPT in esac # @Todo: -# get function to support symlinks -# get function to add entire new directory including contents # push function to push just one file