Skip to content
Merged
137 changes: 117 additions & 20 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,50 @@ zinit load starship/starship

# --- Core Libraries & Utilities ---
zinit wait lucid for \
OMZL::clipboard.zsh \
OMZP::extract \
OMZP::sudo \
OMZP::git \
MichaelAquilina/zsh-you-should-use

# clipboard
# Supports: macOS, Wayland, X11 (xclip/xsel), WSL 1/2, Cygwin, MSYS2
() {
if [[ $OSTYPE == darwin* ]]; then
pbcopy() { command pbcopy "$@"; }
pbpaste() { command pbpaste "$@"; }
elif [[ -n $WAYLAND_DISPLAY ]] && (( $+commands[wl-copy] )); then
pbcopy() { wl-copy "$@"; }
pbpaste() { wl-paste --no-newline "$@"; }
elif [[ -n $DISPLAY ]] && (( $+commands[xclip] )); then
pbcopy() { xclip -selection clipboard -in "$@"; }
pbpaste() { xclip -selection clipboard -out "$@"; }
elif [[ -n $DISPLAY ]] && (( $+commands[xsel] )); then
pbcopy() { xsel --clipboard --input "$@"; }
pbpaste() { xsel --clipboard --output "$@"; }
elif (( $+commands[wl-copy] )); then
pbcopy() { wl-copy "$@"; }
pbpaste() { wl-paste --no-newline "$@"; }
elif [[ $OSTYPE == linux* && -r /proc/version && "$(< /proc/version)" == *[Mm]icrosoft* ]]; then
pbcopy() { clip.exe; }
pbpaste() { powershell.exe -NoProfile -NonInteractive -Command Get-Clipboard | tr -d '\r'; }
elif [[ $OSTYPE == (cygwin*|msys) ]]; then
pbcopy() { tee > /dev/clipboard; }
pbpaste() { print -- "$(< /dev/clipboard)"; }
else
clip() {
print -u2 "clip: no clipboard backend detected on this system"
return 127
}
return 0
fi
clip() {
if [[ -t 0 ]]; then
pbpaste
else
pbcopy
fi
}
}
Comment on lines +54 to +68

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix clip control flow; current ternary pattern can misfire and block.

Line 69 uses A && B || C; if pbpaste fails, pbcopy runs unexpectedly. Also, Lines 65-67 leave clip undefined on unsupported systems.

🛠️ Suggested fix
   else
-    return 0  # No clipboard backend found; skip defining functions
+    clip() {
+      print -u2 "clip: no clipboard backend detected on this system"
+      return 127
+    }
+    return 0
   fi

