Last active
February 5, 2021 11:26
-
-
Save fragolinux/ed12ab72a22ae7a74c00008d789a337d to your computer and use it in GitHub Desktop.
direnv disabler script, inspired by "basher" uninstall script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## direnv disabler script, inspired by "basher" uninstall script | |
# shellcheck disable=SC2034 | |
die() { | |
echo "!! $1 " >&2 | |
echo "!! -----------------------------" >&2 | |
exit 1 | |
} | |
## stop if direnv is not installed | |
command -v direnv >/dev/null 2>&1 || die "I require direnv but it's not installed. Aborting." | |
## now check what shell is running | |
shell_type=$(basename "$SHELL") | |
echo ". detected shell type: $shell_type" | |
case "$shell_type" in | |
bash) startup_type="simple" ; startup_script="$HOME/.bashrc" ;; | |
zsh) startup_type="simple" ; startup_script="$HOME/.zshrc" ;; | |
sh) startup_type="simple" ; startup_script="$HOME/.profile";; | |
fish) startup_type="fish" ; startup_script="$HOME/.config/fish/config.fish" ;; | |
*) startup_type="?" ; startup_script="" ; ;; | |
esac | |
## startup script should exist already | |
[[ -n "$startup_script" && ! -f "$startup_script" ]] && die "startup script [$startup_script] does not exist" | |
## direnv_keyword will allow us to remove the lines upon uninstall | |
direnv_keyword="direnv5ea843" | |
if grep -q "$direnv_keyword" "$startup_script" ; then | |
echo ". remove direnv from startup script [$startup_script]" | |
sleep 1 | |
temp_file="$startup_script.temp" | |
cp "$startup_script" "$temp_file" | |
< "$temp_file" grep -v "$direnv_keyword" > "$startup_script" | |
rm "$temp_file" | |
elif grep -q direnv "$startup_script" ; then | |
grep direnv "$startup_script" | |
die "Can't auto-remove the lines from $(basename $startup_script) - please do so manually " | |
else | |
die "Can't find initialisation commands for direnv" | |
fi | |
## script is finished | |
echo "direnv config is uninstalled" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment