aboutsummaryrefslogtreecommitdiffstats
path: root/install.sh
blob: 0dc0419f98ec847979fb11e97e459e1001ae41d8 (plain) (blame)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#! /bin/sh
set -eu

ATUIN_NON_INTERACTIVE="no"

for arg in "$@"; do
  case "$arg" in
    --non-interactive) ATUIN_NON_INTERACTIVE="yes" ;;
    *) ;;
  esac
done

if [ "$ATUIN_NON_INTERACTIVE" != "yes" ]; then
  if [ -t 0 ] || { true </dev/tty; } 2>/dev/null; then
    ATUIN_NON_INTERACTIVE="no"
  else
    ATUIN_NON_INTERACTIVE="yes"
  fi
fi

cat << EOF
 _______  _______  __   __  ___   __    _
|   _   ||       ||  | |  ||   | |  |  | |
|  |_|  ||_     _||  | |  ||   | |   |_| |
|       |  |   |  |  |_|  ||   | |       |
|       |  |   |  |       ||   | |  _    |
|   _   |  |   |  |       ||   | | | |   |
|__| |__|  |___|  |_______||___| |_|  |__|

Magical shell history

Atuin setup
https://github.com/atuinsh/atuin
https://forum.atuin.sh

Please file an issue or reach out on the forum if you encounter any problems!

===============================================================================

EOF

__atuin_install_binary(){
  curl --proto '=https' --tlsv1.2 -LsSf https://github.com/atuinsh/atuin/releases/latest/download/atuin-installer.sh | sh
}

if ! command -v curl > /dev/null; then
    echo "curl not installed. Please install curl."
    exit
elif ! command -v sed > /dev/null; then
    echo "sed not installed. Please install sed."
    exit
fi


__atuin_install_binary

# TODO: Check which shell is in use
# Use of single quotes around $() is intentional here
# shellcheck disable=SC2016
if ! grep -q "atuin init zsh" "${ZDOTDIR:-$HOME}/.zshrc"; then
  printf '\neval "$(atuin init zsh)"\n' >> "${ZDOTDIR:-$HOME}/.zshrc"
fi

# Use of single quotes around $() is intentional here
# shellcheck disable=SC2016

if ! grep -q "atuin init bash" ~/.bashrc; then
  curl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh
  printf '\n[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh\n' >> ~/.bashrc
  echo 'eval "$(atuin init bash)"' >> ~/.bashrc
fi

if [ -f "$HOME/.config/fish/config.fish" ]; then
  # Check if the line already exists to prevent duplicates
  if ! grep -q "atuin init fish" "$HOME/.config/fish/config.fish"; then
        # Detect BSD or GNU sed
        if sed --version >/dev/null 2>&1; then
          # GNU
          sed -i '/if status is-interactive/,/end/ s/end$/    atuin init fish | source\
end/' "$HOME/.config/fish/config.fish"
        else
          # BSD (macOS)
          sed -i '' '/if status is-interactive/,/end/ s/end$/    atuin init fish | source\
end/' "$HOME/.config/fish/config.fish"
        fi
    fi
fi

ATUIN_BIN="$HOME/.atuin/bin/atuin"

echo ""
echo "Atuin installed successfully!"
echo ""

if [ "$ATUIN_NON_INTERACTIVE" != "yes" ]; then

  printf "Would you like to import your existing shell history into Atuin? [Y/n] "
  read -r import_answer </dev/tty || import_answer="n"
  import_answer="${import_answer:-y}"

  case "$import_answer" in
    [yY]*)
      echo ""
      if ! "$ATUIN_BIN" import auto; then
        echo ""
        echo "History import failed. You can retry later with 'atuin import auto'."
      fi
      echo ""
      ;;
    *)
      echo "Skipping history import. You can always run 'atuin import auto' later."
      echo ""
      ;;
  esac

  cat << EOF
Sync your history across all your machines with Atuin Cloud:

  - End-to-end encrypted — only you can read your data
  - Access your history from any device
  - Never lose your history, even if you wipe a machine

EOF

  printf "Sign up for a sync account? [Y/n] "
  read -r sync_answer </dev/tty || sync_answer="n"
  sync_answer="${sync_answer:-y}"

  case "$sync_answer" in
    [yY]*)
      echo ""
      if ! "$ATUIN_BIN" register </dev/tty; then
        echo ""
        echo "Registration did not complete. You can run 'atuin register' any time to try again."
      fi
      ;;
    *)
      echo ""
      printf "Already have an account? Log in with 'atuin login'.\n"
      echo "You can also run 'atuin register' any time to create one."
      ;;
  esac

else
  echo "Non-interactive environment detected — skipping setup prompts."
  echo "You can run the following commands manually after installation:"
  echo ""
  echo "  atuin import auto       Import your existing shell history"
  echo "  atuin register          Sign up for a sync account"
  echo "  atuin login             Log in to an existing sync account"
fi

if [ "$ATUIN_NON_INTERACTIVE" != "yes" ]; then
  "$ATUIN_BIN" setup </dev/tty
fi

cat << EOF

 _______  __   __  _______  __    _  ___   _    __   __  _______  __   __
|       ||  | |  ||   _   ||  |  | ||   | | |  |  | |  ||       ||  | |  |
|_     _||  |_|  ||  |_|  ||   |_| ||   |_| |  |  |_|  ||   _   ||  | |  |
  |   |  |       ||       ||       ||      _|  |       ||  | |  ||  |_|  |
  |   |  |       ||       ||  _    ||     |_   |_     _||  |_|  ||       |
  |   |  |   _   ||   _   || | |   ||    _  |    |   |  |       ||       |
  |___|  |__| |__||__| |__||_|  |__||___| |_|    |___|  |_______||_______|

Thanks for installing Atuin! I really hope you like it.

If you have any issues, please open an issue on GitHub or visit our forum (https://forum.atuin.sh)!

If you love Atuin, please give us a star on GitHub! It really helps ⭐️ https://github.com/atuinsh/atuin

===============================================================================

 ⚠️  Please restart your shell or open a new terminal for Atuin to take effect!

===============================================================================
EOF