Last active
December 15, 2025 13:29
-
-
Save asmoura/c6a839311e8b3314f6cb93094213525c to your computer and use it in GitHub Desktop.
zshrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function zplug_init() { | |
| local ZPLUG_DIR="" | |
| local ZPLUG_HOME="$HOME/.zplug" | |
| local package_manager="" | |
| # Install fonts | |
| # mkdir ~/powerline-fonts | |
| # cd ~/powerline-fonts | |
| # git clone https://github.com/powerline/fonts.git . | |
| # ./install.sh | |
| # Check for APT (Debian/Ubuntu) | |
| if [ -f /etc/os-release ] && command -v apt-cache >/dev/null 2>&1; then | |
| if dpkg -l 2>/dev/null | grep -qw "zplug"; then | |
| ZPLUG_DIR="/usr/share/zplug" | |
| package_manager="APT" | |
| fi | |
| fi | |
| # Check for Homebrew (macOS/Linux) | |
| if [ -z "$ZPLUG_DIR" ] && command -v brew >/dev/null 2>&1; then | |
| if brew list zplug >/dev/null 2>&1; then | |
| ZPLUG_DIR="$(brew --prefix)/opt/zplug" | |
| package_manager="Homebrew" | |
| fi | |
| fi | |
| # Check for FreeBSD and offer source installation | |
| if [ -z "$ZPLUG_DIR" ] && [ "$(uname -s)" = "FreeBSD" ]; then | |
| ZPLUG_SOURCE_DIR="$HOME/.zplug-source" | |
| # Check if already installed from source | |
| if [ -d "$ZPLUG_SOURCE_DIR" ] && [ -f "$ZPLUG_SOURCE_DIR/init.zsh" ]; then | |
| ZPLUG_DIR="$ZPLUG_SOURCE_DIR" | |
| package_manager="FreeBSD (source)" | |
| else | |
| # Offer to install from source | |
| echo "Zplug not found on FreeBSD." | |
| printf "Would you like to install zplug from source? (Y/n): " | |
| read -r response | |
| if [ "$response" != "n" ] && [ "$response" != "N" ]; then | |
| echo "Installing zplug from source..." | |
| # Method 1: Official installer (preferred) | |
| if command -v curl >/dev/null 2>&1; then | |
| export ZPLUG_HOME="$ZPLUG_SOURCE_DIR" | |
| if curl -sL --proto-redir -all,https \ | |
| https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh; then | |
| ZPLUG_DIR="$ZPLUG_SOURCE_DIR" | |
| package_manager="FreeBSD (source)" | |
| echo "✓ Zplug installed successfully via official installer" | |
| else | |
| echo "✗ Official installer failed, trying git clone..." | |
| unset ZPLUG_HOME | |
| fi | |
| fi | |
| # Method 2: Git clone fallback | |
| if [ -z "$ZPLUG_DIR" ] && command -v git >/dev/null 2>&1; then | |
| mkdir -p "$ZPLUG_SOURCE_DIR" | |
| if git clone https://github.com/zplug/zplug "$ZPLUG_SOURCE_DIR"; then | |
| ZPLUG_DIR="$ZPLUG_SOURCE_DIR" | |
| package_manager="FreeBSD (source)" | |
| echo "✓ Zplug installed successfully via git clone" | |
| else | |
| echo "✗ Git clone failed" | |
| rm -rf "$ZPLUG_SOURCE_DIR" | |
| fi | |
| fi | |
| # Check if installation succeeded | |
| if [ -z "$ZPLUG_DIR" ]; then | |
| echo "✗ Failed to install zplug. Please install manually:" | |
| echo " curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh" | |
| return 1 | |
| fi | |
| else | |
| echo "Skipping zplug installation." | |
| return 1 | |
| fi | |
| fi | |
| fi | |
| # Exit if zplug not found | |
| if [ -z "$ZPLUG_DIR" ]; then | |
| echo "Zplug is not installed via APT, Homebrew, or FreeBSD source." | |
| return 1 | |
| fi | |
| # Verify init.zsh exists | |
| if [ ! -f "$ZPLUG_DIR/init.zsh" ]; then | |
| echo "Zplug found via $package_manager, but init.zsh not found at $ZPLUG_DIR" | |
| return 1 | |
| fi | |
| # Verify zoxide exists | |
| if [ -f /etc/os-release ] && command -v apt-cache >/dev/null 2>&1; then | |
| if dpkg -l 2>/dev/null | grep -qw "zoxide"; then | |
| echo "zoxide found installed via APT" | |
| else | |
| echo "zoxide not found. Installing zoxide via APT..." | |
| sudo apt update && sudo apt install -y zoxide | |
| # sudo rootsh apt update && sudo rootsh apt install -y zoxide | |
| fi | |
| fi | |
| if command -v brew >/dev/null 2>&1; then | |
| if brew list zoxide >/dev/null 2>&1; then | |
| echo "zoxide found installed via Homebrew" | |
| else | |
| echo "zoxide not found. Installing zoxide via Homebrew..." | |
| brew install zoxide | |
| fi | |
| fi | |
| # Check for FreeBSD pkg manager | |
| if [ "$(uname -s)" = "FreeBSD" ] && command -v pkg >/dev/null 2>&1; then | |
| if pkg info zoxide >/dev/null 2>&1; then | |
| echo "zoxide found installed via FreeBSD pkg" | |
| else | |
| echo "zoxide not found. Installing zoxide via FreeBSD pkg..." | |
| sudo pkg install -y zoxide | |
| fi | |
| fi | |
| # Set ZPLUG_HOME and source init | |
| if [ ! -d "${ZPLUG_HOME}" ]; then | |
| echo "Creating ${ZPLUG_HOME} directory..." | |
| mkdir -p ${ZPLUG_HOME} | |
| echo "Copying $ZPLUG_DIR to ${ZPLUG_HOME} with permissions set for the user:" | |
| cp -R $ZPLUG_DIR/* $ZPLUG_HOME && chown -R $(id -u):$(id -g) $ZPLUG_HOME | |
| find $ZPLUG_HOME -type f -name '*.sh' -exec chmod +x {} \; | |
| find $ZPLUG_HOME -type f -name '*.zsh' -exec chmod +x {} \; | |
| else | |
| source "$ZPLUG_HOME/init.zsh" | |
| # Load plugins | |
| zplug "plugins/git", from:oh-my-zsh | |
| zplug "plugins/sudo", from:oh-my-zsh | |
| zplug "plugins/command-not-found", from:oh-my-zsh | |
| zplug "plugins/colored-man-pages", from:oh-my-zsh | |
| zplug "plugins/colorize", from:oh-my-zsh | |
| zplug "plugins/debian", from:oh-my-zsh | |
| zplug "plugins/deno", from:oh-my-zsh | |
| zplug "plugins/docker", from:oh-my-zsh | |
| zplug "plugins/docker-compose", from:oh-my-zsh | |
| zplug "plugins/emoji", from:oh-my-zsh | |
| zplug "plugins/emoji-clock", from:oh-my-zsh | |
| zplug "plugins/emotty", from:oh-my-zsh | |
| zplug "plugins/eza", from:oh-my-zsh | |
| zplug "plugins/gh", from:oh-my-zsh | |
| zplug "plugins/git-auto-fetch", from:oh-my-zsh | |
| zplug "plugins/git-commit", from:oh-my-zsh | |
| zplug "plugins/grc", from:oh-my-zsh | |
| zplug "plugins/history", from:oh-my-zsh | |
| zplug "plugins/history-substring-search", from:oh-my-zsh | |
| zplug "plugins/isodate", from:oh-my-zsh | |
| zplug "plugins/lxd", from:oh-my-zsh | |
| zplug "plugins/man", from:oh-my-zsh | |
| zplug "plugins/rclone", from:oh-my-zsh | |
| zplug "plugins/rsync", from:oh-my-zsh | |
| zplug "plugins/safe-paste", from:oh-my-zsh | |
| zplug "plugins/ssh", from:oh-my-zsh | |
| zplug "plugins/ssh-agent", from:oh-my-zsh | |
| zplug "plugins/systemd", from:oh-my-zsh | |
| zplug "plugins/taskwarrior", from:oh-my-zsh | |
| zplug "plugins/tldr", from:oh-my-zsh | |
| zplug "plugins/transfer", from:oh-my-zsh | |
| zplug "plugins/z", from:oh-my-zsh | |
| zplug "plugins/zsh-interactive-cd", from:oh-my-zsh | |
| zplug "plugins/zsh-navigation-tools", from:oh-my-zsh | |
| zplug "plugins/ssh-warrior", from:oh-my-zsh | |
| zplug "zsh-users/zsh-syntax-highlighting" | |
| zplug "zsh-users/zsh-autosuggestions" | |
| zplug "zsh-users/zsh-history-substring-search" | |
| zplug "zsh-users/zsh-completions" | |
| zplug "junegunn/fzf" | |
| zplug "chrissicool/zsh-256color" | |
| zplug "romkatv/powerlevel10k", as:theme, use:"powerlevel10k.zsh-theme" | |
| zplug "plugins/zoxide", from:oh-my-zsh | |
| # Install missing plugins | |
| if ! zplug check --verbose; then | |
| printf "Install missing plugins? [y/N]: " | |
| if read -q; then | |
| echo | |
| zplug install | |
| fi | |
| fi | |
| # Load all plugins | |
| zplug load | |
| fi | |
| } | |
| echo "Initializing zplug..." | |
| zplug_init | |
| echo "zplug initialized." | |
| # Load custom user functions, if file exists | |
| if [[ -f "$HOME/.local/bin/functions" ]] ; then | |
| . $HOME/.local/bin/functions | |
| fi | |
| # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. | |
| # Initialization code that may require console input (password prompts, [y/n] | |
| # confirmations, etc.) must go above this block; everything else may go below. | |
| if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then | |
| source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" | |
| fi | |
| # Set path if required | |
| #export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH | |
| # Aliases | |
| alias ls='ls --color=auto' | |
| alias ll='ls -lah --color=auto' | |
| alias grep='grep --color=auto' | |
| alias ec="$EDITOR $HOME/.zshrc" # edit .zshrc | |
| alias sc="source $HOME/.zshrc" # reload zsh configuration | |
| # Set up the prompt - if you load Theme with zplugin as in this example, this will be overriden by the Theme. If you comment out the Theme in zplugins, this will be loaded. | |
| autoload -Uz promptinit | |
| promptinit | |
| prompt adam1 # see Zsh Prompt Theme below | |
| # Use emacs keybindings even if our EDITOR is set to vi | |
| bindkey -e | |
| setopt histignorealldups sharehistory | |
| # Keep 5000 lines of history within the shell and save it to ~/.zsh_history: | |
| HISTSIZE=100000 | |
| SAVEHIST=500000 | |
| HISTFILE=~/.zsh_history | |
| # Use modern completion system | |
| autoload -Uz compinit | |
| compinit | |
| # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. | |
| [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh | |
| # typeset -g POWERLEVEL9K_INSTANT_PROMPT=off |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Making gist public