diff options
| author | Thomas Schmucker <ts@its1.de> | 2026-07-28 08:01:28 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2026-07-28 08:01:28 +0200 |
| commit | 704f6023337dd19f4c8fdac910673bb9398c5295 (patch) | |
| tree | 628431f24b5de65a44a70086d1c311d2cb5b713f /bootstrap/zsh.sh | |
| parent | 19b0f50dcdcb517e0ea1362b3644a42a91844ab8 (diff) | |
| download | dotfiles-704f6023337dd19f4c8fdac910673bb9398c5295.tar.gz dotfiles-704f6023337dd19f4c8fdac910673bb9398c5295.tar.bz2 dotfiles-704f6023337dd19f4c8fdac910673bb9398c5295.zip | |
bootstrap: zsh.sh hinzugefuegt (Plugins, pwgen, mc, chsh)
Diffstat (limited to 'bootstrap/zsh.sh')
| -rwxr-xr-x | bootstrap/zsh.sh | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/bootstrap/zsh.sh b/bootstrap/zsh.sh new file mode 100755 index 0000000..b1780be --- /dev/null +++ b/bootstrap/zsh.sh | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | set -eu | ||
| 4 | |||
| 5 | OS="$(uname -s)" | ||
| 6 | |||
| 7 | die() { | ||
| 8 | printf 'Fehler: %s\n' "$*" >&2 | ||
| 9 | exit 1 | ||
| 10 | } | ||
| 11 | |||
| 12 | have() { | ||
| 13 | command -v "$1" >/dev/null 2>&1 | ||
| 14 | } | ||
| 15 | |||
| 16 | check_prerequisites() { | ||
| 17 | case "$OS" in | ||
| 18 | Darwin) | ||
| 19 | if ! have brew; then | ||
| 20 | die "Homebrew ist nicht installiert." | ||
| 21 | fi | ||
| 22 | ;; | ||
| 23 | FreeBSD) | ||
| 24 | if ! have doas; then | ||
| 25 | die "doas ist nicht installiert." | ||
| 26 | fi | ||
| 27 | ;; | ||
| 28 | *) | ||
| 29 | die "Nicht unterstütztes Betriebssystem: $OS" | ||
| 30 | ;; | ||
| 31 | esac | ||
| 32 | } | ||
| 33 | |||
| 34 | setup_homebrew_env() { | ||
| 35 | case "$OS" in | ||
| 36 | Darwin) | ||
| 37 | export HOMEBREW_NO_AUTO_UPDATE=1 | ||
| 38 | export HOMEBREW_NO_INSTALL_CLEANUP=1 | ||
| 39 | ;; | ||
| 40 | esac | ||
| 41 | } | ||
| 42 | |||
| 43 | install_pkg() { | ||
| 44 | binary="$1" | ||
| 45 | package="$2" | ||
| 46 | |||
| 47 | if have "$binary"; then | ||
| 48 | printf "✓ %-32s vorhanden\n" "$binary" | ||
| 49 | return | ||
| 50 | fi | ||
| 51 | |||
| 52 | printf "→ Installiere %s\n" "$package" | ||
| 53 | |||
| 54 | case "$OS" in | ||
| 55 | Darwin) | ||
| 56 | brew install "$package" | ||
| 57 | ;; | ||
| 58 | FreeBSD) | ||
| 59 | doas pkg install -y "$package" | ||
| 60 | ;; | ||
| 61 | esac | ||
| 62 | } | ||
| 63 | |||
| 64 | install_plugin() { | ||
| 65 | # zsh-syntax-highlighting/zsh-autosuggestions haben kein eigenes Binary, | ||
| 66 | # deshalb Pruefung anhand des von zsh/zshrc gesourceten Pfads. | ||
| 67 | file="$1" | ||
| 68 | package="$2" | ||
| 69 | |||
| 70 | if [ -e "$file" ]; then | ||
| 71 | printf "✓ %-32s vorhanden\n" "$package" | ||
| 72 | return | ||
| 73 | fi | ||
| 74 | |||
| 75 | printf "→ Installiere %s\n" "$package" | ||
| 76 | |||
| 77 | case "$OS" in | ||
| 78 | Darwin) | ||
| 79 | brew install "$package" | ||
| 80 | ;; | ||
| 81 | FreeBSD) | ||
| 82 | doas pkg install -y "$package" | ||
| 83 | ;; | ||
| 84 | esac | ||
| 85 | } | ||
| 86 | |||
| 87 | install_plugins() { | ||
| 88 | case "$OS" in | ||
| 89 | Darwin) | ||
| 90 | install_plugin "/opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" zsh-syntax-highlighting | ||
| 91 | install_plugin "/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh" zsh-autosuggestions | ||
| 92 | ;; | ||
| 93 | FreeBSD) | ||
| 94 | install_plugin "/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" zsh-syntax-highlighting | ||
| 95 | install_plugin "/usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" zsh-autosuggestions | ||
| 96 | ;; | ||
| 97 | esac | ||
| 98 | } | ||
| 99 | |||
| 100 | install_tools() { | ||
| 101 | install_pkg pwgen pwgen | ||
| 102 | install_pkg mc mc | ||
| 103 | } | ||
| 104 | |||
| 105 | set_default_shell() { | ||
| 106 | zsh_path="$(command -v zsh)" || die "zsh wurde nicht gefunden." | ||
| 107 | |||
| 108 | if [ "${SHELL:-}" = "$zsh_path" ]; then | ||
| 109 | printf "✓ %-32s bereits Login-Shell\n" "zsh" | ||
| 110 | return | ||
| 111 | fi | ||
| 112 | |||
| 113 | printf "→ Setze zsh als Login-Shell (chsh)\n" | ||
| 114 | chsh -s "$zsh_path" | ||
| 115 | } | ||
| 116 | |||
| 117 | main() { | ||
| 118 | check_prerequisites | ||
| 119 | setup_homebrew_env | ||
| 120 | |||
| 121 | install_plugins | ||
| 122 | install_tools | ||
| 123 | set_default_shell | ||
| 124 | |||
| 125 | printf "\nBootstrap abgeschlossen.\n" | ||
| 126 | } | ||
| 127 | |||
| 128 | main "$@" | ||
