-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup
executable file
·51 lines (42 loc) · 1.16 KB
/
setup
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
#!/usr/bin/env bash
fuzzy_cd_setup() {
patched="no"
patch_file() {
file="$1"
if grep -q fuzzycd "$file"; then
echo "=== Skipping $file"
else
echo "=== Amending $file"
printf "source /usr/local/bin/fuzzycd\n" >>"$file"
fi
patched="yes"
}
download_script() {
echo "=== Saving fuzzycd to /usr/local/bin"
sudo=''
if [[ $EUID -ne 0 ]]; then
sudo='sudo'
fi
curl_command="curl -s https://raw.githubusercontent.com/DannyBen/fuzzycd/master/fuzzycd > /usr/local/bin/fuzzycd"
$sudo bash -c "$curl_command"
$sudo chmod a+x /usr/local/bin/fuzzycd
}
patch_startup_files() {
echo "=== Searching for startup files"
[[ -f "$HOME/.zshrc" ]] && patch_file "$HOME/.zshrc"
[[ -f "$HOME/.bashrc" ]] && patch_file "$HOME/.bashrc"
}
show_exit_message() {
if [[ $patched == "yes" ]]; then
echo "=== Done. You may need to source $file or restart your session"
else
echo "=== Setup is INCOMPLETE"
echo " Add 'source ~/.fuzzy-cd/fuzzy-cd' to your shell's initialization script"
exit 1
fi
}
download_script
patch_startup_files
show_exit_message
}
fuzzy_cd_setup