Skip to content

feat: added clipboard utils installation & better os detection#12

Merged
0xdilshan merged 6 commits into
mainfrom
dev
Feb 28, 2026
Merged

feat: added clipboard utils installation & better os detection#12
0xdilshan merged 6 commits into
mainfrom
dev

Conversation

@0xdilshan

@0xdilshan 0xdilshan commented Feb 28, 2026

Copy link
Copy Markdown
Owner

Summary

This PR enhances the shell setup by introducing a convenient alias for managing .zshrc.local, along with improved OS detection and automatic clipboard utilities installation.


✨ Changes

1. Added alias for .zshrc.local

  • Introduced a shortcut alias to quickly open/edit .zshrc.local.
  • Improves developer workflow when customizing local shell configuration.

2. Clipboard utilities installation

  • Added automatic installation logic for clipboard tools:
    • pbcopy (macOS)
    • xclip / xsel (Linux)
  • Reduces manual setup steps.

3. Improved OS detection

  • Enhanced OS detection logic for better cross-platform compatibility.
  • Ensures correct clipboard tool installation based on environment.

🧪 Testing

  • Verified alias works correctly in interactive Zsh.
  • Tested clipboard functionality on:
    • macOS
    • Linux
  • Confirmed OS detection behaves as expected.

Summary by CodeRabbit

  • New Features

    • Added a quick command to open the local shell configuration for easy edits.
    • Installer now resolves major distro families and adapts package flows; macOS Homebrew environment is better detected and applied.
    • Improved clipboard handling: detects Wayland vs X11 vs headless and verifies installation of suitable tools.
  • Chores

    • Expanded common dependencies (including gnupg) and enhanced installer error messaging, fallbacks, and post-install verification.

@coderabbitai

coderabbitai Bot commented Feb 28, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@0xdilshan has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 57ab800 and 0c527e5.

📒 Files selected for processing (1)
  • install.sh
📝 Walkthrough

Walkthrough

Adds a new zlocal() helper to .zshrc for editing a local Zsh config. install.sh gains distro-family resolution (_resolve_distro_familyDISTRO_FAMILY), standardizes package installation by family, improves macOS Homebrew path handling, and enhances Wayland/X11/headless clipboard-tool detection/installation.

Changes

Cohort / File(s) Summary
Shell Configuration
\.zshrc
Added zlocal() helper: zlocal() { _edit "${ZDOTDIR:-$HOME}/.zshrc.local" }, alongside existing config-edit helpers.
Installer Script
install.sh
Introduced _resolve_distro_family() and DISTRO_FAMILY (debian/arch/fedora/suse/unknown); switched package install dispatch to family-based managers (apt/pacman/dnf/zypper); expanded COMMON_DEPS (adds gnupg); improved macOS Homebrew env handling for /opt/homebrew and /usr/local; enhanced clipboard detection and installation (wl-clipboard vs xclip, headless fallback) and added post-install verification and clearer unsupported-family errors.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Installer as "install.sh"
    participant OS as "OS Detection"
    participant Resolver as "Family Resolver"
    participant Pkg as "Package Manager"
    participant Clipboard as "Clipboard Detection"
    participant System

    User->>Installer: run install script
    Installer->>OS: detect platform (/etc/os-release, uname)
    OS-->>Resolver: provide ID / ID_LIKE
    Resolver->>Resolver: _resolve_distro_family()
    Resolver-->>Installer: DISTRO_FAMILY

    alt DISTRO_FAMILY = debian
        Installer->>Pkg: use apt-get / apt
    else DISTRO_FAMILY = arch
        Installer->>Pkg: use pacman
    else DISTRO_FAMILY = fedora
        Installer->>Pkg: use dnf
    else DISTRO_FAMILY = suse
        Installer->>Pkg: use zypper
    else DISTRO_FAMILY = unknown
        Installer->>System: emit error + list required packages
    end

    Installer->>Clipboard: detect Wayland / X11 / headless
    alt Wayland
        Clipboard-->>Installer: select wl-clipboard
    else X11
        Clipboard-->>Installer: select xclip
    else Headless
        Clipboard-->>Installer: select xclip & wl-clipboard
    end

    Installer->>Pkg: install COMMON_DEPS + clipboard tools
    Pkg->>System: deploy packages
    System-->>Installer: report install result
