097477d0b2496da36b75a276925b3813b95e3aea
[webi-installers/.git] / fish / install.sh
1 set -e
2 set -u
3
4 if ! (uname -a | grep -i "darwin" > /dev/null); then
5     echo "No fish installer for Linux yet. Try this instead:"
6     echo "    sudo apt install -y fish"
7     exit 1
8 fi
9
10 ################
11 # Install fish #
12 ################
13
14 # Every package should define these 6 variables
15 pkg_cmd_name="fish"
16
17 pkg_dst_cmd="$HOME/.local/bin/fish"
18 pkg_dst="$pkg_dst_cmd"
19
20 pkg_src_cmd="$HOME/.local/opt/fish-v$WEBI_VERSION/bin/fish"
21 pkg_src_dir="$HOME/.local/opt/fish-v$WEBI_VERSION"
22 pkg_src="$pkg_src_cmd"
23
24 # pkg_install must be defined by every package
25
26 function _macos_post_install() {
27     if ! [ -e "$HOME/.local/bin/fish" ]; then
28         return 0
29     fi
30
31     echo ""
32     echo "Trying to set fish as the default shell..."
33     echo ""
34     # stop the caching of preferences
35     killall cfprefsd
36
37     # Set default Terminal.app shell to fish
38     defaults write com.apple.Terminal "Shell" -string "$HOME/.local/bin/fish"
39     echo "To set 'fish' as the default Terminal.app shell:"
40     echo "    Terminal > Preferences > General > Shells open with:"
41     echo "    $HOME/.local/bin/fish"
42     echo ""
43
44     # Set default iTerm2 shell to fish
45     if [ -e "$HOME/Library/Preferences/com.googlecode.iterm2.plist" ]; then
46         /usr/libexec/PlistBuddy \
47             -c "SET ':New Bookmarks:0:Custom Command' 'Custom Shell'" \
48             $HOME/Library/Preferences/com.googlecode.iterm2.plist
49         /usr/libexec/PlistBuddy \
50             -c "SET ':New Bookmarks:0:Command' $HOME/.local/bin/fish" \
51             $HOME/Library/Preferences/com.googlecode.iterm2.plist
52         echo "To set 'fish' as the default iTerm2 shell:"
53         echo "    iTerm2 > Preferences > Profiles > General > Command >"
54         echo "    Custom Shell: $HOME/.local/bin/fish"
55         echo ""
56     fi
57
58     killall cfprefsd
59 }
60
61 # always try to reset the default shells
62 _macos_post_install
63
64 function pkg_install() {
65     mv fish.app/Contents/Resources/base/usr/local "$HOME/.local/opt/fish-v${WEBI_VERSION}"
66
67 }
68
69 function pkg_post_install() {
70     # don't skip what webi would do automatically
71     webi_post_install
72
73     # try again to update default shells, now that all files should exist
74     _macos_post_install
75 }
76
77 # pkg_get_current_version is recommended, but (soon) not required
78 function pkg_get_current_version() {
79     # 'fish --version' has output in this format:
80     #       fish, version 3.1.2
81     # This trims it down to just the version number:
82     #       3.1.2
83     echo $(fish --version 2>/dev/null | head -n 1 | cut -d ' ' -f 3)
84 }