2013-10-23 01:26:55 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
cd `dirname $BASH_SOURCE`
|
2013-11-26 10:01:01 +00:00
|
|
|
fzf_base=`pwd`
|
2013-11-19 16:29:36 +00:00
|
|
|
|
|
|
|
# ruby executable
|
|
|
|
echo -n "Checking Ruby executable ... "
|
2013-11-26 10:01:01 +00:00
|
|
|
ruby=`which ruby`
|
2013-11-19 16:29:36 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ruby executable not found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "OK"
|
|
|
|
|
|
|
|
# Curses-support
|
|
|
|
echo -n "Checking Curses support ... "
|
|
|
|
/usr/bin/env ruby -e "begin; require 'curses'; rescue Exception; exit 1; end"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Your ruby does not support 'curses'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "OK"
|
|
|
|
|
|
|
|
# Ruby version
|
|
|
|
echo -n "Checking Ruby version ... "
|
|
|
|
/usr/bin/env ruby -e 'exit RUBY_VERSION >= "1.9"'
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo ">= 1.9"
|
2013-11-26 10:01:01 +00:00
|
|
|
fzf_cmd="$ruby --disable-gems $fzf_base/fzf"
|
2013-11-19 16:29:36 +00:00
|
|
|
else
|
|
|
|
echo "< 1.9"
|
2013-11-26 10:01:01 +00:00
|
|
|
fzf_cmd="$ruby $fzf_base/fzf"
|
2013-11-19 16:29:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Auto-completion
|
|
|
|
read -p "Do you want to add auto-completion support? (y/n) " -n 1 -r
|
|
|
|
echo
|
|
|
|
[[ ! $REPLY =~ ^[Nn]$ ]]
|
2013-11-26 10:01:01 +00:00
|
|
|
auto_completion=$?
|
2013-11-19 16:29:36 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
for shell in bash zsh; do
|
2013-11-26 10:01:01 +00:00
|
|
|
echo -n "Generate ~/.fzf.$shell ... "
|
|
|
|
src=~/.fzf.${shell}
|
2013-11-19 16:29:36 +00:00
|
|
|
|
2013-11-26 10:01:01 +00:00
|
|
|
fzf_completion="source $fzf_base/fzf-completion.${shell}"
|
|
|
|
if [ $auto_completion -ne 0 ]; then
|
|
|
|
fzf_completion="# $fzf_completion"
|
2013-11-19 16:29:36 +00:00
|
|
|
fi
|
|
|
|
|
2013-11-26 10:01:01 +00:00
|
|
|
cat > $src << EOF
|
|
|
|
unalias fzf 2> /dev/null
|
|
|
|
fzf() {
|
|
|
|
$fzf_cmd "\$@"
|
|
|
|
}
|
|
|
|
export -f fzf > /dev/null
|
|
|
|
$fzf_completion
|
|
|
|
|
|
|
|
EOF
|
|
|
|
echo "OK"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
for shell in bash zsh; do
|
|
|
|
rc=~/.${shell}rc
|
|
|
|
src="source ~/.fzf.${shell}"
|
|
|
|
|
|
|
|
echo "Update $rc:"
|
|
|
|
echo " - $src"
|
|
|
|
if [ $(grep "$src" $rc | wc -l) -gt 0 ]; then
|
|
|
|
echo " - Not added (already being sourced)"
|
|
|
|
else
|
|
|
|
echo $src >> $rc
|
|
|
|
echo " - Added"
|
2013-11-19 16:29:36 +00:00
|
|
|
fi
|
|
|
|
echo
|
|
|
|
done
|
|
|
|
|
2013-11-19 17:10:19 +00:00
|
|
|
echo "Finished. Reload your .bashrc or .zshrc to take effect."
|
|
|
|
echo " source ~/.bashrc # bash"
|
|
|
|
echo " source ~/.zshrc # zsh"
|
|
|
|
echo
|
2013-11-26 10:01:01 +00:00
|
|
|
echo "To uninstall fzf, simply remove the added line."
|
2013-10-23 01:26:55 +00:00
|
|
|
|