forked from pure-fish/pure
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller.fish
100 lines (87 loc) · 3.33 KB
/
installer.fish
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
set color_success (set_color green)
set color_error (set_color --bold red)
set color_white (set_color white)
set color_normal (set_color normal)
function pure::set_fish_config_path
printf "\tSet environment variable: %s\n" "\$FISH_CONFIG_DIR"
if test (count $argv) -ge 1
set -gx FISH_CONFIG_DIR $argv[1]
else
set -gx FISH_CONFIG_DIR "$HOME/.config/fish"
end
end
function pure::set_pure_install_path
printf "\tSet environment variable: %s\n" "\$PURE_INSTALL_DIR"
if test (count $argv) -ge 2
set -gx PURE_INSTALL_DIR $argv[2]
else
set -gx PURE_INSTALL_DIR "$FISH_CONFIG_DIR/functions/theme-pure"
end
end
function pure::fetch_source
printf "\tFetching theme's source"
set --local package "https://github.com/rafaelrinaldi/pure/archive/master.tar.gz"
mkdir -p $PURE_INSTALL_DIR
command curl --show-error --location "$package" | command tar -xzf- -C $PURE_INSTALL_DIR --strip-components=1; or begin;
printf "%sError: fetching Pure sources failed%s" "$color_error" "$color_normal"
return 1
end
end
function pure::backup_existing_theme
printf "\tBackuping existing theme"
set --local old_prompt $FISH_CONFIG_DIR/functions/fish_prompt.fish
set --local backup_prompt $old_prompt.ignore
if test -f "$old_prompt"
mv "$old_prompt" "$backup_prompt"; pure::exit_symbol $status
printf "\tPrevious config saved to: %s%s%s." "$color_white" "$backup_prompt" "$color_normal"
end
end
function pure::enable_autoloading
printf "\tEnabling autoloading for pure's functions on shell init"
touch "$FISH_CONFIG_DIR/config.fish"
if not grep -q "pure.fish" $FISH_CONFIG_DIR/config.fish
echo "# THEME PURE #" >> $FISH_CONFIG_DIR/config.fish
echo "set fish_function_path $PURE_INSTALL_DIR/functions/" '$fish_function_path' >> $FISH_CONFIG_DIR/config.fish
echo "source $PURE_INSTALL_DIR/conf.d/pure.fish" >> $FISH_CONFIG_DIR/config.fish
end
ln -sf $PURE_INSTALL_DIR/fish_*.fish $FISH_CONFIG_DIR/functions/
ln -sf $PURE_INSTALL_DIR/functions/*.fish $FISH_CONFIG_DIR/functions/
ln -sf $PURE_INSTALL_DIR/conf.d/* $FISH_CONFIG_DIR/conf.d/
end
function pure::enable_theme
printf "\tEnabling theme"
set fish_function_path $PURE_INSTALL_DIR/functions/ $fish_function_path
source $FISH_CONFIG_DIR/config.fish
end
function pure::clean_after_install
printf "\tCleaning after install"
functions --erase pure::set_fish_config_dir
functions --erase pure::set_pure_install_dir
functions --erase pure::fetch_source
functions --erase pure::backup_existing_theme
functions --erase pure::enable_autoloading
functions --erase pure::enable_theme
end
function pure::success
echo $color_success "✔" $color_normal
end
function pure::error
echo $color_error "✖" $color_normal
end
function pure::exit_symbol
if test $argv[1] -eq 0
pure::success
else
pure::error
end
end
function install_pure
printf "Installing Pure theme\n"
pure::set_fish_config_path $argv
pure::set_pure_install_path $argv
pure::fetch_source; pure::exit_symbol $status
pure::backup_existing_theme; pure::exit_symbol $status
pure::enable_autoloading; pure::exit_symbol $status
pure::enable_theme; pure::exit_symbol $status
pure::clean_after_install; pure::exit_symbol $status
end