-  clip() { [[ -t 0 ]] && pbpaste || pbcopy }
+  clip() {
+    if [[ -t 0 ]]; then
+      pbpaste
+    else
+      pbcopy
+    fi
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else
return 0 # No clipboard backend found; skip defining functions
fi
clip() { [[ -t 0 ]] && pbpaste || pbcopy }
}
else
clip() {
print -u2 "clip: no clipboard backend detected on this system"
return 127
}
return 0
fi
clip() {
if [[ -t 0 ]]; then
pbpaste
else
pbcopy
fi
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.zshrc around lines 65 - 70, Replace the fragile A && B || C expression in
the clip function with an explicit conditional: change clip() { [[ -t 0 ]] &&
pbpaste || pbcopy } to an if/then/else block (if [[ -t 0 ]]; then pbpaste; else
pbcopy; fi) so pbcopy does not run when pbpaste fails; also ensure clip is
always defined even on unsupported systems by removing the early return and
instead defining a no-op clip() { return 0; } (or a stub that exits non‑zero) in
the branch that detects “no clipboard backend found”, so callers never see an
undefined function.


# --- BAT (Cat replacement) ---
zinit ice as"program" from"gh-r" mv"bat* -> bat" pick"bat/bat" wait lucid
zinit load sharkdp/bat
Expand All @@ -47,8 +85,9 @@ zinit load sharkdp/fd
zinit ice as"program" from"gh-r" wait lucid \
atclone"./fzf --zsh > init.zsh" \
atpull"%atclone" \
src"init.zsh"
zinit load junegunn/fzf
src"init.zsh" \
atload'export FZF_DEFAULT_COMMAND="fd --type f --strip-cwd-prefix --hidden --follow --exclude .git"; export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"'
zinit light junegunn/fzf

# --- RIPGREP (Grep replacement) ---
zinit ice as"program" from"gh-r" mv"ripgrep* -> ripgrep" pick"ripgrep/rg" wait lucid
Expand All @@ -63,24 +102,27 @@ zinit ice as"program" from"gh-r" pick"zoxide" \
atclone"./zoxide init zsh --cmd cd > init.zsh" \
atpull"%atclone" \
src"init.zsh" nocompile"init.zsh"
zinit load ajeetdsouza/zoxide
zinit light ajeetdsouza/zoxide

# --- Completions, Suggestions & Highlighting ---

# 1. Load Completions First
# Load extra completions first
zinit wait lucid blockf atpull"zinit creinstall -q ." for \
zsh-users/zsh-completions

# 2. FZF-Tab (Replaces standard completion menu)
zinit wait lucid atinit"zicompinit; zicdreplay" \
atload'compdump="${ZSH_COMPDUMP:-${ZDOTDIR:-$HOME}/.zcompdump}"; [[ ! -s "${compdump}.zwc" || "$compdump" -nt "${compdump}.zwc" ]] && zcompile "$compdump" &!' \
for Aloxaf/fzf-tab

# 3. Syntax Highlighting (Must load after completions)
zinit wait lucid for zdharma-continuum/fast-syntax-highlighting
# IMPORTANT ORDER:
# compinit -> fzf-tab -> syntax-highlighting -> autosuggestions

# 4. Autosuggestions (Must load absolutely last)
zinit wait lucid atload"_zsh_autosuggest_start" for zsh-users/zsh-autosuggestions
zinit wait lucid \
atinit"zicompinit; zicdreplay" \
atload'compdump="${ZSH_COMPDUMP:-${ZDOTDIR:-$HOME}/.zcompdump}";
[[ ! -s "${compdump}.zwc" || "$compdump" -nt "${compdump}.zwc" ]] &&
zcompile "$compdump" &!' \
for Aloxaf/fzf-tab \
zdharma-continuum/fast-syntax-highlighting \
atload"_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions

# =============================================================================
# 4. CONFIGURATION
Expand All @@ -101,10 +143,6 @@ setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt AUTO_CD

# --- FZF Variables ---
export FZF_DEFAULT_COMMAND="fd --type f --strip-cwd-prefix --hidden --follow --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"

# --- Completion Styling (Replaces OMZL::completion.zsh) ---
# Case-insensitive matching (a matches A)
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*'
Expand All @@ -123,6 +161,8 @@ zstyle ':completion:*:descriptions' format '[%d]'
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always -- "$realpath"'
# Switch completion groups using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'
# Scroll in eza preview using Ctrl+j/k bindings
zstyle ':fzf-tab:*' fzf-flags --bind 'ctrl-j:preview-down' --bind 'ctrl-k:preview-up'

# =============================================================================
# 5. ALIASES & FUNCTIONS
Expand All @@ -135,10 +175,67 @@ alias ...='cd ../..'
alias md='mkdir -p'

# --- Quick Edits ---
alias sconf='${EDITOR:-nano} ~/.config/starship.toml'
alias zconf='${EDITOR:-nano} ~/.zshrc'
# Config shortcuts
_edit() {
local editor="${VISUAL:-${EDITOR:-$(command -v nano 2>/dev/null || command -v vi 2>/dev/null)}}"
if [[ -z "$editor" ]]; then
echo "No editor found (tried \$VISUAL, \$EDITOR, nano, vi)" >&2
return 1
fi
"$editor" "$@"
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

sconf() { _edit "${XDG_CONFIG_HOME:-$HOME/.config}/starship.toml" }
zconf() { _edit "${ZDOTDIR:-$HOME}/.zshrc" }
alias reload='exec zsh'

# --- Git Shortcuts ---

alias g='git'
alias ga='git add'
alias gaa='git add -A'
alias gc='git commit'
alias gcm='git commit -m'
alias gcam='git commit --amend'
alias gcb='git checkout -b'
alias gco='git checkout'
alias gd='git diff'
alias gds='git diff --staged'
alias gf='git fetch'
alias gl='git log --oneline --graph --decorate'
alias gla='git log --oneline --graph --decorate --all'
alias gm='git merge'
alias gp='git push'
alias gpf='git push --force-with-lease'
alias gpl='git pull'
alias gpr='git pull --rebase'
alias grb='git rebase'
alias grbi='git rebase -i'
alias grs='git restore'
alias grss='git restore --staged'
alias gs='git status'
alias gss='git status -s'
alias gst='git stash'
alias gstp='git stash pop'
alias gstl='git stash list'
alias gsw='git switch'
alias gswc='git switch -c'
alias gpsu='git push --set-upstream origin $(git branch --show-current)' # Push and set upstream in one go
alias gundo='git reset --soft HEAD~1' # Undo last commit but keep changes staged
alias gnuke='git reset --hard HEAD~1' # Nuke last commit and changes entirely
alias gbr='git branch --sort=-committerdate' # Show branches sorted by most recent commit

# Open the git repository's remote URL in the default web browser

gopen() {
local url=$(git remote get-url origin 2>/dev/null)
[[ -z "$url" ]] && echo "No remote 'origin' found" && return 1

url=$(echo "$url" | sed 's|^git@\(.*\):|https://\1/|; s|\.git$||')

open "$url" 2>/dev/null || xdg-open "$url" 2>/dev/null || { echo "Could not open: $url" >&2; return 1; }
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# --- Human readable disk usage ---
alias df='df -h'
alias du='du -h -d 1' # Disk usage depth 1
Expand Down
62 changes: 58 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
![Tealdeer](https://img.shields.io/badge/Docs-Tealdeer-%2320B2AA?style=flat-square&logo=rust&logoColor=white)
![Nerd Fonts](https://img.shields.io/badge/Nerd_Fonts-%23333333.svg?style=flat-square&logo=nerdfonts&logoColor=white)
![Git](https://img.shields.io/badge/git-%23F05033.svg?style=flat-square&logo=git&logoColor=white)
![Zsh Startup Time](https://img.shields.io/badge/Startup_Time-%3C70ms-success?style=flat-square&logo=zsh)
![Zsh Interactive Prompt Time](https://img.shields.io/badge/Startup_Time-%3C69ms-success?style=flat-square&logo=zsh)
![Input Lag](https://img.shields.io/badge/Input_Lag-~3ms-blue?style=flat-square)
[![Z-Shift CI](https://github.com/0xdilshan/Z-SHIFT/actions/workflows/ci.yml/badge.svg)](https://github.com/0xdilshan/Z-SHIFT/actions/workflows/ci.yml)

Expand All @@ -28,11 +28,11 @@ It handles the heavy lifting of installing a modern plugin manager, configuring

<div align="center">

[![asciicast](https://asciinema.org/a/qVjPp58itF6FGrI6.svg)](https://asciinema.org/a/qVjPp58itF6FGrI6)
<a href="https://asciinema.org/a/lfoK4Wtcqwo6bJsK" target="_blank"><img src="https://asciinema.org/a/lfoK4Wtcqwo6bJsK.svg" alt="Z-SHIFT terminal demo recording" /></a>

***🚅 High-Performance Zsh + 🌸Gruvbox + ⚡ Zinit + Extra Goodies Installer***

***⚡ ~20ms core startup time with a total time-to-prompt of under 70ms.***
***⚡ ~20ms core startup time with a total time-to-prompt of under 69ms.***

</div>

Expand All @@ -44,6 +44,7 @@ It handles the heavy lifting of installing a modern plugin manager, configuring
- [💿 Installation](#-installation)
+ [One-Line Install](#one-line-install)
+ [Manual Install](#manual-install)
- [📥 Update z-shift](#-update)
- [🗑️ Uninstall Z-SHIFT](#uninstall-z-shift)
- [🎨 Change Themes](#-change-themes)
- [📦 Plugin Ecosystem](#-plugin-ecosystem)
Expand Down Expand Up @@ -103,6 +104,17 @@ chmod +x install.sh
```
------------

## 📥 Update

Run the alias below to update to the latest `.zshrc` config.

```bash
zsu
```


------------

## Uninstall Z-SHIFT


Expand Down Expand Up @@ -141,6 +153,48 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/0xdilshan/Z-SHIFT/main/t
- **Autosuggestions:** Fish-style inline suggestions powered by `zsh-autosuggestions`.
- **Clipboard:** Cross-platform clipboard integration.

<details open>

<summary>clip command usage examples:</summary>

**Copying to the clipboard**

```bash
# Copy a string directly
echo "This is now in my clipboard" | clip

# Copy the contents of a file
cat ~/.ssh/id_rsa.pub | clip

# Copy the output of a command
ls -la | clip
```

**Pasting from the clipboard**

```bash
# Paste clipboard contents directly into the terminal
clip

# Paste clipboard contents into a new file
clip > pasted_data.txt

# Pipe clipboard contents into another command
clip | grep "error"
```

**Advanced Chaining**

```bash
# Read clipboard, convert to lowercase, and copy the result back to clipboard
clip | tr 'A-Z' 'a-z' | clip

# Format JSON currently in the clipboard and copy it back
clip | jq . | clip
```

</details>

- ### Power Utilities

- **extract:** One command to decompress almost any archive file (`.tar`, `.zip`, `.gz`, etc.).
Expand All @@ -167,7 +221,7 @@ Optimized for speed and low latency. Benchmarked using [zsh-bench](https://githu
| Metric | Time |
| :--- | :--- |
| **First Prompt** | `~69 ms` 🚀 |
| **Command Lag** | `~70 ms` |
| **Command Lag** | `~55 ms` |
| **Input Lag** | `~3 ms` |

![benchmark](benchmark/z-shift-bench.webp)
Expand Down
Binary file modified benchmark/z-shift-bench.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.