uninstall: try to determine initialization file
uninstall: TIL that `fgrep` is deprecated...pull/2039/head
parent
0485778117
commit
68149f7c8d
|
|
@ -7,55 +7,85 @@ function local_setup() {
|
|||
}
|
||||
|
||||
function local_setup_file() {
|
||||
# Determine which config file to use based on OS.
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
export BASH_IT_CONFIG_FILE=.bash_profile
|
||||
;;
|
||||
*)
|
||||
export BASH_IT_CONFIG_FILE=.bashrc
|
||||
;;
|
||||
esac
|
||||
# don't load any libraries as the tests here test the *whole* kit
|
||||
: # don't load any libraries as the tests here test the *whole* kit
|
||||
}
|
||||
|
||||
@test "uninstall: verify that the uninstall script exists" {
|
||||
assert_file_exist "$BASH_IT/uninstall.sh"
|
||||
}
|
||||
|
||||
@test "uninstall: run the uninstall script with an existing backup file" {
|
||||
cd "$BASH_IT"
|
||||
@test "uninstall: run the uninstall script with existing backup 'bashrc'" {
|
||||
BASH_IT_CONFIG_FILE=.bashrc
|
||||
|
||||
echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak"
|
||||
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
|
||||
local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
|
||||
echo "test file content for backup" > "${HOME?}/$BASH_IT_CONFIG_FILE.bak"
|
||||
echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
local md5_bak=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
|
||||
|
||||
run ./uninstall.sh
|
||||
run "${BASH_IT?}/uninstall.sh"
|
||||
assert_success
|
||||
assert_output --partial "Your original ~/$BASH_IT_CONFIG_FILE has been restored."
|
||||
|
||||
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall"
|
||||
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
|
||||
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak"
|
||||
assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
|
||||
local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
local md5_conf=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
|
||||
assert_equal "$md5_bak" "$md5_conf"
|
||||
}
|
||||
|
||||
@test "uninstall: run the uninstall script without an existing backup file" {
|
||||
cd "$BASH_IT"
|
||||
@test "uninstall: run the uninstall script with existing backup 'bash_profile'" {
|
||||
BASH_IT_CONFIG_FILE=.bash_profile
|
||||
|
||||
echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
|
||||
local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
echo "test file content for backup file" > "${HOME?}/$BASH_IT_CONFIG_FILE.bak"
|
||||
echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
local md5_bak=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
|
||||
|
||||
run ./uninstall.sh
|
||||
run "${BASH_IT?}/uninstall.sh"
|
||||
assert_success
|
||||
|
||||
assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall"
|
||||
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
|
||||
assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak"
|
||||
assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
|
||||
local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
|
||||
local md5_conf=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
|
||||
assert_equal "$md5_bak" "$md5_conf"
|
||||
}
|
||||
|
||||
@test "uninstall: run the uninstall script without existing backup 'bashrc" {
|
||||
BASH_IT_CONFIG_FILE=.bashrc
|
||||
|
||||
echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
local md5_orig=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
|
||||
run "${BASH_IT?}/uninstall.sh"
|
||||
assert_success
|
||||
|
||||
assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
|
||||
local md5_uninstall=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
|
||||
|
||||
assert_equal "$md5_orig" "$md5_uninstall"
|
||||
}
|
||||
|
||||
@test "uninstall: run the uninstall script without existing backup 'bash_profile" {
|
||||
BASH_IT_CONFIG_FILE=.bash_profile
|
||||
|
||||
echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
local md5_orig=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
|
||||
run "${BASH_IT?}/uninstall.sh"
|
||||
|
||||
assert_success
|
||||
|
||||
assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak"
|
||||
assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE"
|
||||
|
||||
local md5_uninstall=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
|
||||
|
||||
assert_equal "$md5_orig" "$md5_uninstall"
|
||||
}
|
||||
|
|
|
|||
22
uninstall.sh
22
uninstall.sh
|
|
@ -5,12 +5,30 @@
|
|||
|
||||
: "${BASH_IT:=${HOME?}/.bash_it}"
|
||||
|
||||
if [[ ! -e ~/.bashrc && ! -e ~/.bash_profile && ! -e ~/.bashrc.bak && ! -e ~/.bash_profile.bak ]]; then
|
||||
echo "We can't locate your configuration files, so we can't uninstall..."
|
||||
return
|
||||
elif grep -F -q -- BASH_IT ~/.bashrc && grep -F -q -- BASH_IT ~/.bash_profile; then
|
||||
echo "We can't figure out if Bash-it is loaded from ~/.bashrc or ~/.bash_profile..."
|
||||
return
|
||||
elif grep -F -q -- BASH_IT ~/.bashrc || [[ -e ~/.bashrc.bak && ! -e ~/.bashrc ]]; then
|
||||
CONFIG_FILE=".bashrc"
|
||||
if [[ ! -e ~/.bashrc && -e ~/.bash_profile ]]; then
|
||||
# legacy Mac or WSL or just no backup file
|
||||
elif grep -F -q -- BASH_IT ~/.bash_profile || [[ -e ~/.bash_profile.bak && ! -e ~/.bash_profile ]]; then
|
||||
CONFIG_FILE=".bash_profile"
|
||||
else
|
||||
echo "Bash-it does not appear to be installed."
|
||||
return
|
||||
fi
|
||||
|
||||
# possible states:
|
||||
# - both .bash* /and/ .bash*.bak, /and/ both config reference `$BASH_IT`: no solution
|
||||
# - both config and bak, but only one references `$BASH_IT`: that one
|
||||
# - both config, only one bak, but other references `$BASH_IT`: the other one?
|
||||
# - both config, no bak, with `$BASH_IT` reference: that one
|
||||
# - one config, no bak, but no `$BASH_IT` reference: wut
|
||||
# - no config, with bak, with `$BASH_IT`: re-create???
|
||||
# - no config, no bak: nothing.
|
||||
|
||||
BACKUP_FILE=$CONFIG_FILE.bak
|
||||
|
||||
if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then
|
||||
|
|
|
|||
Loading…
Reference in New Issue