Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update link_files script

  • Loading branch information...
commit da7fd6d10711761705c47e51b4efdc59c67a305b 1 parent f29f2e4
@graudeejs authored
Showing with 35 additions and 19 deletions.
  1. +35 −19 link_files.sh
View
54 link_files.sh
@@ -10,30 +10,46 @@
DOT_DIR="`pwd`"
./Xdefaults.sh
-DOT_FILES="`ls -d dot.*`"
-DOT_CONFIG_FILES="`ls config/`"
+DOT_FILES="`find . -name "dot.*" -depth 1 | sed 's#^\./##'`"
+DOT_CONFIG_FILES="`find config -depth 1`"
+BIN_FILES="`find bin -depth 1`"
+
+## copy file to directory
+# "dot" prefix will be removed
+# Arguments:
+# $1 - src file/directory/symbolic link
+# $2 - dest directory
+copy_file() {
+ if [ "$1" = '' -o "$2" = '' ]; then
+ echo "Argument error" > /dev/stderr
+ exit 1
+ fi
+
+
+ FILE_NAME="`echo "$1" | sed 's#.*/##; s/^dot\././'`"
+
+ echo "$2/$FILE_NAME"
+ rm -Rf "$2/$FILE_NAME"
+ if [ -L "$DOT_DIR/$1" ]; then
+ cp -RP "$DOT_DIR/$1" "$2/$FILE_NAME"
+ else
+ ln -s "$DOT_DIR/$1" "$2/$FILE_NAME"
+ fi
+}
# handle dotfiles in ~/
for FILE in $DOT_FILES; do
- FILE_NAME="`echo "$FILE" | sed 's/^dot//'`"
- rm -Rvf $HOME/$FILE_NAME
-
- if [ -L "$DOT_DIR/$FILE" ]; then
- cp -vRP "$DOT_DIR/$FILE" "$HOME/$FILE_NAME"
- else
- ln -vs "$DOT_DIR/$FILE" "$HOME/$FILE_NAME"
- fi
+ copy_file "$FILE" "$HOME"
done
# handle dotfiles in ~/.config
-[ -d "$HOME/.config" ] || mkdir "$HOME/.config"
+[ -d "$HOME/.config" ] || mkdir -p "$HOME/.config"
for FILE in $DOT_CONFIG_FILES; do
- rm -Rvf "$HOME/.config/$FILE"
- FILE_NAME="`echo "$FILE" | sed 's/^dot//'`"
-
- if [ -L "$DOT_DIR/config/$FILE" ]; then
- cp -vRP "$DOT_DIR/config/$FILE" "$HOME/.config/$FILE_NAME"
- else
- ln -vs "$DOT_DIR/config/$FILE" "$HOME/.config/$FILE_NAME"
- fi
+ copy_file "$FILE" "$HOME/.config"
+done
+
+# handle ~/bin files
+[ -d "$HOME/bin" ] || mkdir -p "$HOME/bin"
+for FILE in $BIN_FILES; do
+ copy_file "$FILE" "$HOME/bin"
done
Please sign in to comment.
Something went wrong with that request. Please try again.