summaryrefslogtreecommitdiffstats
path: root/install
blob: 92a488d2f724ac8038909127cde5e7279c0527a1 (plain)
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
#!/bin/bash

cd `dirname $BASH_SOURCE`
FZF_BASE=`pwd`

# ruby executable
echo -n "Checking Ruby executable ... "
RUBY=`which ruby`
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"
  FZF_ALIAS="alias fzf='$RUBY --disable-gems $FZF_BASE/fzf'"
else
  echo "< 1.9"
  FZF_ALIAS="alias fzf='$RUBY $FZF_BASE/fzf' # fzf"
fi

# Auto-completion
read -p "Do you want to add auto-completion support? (y/n) " -n 1 -r
echo
[[ ! $REPLY =~ ^[Nn]$ ]]
AUTO_COMPLETION=$?

echo
for shell in bash zsh; do
  rc=~/.${shell}rc
  echo "Update $rc:"

  # Install fzf alias
  echo "- Add fzf alias:"
  echo "  - $FZF_ALIAS"
  if [ $(grep "alias fzf=" $rc | wc -l) -gt 0 ]; then
    echo "    - (X) fzf alias already exists"
  else
    echo $FZF_ALIAS >> $rc
    echo "    - Added."
  fi

  # Install auto-completion support
  if [ $AUTO_COMPLETION -eq 0 ]; then
    FZF_COMPLETION="source $FZF_BASE/fzf-completion.${shell}"
    echo "- Add auto-completion support"
    echo "  - $FZF_COMPLETION"
    if [ $(grep "source.*fzf-completion" $rc | wc -l) -gt 0 ]; then
      echo "    - (X) fzf-completion.${shell} already being sourced"
    else
      echo $FZF_COMPLETION >> $rc
      echo "    - Added."
    fi
  fi
  echo
done

echo "Finished. Reload your .bashrc or .zshrc to take effect."
echo "   source ~/.bashrc  # bash"
echo "   source ~/.zshrc   # zsh"
echo
echo "To uninstall fzf, simply remove the added lines."