-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-fzf.sh
executable file
·138 lines (117 loc) · 3.66 KB
/
update-fzf.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
# Description: Download and install fzf on Linux and Mac
# Author: Chuck Nemeth
# https://github.com/junegunn/fzf
# Colored output
code_err() { tput setaf 1; printf '%s\n' "$*" >&2; tput sgr0; }
code_grn() { tput setaf 2; printf '%s\n' "$*"; tput sgr0; }
code_yel() { tput setaf 3; printf '%s\n' "$*"; tput sgr0; }
# Variables
bin_dir="${HOME}/.local/bin"
src_dir="${HOME}/.local/src"
man_dir="${HOME}/.local/man/man1"
fzf_man="fzf.1"
fzf_tmux_man="fzf-tmux.1"
if command -v fzf >/dev/null 2>&1; then
fzf_installed_version="$(fzf --version | cut -d' ' -f 1)"
else
fzf_installed_version="Not Installed"
fi
fzf_version="$(curl -s https://api.github.com/repos/junegunn/fzf/releases/latest | \
awk -F': ' '/tag_name/ { gsub(/\"|\,/,"",$2); print $2 }')"
# OS check
archi=$(uname -sm)
case "$archi" in
Darwin\ arm64)
fzf_archive="fzf-${fzf_version##v}-darwin_arm64.tar.gz"
;;
Darwin\ x86_64)
fzf_archive="fzf-${fzf_version##v}-darwin_amd64.tar.gz"
;;
Linux\ armv5*)
fzf_archive="fzf-${fzf_version##v}-linux_armv5.tar.gz"
;;
Linux\ armv6*)
fzf_archive="fzf-${fzf_version##v}-linux_armv6.tar.gz"
;;
Linux\ armv7*)
fzf_archive="fzf-${fzf_version##v}-linux_armv7.tar.gz"
;;
Linux\ armv[8-9]* | Linux\ aarch64*)
fzf_archive="fzf-${fzf_version##v}-linux_arm64.tar.gz"
;;
Linux\ *64)
fzf_archive="fzf-${fzf_version##v}-linux_amd64.tar.gz"
;;
FreeBSD\ *64)
fzf_archive="fzf-${fzf_version##v}-freebsd_amd64.tar.gz"
;;
OpenBSD\ *64)
fzf_archive="fzf-${fzf_version##v}-openbsd_amd64.tar.gz"
;;
*)
code_err "[ERROR] OS not supported!"
exit 1
;;
esac
fzf_url="https://github.com/junegunn/fzf/releases/download/${fzf_version}/${fzf_archive}"
# PATH check
case :$PATH: in
*:"${bin_dir}":*) ;; # do nothing
*)
code_err "[ERROR] ${bin_dir} was not found in \$PATH!"
code_err "Add ${bin_dir} to PATH or select another directory to install to"
exit 1
;;
esac
# Version check
if [ "${fzf_version##v}" = "${fzf_installed_version}" ]; then
printf '%s\n' "Installed Version: ${fzf_installed_version}"
printf '%s\n' "Latest Version: ${fzf_version}"
code_yel "[INFO] Already using latest version. Exiting."
exit 0
else
printf '%s\n' "Installed Verision: ${fzf_installed_version}"
printf '%s\n' "Latest Version: ${fzf_version}"
fi
# Prepare
[ ! -d "${bin_dir}" ] && mkdir -p "${bin_dir}"
[ ! -d "${src_dir}" ] && mkdir -p "${src_dir}"
[ ! -d "${man_dir}" ] && mkdir -p "${man_dir}"
# Download
cd "${src_dir}" || exit
# Clone or update the repository
if [ ! -d "${src_dir}/fzf" ]; then
printf '%s\n' "Cloning the fzf repository"
git clone --depth 1 https://github.com/junegunn/fzf.git fzf
else
printf '%s\n' "Updating the fzf repository"
cd "${src_dir}/fzf" || exit
git pull
fi
cd "${src_dir}/fzf/bin" || exit
# Delete old binary
if [ -f "${src_dir}/fzf/bin/fzf" ]; then
printf '%s\n' "Deleting old fzf binary"
rm -f "${src_dir}/fzf/bin/fzf"
fi
# Download and extract new binary
printf '%s\n' "Downloading fzf binary"
if command -v curl >/dev/null 2>&1; then
curl -fL "${fzf_url}" | tar -xzf -
else
wget -O - "${fzf_url}" | tar -xzf -
fi
chmod u+x "${src_dir}/fzf/bin/fzf"
# Create symlinks
printf '%s\n' "Creating symlinks"
ln -sf "${src_dir}/fzf/bin/fzf" "${bin_dir}"
ln -sf "${src_dir}/fzf/bin/fzf-tmux" "${bin_dir}"
ln -sf "${src_dir}/fzf/man/man1/${fzf_man}" "${man_dir}"
ln -sf "${src_dir}/fzf/man/man1/${fzf_tmux_man}" "${man_dir}"
# Version check
code_grn "Done!"
code_grn "Installed Version: $(fzf --version | cut -d' ' -f 1)"
printf '%s\n' "Make sure to add the following to ~/.vimrc"
printf '%s\n' "Plug '~/.local/src/fzf'"
# vim: ft=sh ts=2 sts=2 sw=2 sr et