Loading

Estimated Code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I hop to dotfiles, nibble a line,
zlocal opens where local configs shine.
Distros sorted, clipboards set in tune,
Brew paths found beneath the moon.
Tiny hops — tidy configs soon! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding clipboard utilities installation and improving OS detection logic, both of which are prominent in the PR objectives and code modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
install.sh (2)

152-156: Minor: Identical branches can be unified.

Both branches call install_pkg "${COMMON_DEPS[@]}" identically, making the conditional unnecessary.

♻️ Proposed simplification
-if [[ "$OS_TYPE" == "macos" ]]; then
-    install_pkg "${COMMON_DEPS[@]}"
-else
-    install_pkg "${COMMON_DEPS[@]}"
-fi
+install_pkg "${COMMON_DEPS[@]}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@install.sh` around lines 152 - 156, The conditional checking OS_TYPE around
calling install_pkg with COMMON_DEPS is redundant because both branches execute
identical code; remove the if/else and call install_pkg "${COMMON_DEPS[@]}"
directly (eliminate the OS_TYPE check and associated branching so only a single
invocation of install_pkg with COMMON_DEPS remains).

169-191: Simplify redundant case statements.

All distro families install identical packages (wl-clipboard, xclip). The case statements can be collapsed since install_pkg already handles distro-specific logic.

♻️ Proposed simplification
     if [[ -n "${WAYLAND_DISPLAY:-}" ]]; then
         echo -e "${BLUE}Wayland detected — installing wl-clipboard${NC}"
-        case "$DISTRO_FAMILY" in
-            debian) install_pkg wl-clipboard ;;
-            arch)   install_pkg wl-clipboard ;;
-            fedora) install_pkg wl-clipboard ;;
-            suse)   install_pkg wl-clipboard ;;
-        esac
+        install_pkg wl-clipboard
     elif [[ -n "${DISPLAY:-}" ]]; then
         echo -e "${BLUE}X11 detected — installing xclip${NC}"
-        case "$DISTRO_FAMILY" in
-            debian) install_pkg xclip ;;
-            arch)   install_pkg xclip ;;
-            fedora) install_pkg xclip ;;
-            suse)   install_pkg xclip ;;
-        esac
+        install_pkg xclip
     else
         # Headless / TTY-only: install both so the env is ready for either
         echo -e "${YELLOW}No display server detected (headless/TTY) — installing xclip + wl-clipboard as fallback${NC}"
-        case "$DISTRO_FAMILY" in
-            debian) install_pkg xclip wl-clipboard ;;
-            arch)   install_pkg xclip wl-clipboard ;;
-            fedora) install_pkg xclip wl-clipboard ;;
-            suse)   install_pkg xclip wl-clipboard ;;
-        esac
+        install_pkg xclip wl-clipboard
     fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@install.sh` around lines 169 - 191, Collapse the repeated case branches by
calling install_pkg directly for the required packages instead of branching on
DISTRO_FAMILY each time; replace the three identical case blocks (the ones that
install wl-clipboard when WAYLAND_DETECTED, xclip when DISPLAY is set, and both
when headless) with direct calls like install_pkg wl-clipboard, install_pkg
xclip, and install_pkg xclip wl-clipboard respectively, keeping the
DISPLAY/Wayland detection logic and referencing the existing DISTRO_FAMILY
variable only if install_pkg needs it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@install.sh`:
- Around line 68-95: The distro family resolver fails to map macOS; update
_resolve_distro_family so that when id is "macos" (and optionally when id_like
contains "macos" or "darwin") it echoes "macos" instead of falling through to
"unknown". Modify the top-level case in _resolve_distro_family to include macos
in the id matches and add a corresponding branch in the id_like fallback,
ensuring DISTRO_FAMILY="$( _resolve_distro_family "$DISTRO" "$DISTRO_LIKE" )"
will be "macos" so install_pkg uses the Homebrew path correctly.
- Around line 167-175: The script currently references WAYLAND_DISPLAY and
DISPLAY directly while run under set -u, causing failures when those env vars
are unset; update the conditionals to use safe parameter expansion (e.g.,
${WAYLAND_DISPLAY:-} and ${DISPLAY:-}) wherever they are read (the if [[ -n
"$WAYLAND_DISPLAY" ]] and elif [[ -n "$DISPLAY" ]] checks) so they default to
empty strings, preserving behavior of the install_pkg calls (wl-clipboard) and
still respecting DISTRO_FAMILY and install_pkg logic.

