#!/usr/bin/env sh set -e usage() { echo "Usage: $0 [--shell fish|bash|none|all] [--no-man]" } requested_shell= install_man=true while [ "$#" -gt 0 ]; do case "$1" in --shell) requested_shell=${2:-} shift 2 ;; --shell=*) requested_shell=${1#--shell=} shift ;; --no-man) install_man=false shift ;; -h|--help) usage exit 0 ;; *) echo "Unknown option: $1" >&2 usage >&2 exit 1 ;; esac done cabal build exe:tasker bin=$(cabal list-bin exe:tasker) sudo install -Dm755 "$bin" /usr/local/bin/tasker echo "Installed $bin -> /usr/local/bin/tasker" detect_shell() { if [ -n "$requested_shell" ]; then echo "$requested_shell" else basename "${SHELL:-}" fi } install_fish_completion() { if [ -f tasker.fish ]; then sudo install -Dm644 tasker.fish \ /usr/share/fish/vendor_completions.d/tasker.fish echo "Installed tasker.fish -> /usr/share/fish/vendor_completions.d/tasker.fish" else echo "Skipped fish completion: tasker.fish not found" fi } install_bash_completion() { if [ -f tasker.bash ]; then sudo install -Dm644 tasker.bash \ /usr/share/bash-completion/completions/tasker echo "Installed tasker.bash -> /usr/share/bash-completion/completions/tasker" else echo "Skipped bash completion: tasker.bash not found" fi } install_manpage() { if [ -f tasker.1 ]; then sudo install -Dm644 tasker.1 \ /usr/local/share/man/man1/tasker.1 sudo mandb 2>/dev/null || true echo "Installed tasker.1 -> /usr/local/share/man/man1/tasker.1" else echo "Skipped manpage: tasker.1 not found" fi } case "$(detect_shell)" in fish) install_fish_completion ;; bash) install_bash_completion ;; all) install_fish_completion install_bash_completion ;; none) echo "Skipped shell completions" ;; *) echo "Unsupported shell: ${requested_shell:-${SHELL:-unset}}" echo "Skipped shell completions" ;; esac if [ "$install_man" = true ]; then install_manpage fi