|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +prog="angryoxide" |
| 4 | +bash_completion_script="completions/bash_angryoxide_completions" |
| 5 | +zsh_completion_script="completions/zsh_angryoxide_completions" |
| 6 | +BASH_COMPLETION_DIR="/etc/bash_completion.d" |
| 7 | +ZSH_COMPLETION_DIR="/home" |
| 8 | + |
| 9 | +check_root() { |
| 10 | + if [[ "$(id -u)" -ne 0 ]]; then |
| 11 | + echo "This operation must be run as root. Please use sudo." >&2 |
| 12 | + exit 1 |
| 13 | + fi |
| 14 | +} |
| 15 | + |
| 16 | +install_binary() { |
| 17 | + check_root |
| 18 | + echo "Installing $prog binary..." |
| 19 | + cp "../$prog" "/usr/bin/$prog" |
| 20 | +} |
| 21 | + |
| 22 | +install_bash() { |
| 23 | + check_root |
| 24 | + if command -v bash &> /dev/null; then |
| 25 | + echo "Installing bash completion for $prog..." |
| 26 | + mkdir -p "$BASH_COMPLETION_DIR" |
| 27 | + cp "$bash_completion_script" "$BASH_COMPLETION_DIR/$prog" |
| 28 | + echo "Bash completion installed successfully." |
| 29 | + else |
| 30 | + echo "Bash not found, skipping Bash completion installation." |
| 31 | + fi |
| 32 | +} |
| 33 | + |
| 34 | +install_zsh() { |
| 35 | + check_root |
| 36 | + if command -v zsh &> /dev/null; then |
| 37 | + echo "Installing zsh completion for $prog for all users..." |
| 38 | + for dir in $ZSH_COMPLETION_DIR/*; do |
| 39 | + if [[ -d "$dir" ]]; then |
| 40 | + user=$(basename "$dir") |
| 41 | + zsh_dir="$dir/.zsh/completion" |
| 42 | + echo "Installing for user $user..." |
| 43 | + mkdir -p "$zsh_dir" |
| 44 | + cp "$zsh_completion_script" "$zsh_dir/_$prog" |
| 45 | + chown "$user:$user" "$zsh_dir/_$prog" |
| 46 | + fi |
| 47 | + done |
| 48 | + echo "Zsh completion installed successfully for all users." |
| 49 | + else |
| 50 | + echo "Zsh not found, skipping Zsh completion installation." |
| 51 | + fi |
| 52 | +} |
| 53 | + |
| 54 | +uninstall() { |
| 55 | + check_root |
| 56 | + echo "Uninstalling $prog..." |
| 57 | + rm -f "/usr/bin/$prog" |
| 58 | + rm -f "$BASH_COMPLETION_DIR/$prog" |
| 59 | + for dir in $ZSH_COMPLETION_DIR/*; do |
| 60 | + if [[ -d "$dir" ]]; then |
| 61 | + rm -f "$dir/.zsh/completion/_$prog" |
| 62 | + fi |
| 63 | + done |
| 64 | + echo "Cleaned installed binary and completion scripts." |
| 65 | +} |
| 66 | + |
| 67 | +case "$1" in |
| 68 | + install) |
| 69 | + install_binary |
| 70 | + install_bash |
| 71 | + install_zsh |
| 72 | + ;; |
| 73 | + uninstall) |
| 74 | + uninstall |
| 75 | + ;; |
| 76 | + *) |
| 77 | + echo "Usage: $0 (install|uninstall)" |
| 78 | + exit 1 |
| 79 | + ;; |
| 80 | +esac |
0 commit comments