Add copy_dotfiles script and other things
This commit is contained in:
55
copy_dotfiles
Executable file
55
copy_dotfiles
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/zsh
|
||||
|
||||
dry="0"
|
||||
|
||||
execute() {
|
||||
log "execute $@"
|
||||
if [[ $dry != "1" ]]; then
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
log() {
|
||||
if [[ $dry != "1" ]]; then
|
||||
echo "$@"
|
||||
else
|
||||
echo "[DRY RUN]: $@"
|
||||
fi
|
||||
}
|
||||
|
||||
while [[ $# > 0 ]]; do
|
||||
if [[ $1 == "--dry" ]]; then
|
||||
dry="1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
log "---------------- dotfiles ----------------"
|
||||
|
||||
copy_dir() {
|
||||
from=$1
|
||||
to=$2
|
||||
pushd $from > /dev/null
|
||||
dirs=(`find . -mindepth 1 -maxdepth 1 -type d`)
|
||||
echo $dirs
|
||||
for dir in $dirs; do
|
||||
if [[ -d $to/$dir ]]; then
|
||||
execute rm -rf $to/$dir
|
||||
fi
|
||||
execute cp -rp $dir $to/$dir
|
||||
done
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
copy_file() {
|
||||
from=$1
|
||||
to=$2
|
||||
filename=$(basename $from)
|
||||
if [[ -e $to/$filename ]]; then
|
||||
execute rm $to/$filename
|
||||
fi
|
||||
execute cp -p $from $to/$filename
|
||||
}
|
||||
|
||||
copy_dir .config $HOME/.config
|
||||
# copy_file .zxcv $HOME
|
Reference in New Issue
Block a user