---

Nitpick comments:
In `@install.sh`:
- Around line 152-156: The conditional checking OS_TYPE around calling
install_pkg with COMMON_DEPS is redundant because both branches execute
identical code; remove the if/else and call install_pkg "${COMMON_DEPS[@]}"
directly (eliminate the OS_TYPE check and associated branching so only a single
invocation of install_pkg with COMMON_DEPS remains).
- Around line 169-191: Collapse the repeated case branches by calling
install_pkg directly for the required packages instead of branching on
DISTRO_FAMILY each time; replace the three identical case blocks (the ones that
install wl-clipboard when WAYLAND_DETECTED, xclip when DISPLAY is set, and both
when headless) with direct calls like install_pkg wl-clipboard, install_pkg
xclip, and install_pkg xclip wl-clipboard respectively, keeping the
DISPLAY/Wayland detection logic and referencing the existing DISTRO_FAMILY
variable only if install_pkg needs it.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34fd2f9 and f04a5a1.

📒 Files selected for processing (2)
  • .zshrc
  • install.sh

Comment thread install.sh Outdated
Comment thread install.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
install.sh (1)

68-95: ⚠️ Potential issue | 🔴 Critical

DISTRO_FAMILY still misses macOS mapping, which breaks package installs on macOS.

At Line 73 and Line 84, _resolve_distro_family never returns macos, so macOS resolves to unknown and hits the unsupported branch in install_pkg.

🐛 Proposed fix
 _resolve_distro_family() {
     local id="$1"
     local id_like="$2"

     case "$id" in
+        macos|darwin)
+            echo "macos" ;;
         ubuntu|debian|pop|kali|linuxmint|raspbian|elementary|zorin)
             echo "debian" ;;
         arch|manjaro|endeavouros|garuda|artix)
             echo "arch" ;;
         fedora|rhel|centos|rocky|almalinux|nobara)
             echo "fedora" ;;
         opensuse*|suse*)
             echo "suse" ;;
         *)
             case "$id_like" in
+                *macos*|*darwin*)  echo "macos"  ;;
                 *debian*|*ubuntu*) echo "debian" ;;
                 *arch*)            echo "arch"   ;;
                 *fedora*|*rhel*)   echo "fedora" ;;
                 *suse*)            echo "suse"   ;;
                 *)                 echo "unknown" ;;
             esac
             ;;
     esac
 }

Also applies to: 101-123

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@install.sh` around lines 68 - 95, The distro detection routine
_resolve_distro_family fails to map macOS, causing DISTRO_FAMILY to be "unknown"
and breaking install_pkg; update _resolve_distro_family to return "macos" for
macOS identifiers (e.g., match "darwin", "macos", "macosx", "macos*" as
appropriate) in the outer case and also include a fallback in the ID_LIKE inner
case (match "*macos*" or "*darwin*"); ensure references to DISTRO_FAMILY and any
logic in install_pkg that checks for "macos" will now work by adding this
mapping to the function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@install.sh`:
- Around line 101-115: The package installation commands inside install_pkg (the
case on DISTRO_FAMILY using pkgs) currently run without checking failure; change
each package-manager invocation (apt-get, pacman, dnf, zypper) so that failures
are propagated (e.g., chain operations with && or test the command exit status)
and ensure the case block itself exits non‑zero on failure: after the install
command for each distro, add a failure check that logs an error and exits (or
simply use && to make the whole operation fail), and add a final fallback/error
handler in the case statement so install_pkg returns non‑zero and prints a clear
message when a package manager command fails.

---

Duplicate comments:
In `@install.sh`:
- Around line 68-95: The distro detection routine _resolve_distro_family fails
to map macOS, causing DISTRO_FAMILY to be "unknown" and breaking install_pkg;
update _resolve_distro_family to return "macos" for macOS identifiers (e.g.,
match "darwin", "macos", "macosx", "macos*" as appropriate) in the outer case
and also include a fallback in the ID_LIKE inner case (match "*macos*" or
"*darwin*"); ensure references to DISTRO_FAMILY and any logic in install_pkg
that checks for "macos" will now work by adding this mapping to the function.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f04a5a1 and 32c8303.

