|
| 1 | +#!/usr/bin/bash |
| 2 | + |
| 3 | +# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux |
| 4 | +# Reset |
| 5 | +Color_Off='\033[0m' # Text Reset |
| 6 | + |
| 7 | +# Regular Colors |
| 8 | +Black='\033[0;30m' # Black |
| 9 | +Red='\033[0;31m' # Red |
| 10 | +Green='\033[0;32m' # Green |
| 11 | +Yellow='\033[0;33m' # Yellow |
| 12 | +Blue='\033[0;34m' # Blue |
| 13 | +Purple='\033[0;35m' # Purple |
| 14 | +Cyan='\033[0;36m' # Cyan |
| 15 | +White='\033[0;37m' # White |
| 16 | + |
| 17 | +# Bold |
| 18 | +BBlack='\033[1;30m' # Black |
| 19 | +BRed='\033[1;31m' # Red |
| 20 | +BGreen='\033[1;32m' # Green |
| 21 | +BYellow='\033[1;33m' # Yellow |
| 22 | +BBlue='\033[1;34m' # Blue |
| 23 | +BPurple='\033[1;35m' # Purple |
| 24 | +BCyan='\033[1;36m' # Cyan |
| 25 | +BWhite='\033[1;37m' # White |
| 26 | + |
| 27 | +# Underline |
| 28 | +UBlack='\033[4;30m' # Black |
| 29 | +URed='\033[4;31m' # Red |
| 30 | +UGreen='\033[4;32m' # Green |
| 31 | +UYellow='\033[4;33m' # Yellow |
| 32 | +UBlue='\033[4;34m' # Blue |
| 33 | +UPurple='\033[4;35m' # Purple |
| 34 | +UCyan='\033[4;36m' # Cyan |
| 35 | +UWhite='\033[4;37m' # White |
| 36 | + |
| 37 | +# Background |
| 38 | +On_Black='\033[40m' # Black |
| 39 | +On_Red='\033[41m' # Red |
| 40 | +On_Green='\033[42m' # Green |
| 41 | +On_Yellow='\033[43m' # Yellow |
| 42 | +On_Blue='\033[44m' # Blue |
| 43 | +On_Purple='\033[45m' # Purple |
| 44 | +On_Cyan='\033[46m' # Cyan |
| 45 | +On_White='\033[47m' # White |
| 46 | + |
| 47 | +# High Intensity |
| 48 | +IBlack='\033[0;90m' # Black |
| 49 | +IRed='\033[0;91m' # Red |
| 50 | +IGreen='\033[0;92m' # Green |
| 51 | +IYellow='\033[0;93m' # Yellow |
| 52 | +IBlue='\033[0;94m' # Blue |
| 53 | +IPurple='\033[0;95m' # Purple |
| 54 | +ICyan='\033[0;96m' # Cyan |
| 55 | +IWhite='\033[0;97m' # White |
| 56 | + |
| 57 | +# Bold High Intensity |
| 58 | +BIBlack='\033[1;90m' # Black |
| 59 | +BIRed='\033[1;91m' # Red |
| 60 | +BIGreen='\033[1;92m' # Green |
| 61 | +BIYellow='\033[1;93m' # Yellow |
| 62 | +BIBlue='\033[1;94m' # Blue |
| 63 | +BIPurple='\033[1;95m' # Purple |
| 64 | +BICyan='\033[1;96m' # Cyan |
| 65 | +BIWhite='\033[1;97m' # White |
| 66 | + |
| 67 | +# High Intensity backgrounds |
| 68 | +On_IBlack='\033[0;100m' # Black |
| 69 | +On_IRed='\033[0;101m' # Red |
| 70 | +On_IGreen='\033[0;102m' # Green |
| 71 | +On_IYellow='\033[0;103m' # Yellow |
| 72 | +On_IBlue='\033[0;104m' # Blue |
| 73 | +On_IPurple='\033[0;105m' # Purple |
| 74 | +On_ICyan='\033[0;106m' # Cyan |
| 75 | +On_IWhite='\033[0;107m' # White |
| 76 | + |
| 77 | +tempdir=$(mktemp -d) |
| 78 | + |
| 79 | +function require_sudo { |
| 80 | + if [[ $UID != 0 ]]; then |
| 81 | + echo "Please run this script with sudo:" |
| 82 | + echo "sudo $0 $*" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +} |
| 86 | + |
| 87 | +function require_amd64 { |
| 88 | + bit=$(getconf LONG_BIT) |
| 89 | + if [[ $bit != 64 ]]; then |
| 90 | + echo "This script only works for 64bit Debian/Ubuntu-based machines." |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +} |
| 94 | + |
| 95 | +function success { |
| 96 | + echo -e "$Green $1 $Color_Off" |
| 97 | +} |
| 98 | + |
| 99 | +function warn { |
| 100 | + echo -e "$Yellow $1 $Color_Off" |
| 101 | +} |
| 102 | + |
| 103 | +function fail { |
| 104 | + echo -e "$Red $1 $Color_Off" |
| 105 | +} |
| 106 | + |
| 107 | +function __install_dpkg { |
| 108 | + url=$1 |
| 109 | + name=$2 |
| 110 | + |
| 111 | + gum spin --spinner dot --title "wget $name" -- wget "$url" -O "$tempdir/$name.deb" |
| 112 | + gum spin --spinner dot --title "dpkg -i $name" -- dpkg -i "$tempdir/$name.deb" |
| 113 | +} |
| 114 | + |
| 115 | +function __install_apt { |
| 116 | + name=$1 |
| 117 | + |
| 118 | + gum spin --spinner dot --title "apt install $name" -- apt install -y $name |
| 119 | +} |
| 120 | + |
| 121 | +function _install_gum { |
| 122 | + url="https://github.com/charmbracelet/gum/releases/download/v0.3.0/gum_0.3.0_linux_amd64.deb" |
| 123 | + |
| 124 | + # don't use __install_dpkg since gum isn't installed yet |
| 125 | + |
| 126 | + wget "$url" -O "$tempdir/gum.deb" |
| 127 | + apt install "$tempdir/gum.deb" -y |
| 128 | +} |
| 129 | + |
| 130 | +function install_gum { |
| 131 | + which gum >/dev/null && return || echo "installing gum" && _install_gum >/dev/null 2>/dev/null |
| 132 | + which gum >/dev/null && success "installed" || (fail "Failed installing gum" && exit 1) |
| 133 | +} |
| 134 | + |
| 135 | +function spin { |
| 136 | + name=$1 |
| 137 | + alias method=$2 |
| 138 | + |
| 139 | + gum spin --spinner dot --title "Installing $name..." $method |
| 140 | +} |
| 141 | + |
| 142 | +function _install_tool { |
| 143 | + name=$1 |
| 144 | + description=$2 |
| 145 | + method=$3 |
| 146 | + |
| 147 | + gum confirm "Would you like to install $name? ($description)" && ($method && success "installed $name" || fail "error installing $name") || warn "skipped installing $name" # final || is for confirm = false |
| 148 | +} |
| 149 | + |
| 150 | +function install_bat { |
| 151 | + __install_apt bat |
| 152 | +} |
| 153 | + |
| 154 | +function setup_bat_alias { |
| 155 | + bashrc="/home/$SUDO_USER/.bashrc" |
| 156 | + |
| 157 | + which batcat > /dev/null 2> /dev/null || return |
| 158 | + |
| 159 | + grep 'alias bat' $bashrc >/dev/null && warn "alias bat already exists" || gum confirm "Would you like to setup the alias 'bat' for 'batcat'?" && echo -e "\nalias bat=batcat\n" >>$bashrc |
| 160 | +} |
| 161 | + |
| 162 | +function install_exa { |
| 163 | + __install_apt exa |
| 164 | +} |
| 165 | + |
| 166 | +function install_lsd { |
| 167 | + url="https://github.com/Peltoche/lsd/releases/download/0.22.0/lsd_0.22.0_amd64.deb" |
| 168 | + __install_dpkg $url "lsd" |
| 169 | +} |
| 170 | + |
| 171 | +function install_delta { |
| 172 | + url="https://github.com/dandavison/delta/releases/download/0.13.0/git-delta_0.13.0_amd64.deb" |
| 173 | + __install_dpkg $url "delta" |
| 174 | +} |
| 175 | + |
| 176 | +function show_delta_git_setup { |
| 177 | + echo "Write this to your git config if you want to use delta for git:" |
| 178 | + cat <<EOF |
| 179 | +# ~/.gitconfig |
| 180 | +[core] |
| 181 | + pager = delta |
| 182 | +
|
| 183 | +[interactive] |
| 184 | + diffFilter = delta --color-only |
| 185 | +[add.interactive] |
| 186 | + useBuiltin = false # required for git 2.37.0 |
| 187 | +
|
| 188 | +[delta] |
| 189 | + navigate = true # use n and N to move between diff sections |
| 190 | + light = false # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal) |
| 191 | +
|
| 192 | +[merge] |
| 193 | + conflictstyle = diff3 |
| 194 | +
|
| 195 | +[diff] |
| 196 | + colorMoved = default |
| 197 | +EOF |
| 198 | +} |
| 199 | + |
| 200 | +function install_dust { |
| 201 | + url="https://github.com/bootandy/dust/releases/download/v0.8.1/du-dust_0.8.1_amd64.deb" |
| 202 | + __install_dpkg $url "dust" |
| 203 | +} |
| 204 | + |
| 205 | +function install_duf { |
| 206 | + __install_apt "duf" |
| 207 | +} |
| 208 | + |
| 209 | +function install_broot { |
| 210 | + fail "broot is currently not supported" |
| 211 | +} |
| 212 | + |
| 213 | +function install_fd { |
| 214 | + __install_apt "fd-find" |
| 215 | +} |
| 216 | + |
| 217 | +function setup_fd_alias { |
| 218 | + which fd > /dev/null 2> /dev/null && warn "command fd already exists - not making alias" && return |
| 219 | + which fdfind > /dev/null 2> /dev/null && (ln -s $(which fdfind) /usr/bin/fd) || warn "fd not installed - not making alias" |
| 220 | +} |
| 221 | + |
| 222 | +function install_ripgrep { |
| 223 | + __install_apt ripgrep |
| 224 | +} |
| 225 | + |
| 226 | +function install_ag { |
| 227 | + __install_apt silversearcher-ag |
| 228 | +} |
| 229 | + |
| 230 | +function install { |
| 231 | + name=$1 |
| 232 | + description=$2 |
| 233 | + method=$3 |
| 234 | + pkg=${4:-"$name"} |
| 235 | + |
| 236 | + which $pkg >/dev/null && warn "$name already installed" || _install_tool "$name" "$description" $method |
| 237 | +} |
| 238 | + |
| 239 | +function main { |
| 240 | + require_sudo |
| 241 | + require_amd64 |
| 242 | + |
| 243 | + # gum can't use install since _install_tool uses gum |
| 244 | + install_gum |
| 245 | + |
| 246 | + install bat "Better cat" install_bat batcat |
| 247 | + setup_bat_alias |
| 248 | + |
| 249 | + install exa "A modern replacement for ls." install_exa |
| 250 | + |
| 251 | + install lsd "The next gen file listing command." install_lsd |
| 252 | + |
| 253 | + install delta "A syntax-highlighting pager for git, diff, and grep output" install_delta && show_delta_git_setup |
| 254 | + |
| 255 | + install dust "A more intuitive version of du written in rust." install_dust |
| 256 | + |
| 257 | + install duf "A better df alternative" install_duf |
| 258 | + |
| 259 | + install broot "A new way to see and navigate directory trees" install_broot |
| 260 | + |
| 261 | + install fd "A simple, fast and user-friendly alternative to find." install_fd fdfind |
| 262 | + setup_fd_alias |
| 263 | + |
| 264 | + install rg "[ripgrep] An extremely fast alternative to grep that respects your gitignore" install_ripgrep |
| 265 | + |
| 266 | + install ag "A code searching tool similar to ack, but faster." install_ag |
| 267 | + |
| 268 | + # ... |
| 269 | + # keep gum? |
| 270 | +} |
| 271 | + |
| 272 | +main |
| 273 | + |
| 274 | +# todo: remove flag |
| 275 | +# todo: menu with 1. install all; 2. install some; 3. remove all; 4. remove some |
| 276 | +# sudo apt remove -y gum git-delta lsd exa bat du-dust duf fd-find ripgrep silversearcher-ag ... |
0 commit comments