forked from spaceship-prompt/spaceship-prompt
-
Notifications
You must be signed in to change notification settings - Fork 12
/
uninstall.zsh
executable file
·72 lines (60 loc) · 2.04 KB
/
uninstall.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env zsh
#
# Author: Denys Dovhan, denysdovhan.com
# https://github.com/denysdovhan/spaceship-zsh-theme
# ------------------------------------------------------------------------------
# VARIABLES
# Paths to important resources
# ------------------------------------------------------------------------------
ZSHRC="$HOME/.zshrc"
DIST="$ZSH_CUSTOM/themes/spaceship.zsh-theme"
# ------------------------------------------------------------------------------
# HELPERS
# Useful functions for common tasks
# ------------------------------------------------------------------------------
# Paint text in color
# USAGE:
# paint <color> [text...]
paint() {
echo "$fg[$1]${@:2}$reset_color"
}
# Logging functions.
# USAGE:
# log|error|success [text...]
log() { paint 'cyan' "SPACESHIP: $*" }
warning() { paint 'yellow' "SPACESHIP: $*" }
error() { echo ; paint 'red' "SPACESHIP: $*" ; echo }
success() { echo ; paint 'green' "SPACESHIP: $*" ; echo }
# ------------------------------------------------------------------------------
# MAIN
# Checkings and uninstalling process
# ------------------------------------------------------------------------------
# Source ~/.zshrc because we need oh-my-zsh variables
source "$ZSHRC"
# Check if $ZSH_CUSTOM is set
if [[ -z $ZSH_CUSTOM ]]; then
error '$ZSH_CUSTOM is not defined!'
exit 1
fi
# Remove symlink
if [[ -L "$DIST" ]]; then
log "Removing $DIST..."
rm -f "$DIST"
else
warning "$DIST is not present!"
fi
# Remove spaceship from .zshrc
if grep -q "$DIST" "$ZSHRC"; then
log "Removing Spaceship from $ZSHRC"
sed -i '' "/source .*\/themes\/spaceship.zsh-theme/d" "$ZSHRC"
else
warning "$DIST is not sourced in $ZSHRC!"
fi
# Change theme to default one
if grep -q "ZSH_THEME=.*" "$ZSHRC"; then
log 'Attempting to change theme from "spaceship" to "robbyrussell"'
sed -i '' 's/ZSH_THEME=.spaceship./ZSH_THEME="robbyrussell"/g' "$ZSHRC"
else
warning '"spaceship" was not set as theme!'
fi
success "Done! Spaceship is successfuly removed! Please, reload your terminal."