mirror of
https://github.com/DictXiong/dotfiles.git
synced 2024-11-24 13:47:01 +08:00
adding uninstall functions
This commit is contained in:
parent
7a7526d184
commit
c7f3a19091
9
.zshrc2
9
.zshrc2
|
@ -64,11 +64,10 @@ antigen apply
|
||||||
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
dfs()
|
dfs()
|
||||||
{
|
{
|
||||||
if [[ $1 == update ]]; then
|
case $1 in
|
||||||
(cd "$DOTFILES" && env git pull)
|
update ) (cd "$DOTFILES" && env git pull) ;;
|
||||||
else
|
* ) echo "unknown command \"$1\". available: update" ;;
|
||||||
echo "unknown command \"$1\". available: update"
|
esac
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# alias
|
# alias
|
||||||
|
|
45
install.sh
45
install.sh
|
@ -121,6 +121,16 @@ insert_if_not_exist()
|
||||||
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
|
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_if_exist()
|
||||||
|
{
|
||||||
|
filename=$1
|
||||||
|
line=$2
|
||||||
|
fmt_note "removing \"$line\" from \"$filename\" ..."
|
||||||
|
if [ -f "$filename" ]; then
|
||||||
|
grep -vxF -- "$line" "$filename" >> "$filename"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
create_symlink()
|
create_symlink()
|
||||||
{
|
{
|
||||||
src=$1
|
src=$1
|
||||||
|
@ -146,22 +156,47 @@ create_symlink()
|
||||||
ln -s $src $dest
|
ln -s $src $dest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_link_if_match()
|
||||||
|
{
|
||||||
|
src=$1
|
||||||
|
dest=$2
|
||||||
|
if [ "$(readlink $dest)" -ef "$src" ]; then
|
||||||
|
fmt_note "removing symlink \"$dest\" ..."
|
||||||
|
echo ----------
|
||||||
|
env stat $dest
|
||||||
|
echo ----------
|
||||||
|
rm $dest
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
install_crontab(){
|
install_crontab(){
|
||||||
fmt_note "installing \"$crontab_job\" to crontab ..."
|
fmt_note "installing \"$crontab_job\" to crontab ..."
|
||||||
( crontab -l | grep -v "${crontab_job//\*/\\\*}" | grep -v "no crontab for"; echo "$crontab_job" ) | crontab -
|
( crontab -l | grep -vxF "${crontab_job}" | grep -v "no crontab for"; echo "$crontab_job" ) | crontab -
|
||||||
}
|
}
|
||||||
|
|
||||||
uninstall_crontab(){
|
uninstall_crontab(){
|
||||||
fmt_note uninstalling "\"$crontab_job\"" from crontab ...
|
fmt_note "removing \"$crontab_job\" from crontab ..."
|
||||||
( crontab -l | grep -v"$crontab_job" ) | crontab -
|
( crontab -l | grep -vxF "$crontab_job" ) | crontab -
|
||||||
}
|
}
|
||||||
|
|
||||||
install(){
|
install(){
|
||||||
install_crontab
|
install_crontab
|
||||||
insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
||||||
create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
|
create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
|
||||||
fmt_note "job done!"
|
fmt_note "done installing!"
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall(){
|
||||||
|
uninstall_crontab
|
||||||
|
delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
||||||
|
delete_link_if_match "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
|
||||||
|
fmt_note "done uninstalling!"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_color
|
setup_color
|
||||||
install
|
case $1 in
|
||||||
|
^$|-i ) install ;;
|
||||||
|
-r ) uninstall ;;
|
||||||
|
* ) echo "unknown command \"$1\". available: -i, -r" ;;
|
||||||
|
esac
|
||||||
|
|
Loading…
Reference in New Issue
Block a user