📒 Files selected for processing (1)
  • install.sh

Comment thread install.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
install.sh (1)

106-130: ⚠️ Potential issue | 🟠 Major

Propagate package-manager failures in install_pkg().

Because Line 16 uses set -uo pipefail (without set -e), failures in Lines 109–123 can be ignored and the script may continue in a partially installed state.

Proposed fix
 install_pkg() {
     local pkgs=("$@")
     echo -e "${YELLOW}Installing: ${pkgs[*]}...${NC}"

     case "$DISTRO_FAMILY" in
         debian)
             export DEBIAN_FRONTEND=noninteractive
-            sudo apt-get update -qq -y > /dev/null
-            sudo apt-get install -qq -y "${pkgs[@]}" > /dev/null
+            sudo apt-get update -qq -y > /dev/null &&
+            sudo apt-get install -qq -y "${pkgs[@]}" > /dev/null
             ;;
         arch)
-            sudo pacman -Sy --quiet --noconfirm --needed "${pkgs[@]}" > /dev/null
+            sudo pacman -Sy --quiet --noconfirm --needed "${pkgs[@]}" > /dev/null
             ;;
         fedora)
-            sudo dnf install -q -y "${pkgs[@]}" > /dev/null
+            sudo dnf install -q -y "${pkgs[@]}" > /dev/null
             ;;
         suse)
-            sudo zypper install -q -y "${pkgs[@]}" > /dev/null
+            sudo zypper install -q -y "${pkgs[@]}" > /dev/null
             ;;
         macos)
-            brew install -q "${pkgs[@]}" > /dev/null
+            brew install -q "${pkgs[@]}" > /dev/null
             ;;
         *)
             echo -e "${RED}Unsupported distribution: ${DISTRO} (family: ${DISTRO_FAMILY})${NC}"
             echo -e "${RED}Please install the following packages manually: ${pkgs[*]}${NC}"
             exit 1
             ;;
-    esac
+    esac || {
+        echo -e "${RED}Package installation failed: ${pkgs[*]}${NC}"
+        exit 1
+    }
 }
#!/bin/bash
# Read-only verification: confirm install_pkg lacks explicit failure propagation.
set -u
FILE="$(fd '^install\.sh$' | head -n1)"
nl -ba "$FILE" | sed -n '100,132p'
echo "---- sanity checks ----"
rg -n 'set -uo pipefail|set -e|esac \|\||apt-get update .*&&|apt-get install .*&&|pacman .*&&|dnf .*&&|zypper .*&&|brew install .*&&' "$FILE"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@install.sh` around lines 106 - 130, install_pkg() currently runs distro
package commands under set -uo pipefail without failing the script on errors;
update it so package-manager failures propagate by either enabling errexit for
the function (e.g., start install_pkg() with set -euo pipefail or local +e and
restore) or add explicit failure checks to each branch (append || { echo "Failed
to install ${pkgs[*]} via <manager>"; exit 1; } to the apt-get update/install,
pacman, dnf, zypper and brew commands). Reference install_pkg, DISTRO_FAMILY,
and the package command invocations (apt-get update/install, pacman -Sy, dnf
install, zypper install, brew install) when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@install.sh`:
- Around line 106-130: install_pkg() currently runs distro package commands
under set -uo pipefail without failing the script on errors; update it so
package-manager failures propagate by either enabling errexit for the function
(e.g., start install_pkg() with set -euo pipefail or local +e and restore) or
add explicit failure checks to each branch (append || { echo "Failed to install
${pkgs[*]} via <manager>"; exit 1; } to the apt-get update/install, pacman, dnf,
zypper and brew commands). Reference install_pkg, DISTRO_FAMILY, and the package
command invocations (apt-get update/install, pacman -Sy, dnf install, zypper
install, brew install) when making the change.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32c8303 and 57ab800.

📒 Files selected for processing (1)
  • install.sh

@0xdilshan
0xdilshan merged commit 01b9168 into main Feb 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant