This commit is contained in:
Dict Xiong 2022-05-15 13:18:42 +08:00 committed by GitHub
parent c7f3a19091
commit f48d0912f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,7 +101,7 @@ crontab_job="0 * * * * cd ${dotfile_path} && env git pull"
ask_for_yN() ask_for_yN()
{ {
while true; do while true; do
read -p "$1 [yN]: " yn read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
case $yn in case $yn in
[Yy]* ) return 1;; [Yy]* ) return 1;;
[Nn]* ) return 0;; [Nn]* ) return 0;;
@ -127,7 +127,7 @@ delete_if_exist()
line=$2 line=$2
fmt_note "removing \"$line\" from \"$filename\" ..." fmt_note "removing \"$line\" from \"$filename\" ..."
if [ -f "$filename" ]; then if [ -f "$filename" ]; then
grep -vxF -- "$line" "$filename" >> "$filename" grep -vxF -- "$line" "$filename" | tee "$filename"
fi fi
} }
@ -143,9 +143,9 @@ create_symlink()
if [ -f "$dest" ]; then if [ -f "$dest" ]; then
fmt_warning "\"$dest\" already exists! stat output:" fmt_warning "\"$dest\" already exists! stat output:"
echo ---------- echo ----------
env stat $dest stat $dest
echo ---------- echo ----------
ask_for_yN "${FMT_YELLOW}would you like to replace ${dest}?${FMT_RESET}" ask_for_yN "would you like to replace ${dest}?"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
rm $dest rm $dest
else else
@ -163,7 +163,7 @@ delete_link_if_match()
if [ "$(readlink $dest)" -ef "$src" ]; then if [ "$(readlink $dest)" -ef "$src" ]; then
fmt_note "removing symlink \"$dest\" ..." fmt_note "removing symlink \"$dest\" ..."
echo ---------- echo ----------
env stat $dest stat $dest
echo ---------- echo ----------
rm $dest rm $dest
fi fi
@ -188,15 +188,18 @@ install(){
} }
uninstall(){ uninstall(){
ask_for_yN "do you really want to uninstall?"
if [[ $? == 1 ]]; then
uninstall_crontab uninstall_crontab
delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2" delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
delete_link_if_match "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2" delete_link_if_match "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
fmt_note "done uninstalling!" fmt_note "done uninstalling!"
fi
} }
setup_color setup_color
case $1 in case $1 in
^$|-i ) install ;; ""|-i ) install ;;
-r ) uninstall ;; -r ) uninstall ;;
* ) echo "unknown command \"$1\". available: -i, -r" ;; * ) echo "unknown command \"$1\". available: -i, -r" ;;
esac esac