diff --git a/.zshrc b/.zshrc index 073515c..169ada3 100644 --- a/.zshrc +++ b/.zshrc @@ -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 + } +} + # --- BAT (Cat replacement) --- zinit ice as"program" from"gh-r" mv"bat* -> bat" pick"bat/bat" wait lucid zinit load sharkdp/bat @@ -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 @@ -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 @@ -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:|=*' @@ -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 @@ -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" "$@" +} + +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; } +} + # --- Human readable disk usage --- alias df='df -h' alias du='du -h -d 1' # Disk usage depth 1 diff --git a/README.md b/README.md index ffe034b..b1282c8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -28,11 +28,11 @@ It handles the heavy lifting of installing a modern plugin manager, configuring
-[![asciicast](https://asciinema.org/a/qVjPp58itF6FGrI6.svg)](https://asciinema.org/a/qVjPp58itF6FGrI6) +Z-SHIFT terminal demo recording ***🚅 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.***
@@ -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) @@ -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 @@ -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. +
+ +clip command usage examples: + +**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 +``` + +
+ - ### Power Utilities - **extract:** One command to decompress almost any archive file (`.tar`, `.zip`, `.gz`, etc.). @@ -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) diff --git a/benchmark/z-shift-bench.webp b/benchmark/z-shift-bench.webp index 758ec6f..c2b4174 100644 Binary files a/benchmark/z-shift-bench.webp and b/benchmark/z-shift-bench.webp differ