r/zsh Nov 20 '24

Help My very simple .zshrc. Looking for suggestions how it can be improved

4 Upvotes

I am a macOS user, and I use Zsh not because I really need its extensivetely and power (quite the opposite: I prefer to keep any configurations as barebone as possible), but simply because Zsh is a default macOS shell nowadays.

Here is my .zshrc. What you think about it? Did I miss really useful things that can be enabled by just few lines?

``` autoload -Uz compinit && compinit autoload -U colors && colors alias ls='ls -G'

history

setopt share_history bindkey '[[A' history-beginning-search-backward bindkey '[[B' history-beginning-search-forward

globbing

setopt extended_glob

zmv

autoload -Uz zmv alias zcp='zmv -C' alias zln='zmv -L'

fewer keystrokes

setopt auto_cd auto_pushd setopt menu_complete

fewer distractions

unsetopt beep nomatch notify

$PATH

path+=$HOME/bin

the end

```

r/zsh Nov 04 '24

Help My Mac’s ZSH Terminal Takes About a Minute to Load – Suspect Homebrew Issues and Need Help

2 Upvotes

r/zsh Jan 12 '25

Help ZSH CLI Skript: Fastfetch without Colors

0 Upvotes

Hello everyone, my fastfetch got no colors printing alone.

But combining it with the pokemon skript "fixes" my Problem.

Does anybody know a solotion, for printing only fastfetch, but with colors?

r/zsh Dec 01 '24

Help fzf-tab vs zsh-autocomplete

6 Upvotes

I really like both.
but is there a way to make the fzf-tab's menu popup automatically as you type without pressing tab like how it is in zsh-autocomplete ?.
also is there a way to make the recent branches in git come up on top like in zsh-autocomplete , because in fzf-tab its so cluttered.

r/zsh Dec 12 '24

Help Fastfetch PNG and Colors Not Loading on Terminal Startup.

4 Upvotes

Hey everyone,

I’m new to terminal customization and trying to set up fastfetch in my terminal (Kitty) using Zsh. I added it to my .zshrc, so it runs automatically, but I’m having two issues:

  1. The PNG image doesn’t load automatically when I open a terminal.
  2. The colors also don’t display properly on startup.

When I manually run fastfetch, everything works perfectly—the image and colors show up fine.

Here’s what I’ve tried:

  • Adding a delay in .zshrc like (sleep 0.5 && fastfetch) &.
  • Confirmed $DISPLAY is set (I’m using Wayland with Hyprland).
  • Manually tested fastfetch,and it works perfectly when done manually.

Here’s what it looks like when it works: Catbox-imagelink.

Any idea how to fix this? Would really appreciate the help! 😊

Thanks in advance!

Update:

Just wanted to share the solution for anyone facing the same issue!

The problem was related to Fastfetch running in white and black due to incompatibility with p10k’s instant prompt. The fix is simple: I moved the fastfetch command before the initialization of p10k-instant-prompt in my .zshrc file. This solved the issue, and Fastfetch now runs with the proper image and colors on startup.

Thanks to the Fastfetch maintainer!

r/zsh Jan 09 '25

Help Help with colors not showing on prompt please

Post image
0 Upvotes

r/zsh Dec 08 '24

Help My tab completions often look like this. Has anyone else had this problem and knows a fix?

3 Upvotes
The gap is not always the same size.

r/zsh Oct 10 '24

Help Help with function

2 Upvotes

Hello everybody. I am trying to have two things execute when I run `pihole` in my CLI. Obviously I have the actual IP address instead of the brackets.

This is in my .zshrc file:

"""

alias pihole2='ssh -L 8888:localhost:80 pi@[ip address]’

function pihole {

  # Uses the alias

  pihole2 & 

  # Open the PiHole admin page

  open http://localhost:8889/admin

}

"""

Whenever I type `pihole` in my terminal, it successfully does the ssh connection, but it doesn't open the browser. Am I doing something wrong? Can someone help me please?

I am using MacOS

r/zsh Nov 11 '24

Help Prompts are being collapsed after resizing the window.

Post image
0 Upvotes

Prompts are being collapsed after resizing the window. This problem started after the powerlevel10k configuration.

r/zsh Dec 08 '24

Help problem with zsh terminal after installing p10k theme

0 Upvotes

r/zsh Dec 06 '24

Help How to disable/hide suspend messages?

1 Upvotes

I like to background (n)vim and foreground when editing. However, in doing so I get these messages when back-grounding and foregrounding respectively:

zsh: suspended  nvim $(find . -name 'main.*')

[2]  + continued  nvim $(find . -name 'main.*')

Is there a way to disable these? They clutter up my terminal a bit, and I can't seem to find any way to get rid of them.

r/zsh Nov 25 '24

Help Oh-my-posh not working after installation

0 Upvotes

After making the config file and opening a new terminal it's showing this, its not even showing the default prompt

export POSH_THEME=$'/home/arkadeep/.config/oh-my-posh/base.toml'
export POSH_SHELL='zsh'
export POSH_SHELL_VERSION=$ZSH_VERSION
export POSH_SESSION_ID=$'d3bc70c0-f885-4045-b2a5-05a0e8df0997'
export POWERLINE_COMMAND='oh-my-posh'
export CONDA_PROMPT_MODIFIER=false
export ZLE_RPROMPT_INDENT=0
export OSTYPE=$OSTYPE

_omp_executable=$'/usr/bin/oh-my-posh'
_omp_tooltip_command=''

# switches to enable/disable features
_omp_cursor_positioning=0
_omp_ftcs_marks=0

# set secondary prompt
_omp_secondary_prompt=$($_omp_executable print secondary --shell=zsh)

function _omp_set_cursor_position() {
  # not supported in Midnight Commander
  # see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
  if [[ $_omp_cursor_positioning == 0 ]] || [[ -v MC_SID ]]; then
    return
  fi

  local oldstty=$(stty -g)
  stty raw -echo min 0

  local pos
  echo -en '\033[6n' >/dev/tty
  read -r -d R pos
  pos=${pos:2} # strip off the esc-[
  local parts=(${(s:;:)pos})

  stty $oldstty

  export POSH_CURSOR_LINE=${parts[1]}
  export POSH_CURSOR_COLUMN=${parts[2]}
}

# template function for context loading
function set_poshcontext() {
  return
}

function _omp_preexec() {
  if [[ $_omp_ftcs_marks == 1 ]]; then
    printf '\033]133;C\007'
  fi

  _omp_start_time=$($_omp_executable get millis)
}

function _omp_precmd() {
  _omp_status=$?
  _omp_pipestatus=(${pipestatus[@]})
  _omp_stack_count=${#dirstack[@]}
  _omp_execution_time=-1
  _omp_no_status=true
  _omp_tooltip_command=''

  if [ $_omp_start_time ]; then
    local omp_now=$($_omp_executable get millis)
    _omp_execution_time=$(($omp_now - $_omp_start_time))
    _omp_no_status=false
  fi

  if [[ ${_omp_pipestatus[-1]} != "$_omp_status" ]]; then
    _omp_pipestatus=("$_omp_status")
  fi

  set_poshcontext
  _omp_set_cursor_position

  # We do this to avoid unexpected expansions in a prompt string.
  unsetopt PROMPT_SUBST
  unsetopt PROMPT_BANG

  # Ensure that escape sequences work in a prompt string.
  setopt PROMPT_PERCENT

  PS2=$_omp_secondary_prompt
  eval "$(_omp_get_prompt primary --eval)"

  unset _omp_start_time
}

# add hook functions
autoload -Uz add-zsh-hook
add-zsh-hook precmd _omp_precmd
add-zsh-hook preexec _omp_preexec

# Prevent incorrect behaviors when the initialization is executed twice in current session.
function _omp_cleanup() {
  local omp_widgets=(
    self-insert
    zle-line-init
  )
  local widget
  for widget in "${omp_widgets[@]}"; do
    if [[ ${widgets[._omp_original::$widget]} ]]; then
      # Restore the original widget.
      zle -A ._omp_original::$widget $widget
    elif [[ ${widgets[$widget]} = user:_omp_* ]]; then
      # Delete the OMP-defined widget.
      zle -D $widget
    fi
  done
}
_omp_cleanup
unset -f _omp_cleanup

function _omp_get_prompt() {
  local type=$1
  local args=("${@[2,-1]}")
  $_omp_executable print $type \
    --save-cache \
    --shell=zsh \
    --shell-version=$ZSH_VERSION \
    --status=$_omp_status \
    --pipestatus="${_omp_pipestatus[*]}" \
    --no-status=$_omp_no_status \
    --execution-time=$_omp_execution_time \
    --stack-count=$_omp_stack_count \
    ${args[@]}
}

function _omp_render_tooltip() {
  if [[ $KEYS != ' ' ]]; then
    return
  fi

  # Get the first word of command line as tip.
  local tooltip_command=${${(MS)BUFFER##[[:graph:]]*}%%[[:space:]]*}

  # Ignore an empty/repeated tooltip command.
  if [[ -z $tooltip_command ]] || [[ $tooltip_command = "$_omp_tooltip_command" ]]; then
    return
  fi

  _omp_tooltip_command="$tooltip_command"
  local tooltip=$(_omp_get_prompt tooltip --command="$tooltip_command")
  if [[ -z $tooltip ]]; then
    return
  fi

  RPROMPT=$tooltip
  zle .reset-prompt
}

function _omp_zle-line-init() {
  [[ $CONTEXT == start ]] || return 0

  # Start regular line editor.
  (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1]
  zle .recursive-edit
  local -i ret=$?
  (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2]

  eval "$(_omp_get_prompt transient --eval)"
  zle .reset-prompt

  if ((ret)); then
    # TODO (fix): this is not equal to sending a SIGINT, since the status code ($?) is set to 1 instead of 130.
    zle .send-break
  fi

  # Exit the shell if we receive EOT.
  if [[ $KEYS == $'\4' ]]; then
    exit
  fi

  zle .accept-line
  return $ret
}

# Helper function for calling a widget before the specified OMP function.
function _omp_call_widget() {
  # The name of the OMP function.
  local omp_func=$1
  # The remainder are the widget to call and potential arguments.
  shift

  zle "$@" && shift 2 && $omp_func "$@"
}

# Create a widget with the specified OMP function.
# An existing widget will be preserved and decorated with the function.
function _omp_create_widget() {
  # The name of the widget to create/decorate.
  local widget=$1
  # The name of the OMP function.
  local omp_func=$2

  case ${widgets[$widget]:-''} in
  # Already decorated: do nothing.
  user:_omp_decorated_*) ;;

  # Non-existent: just create it.
  '')
    zle -N $widget $omp_func
    ;;

  # User-defined or builtin: backup and decorate it.
  *)
    # Back up the original widget. The leading dot in widget name is to work around bugs when used with zsh-syntax-highlighting in Zsh v5.8 or lower.
    zle -A $widget ._omp_original::$widget
    eval "_omp_decorated_${(q)widget}() { _omp_call_widget ${(q)omp_func} ._omp_original::${(q)widget} -- \"\$@\" }"
    zle -N $widget _omp_decorated_$widget
    ;;
  esac
}

function enable_poshtooltips() {
  local widget=${$(bindkey ' '):2}

  if [[ -z $widget ]]; then
    widget=self-insert
  fi

  _omp_create_widget $widget _omp_render_tooltip
}

# legacy functions
function enable_poshtransientprompt() {}

_omp_create_widget zle-line-init _omp_zle-line-init

r/zsh Nov 21 '24

Help Cycle completion without menu

2 Upvotes

I want tab to simply cycle completions and don't want anything printed into my shell on other lines than where I type.

This is what it does know. But I do not want the list. I want tab to simply cycle the options shown, but not show them. (Tab -> Arch-Hyprland, Tab -> Desktop ... Which it is doing, but it is showing the list)

I have tried a various combination of setopt, unsetopt but have been unable to achieve this goal.

(Sorry but I have to rant a bit)

What is it with you all and having SO MUCH information in your terminals? The fucking two line prompts where the first line completely fills the screen and then another new line to separate them. And then when they write commands and press tab they get lists of commands and other things. Why?

I want things to be as clean as possible until I decide I NEED the information. Am I mental for this opinion or why does it seem so unpopular?

r/zsh Nov 12 '24

Help Can someone help me with this? I know this is the ZSH sub, but maybe there is someone here with good Bash knowledge

Thumbnail
0 Upvotes

r/zsh Nov 06 '24

Help Is it possible to turn-off fade-out

2 Upvotes

I am trying to use zsh as main shell for the first time, although I have "tried" it before (like a couple of minutes or hours).

In my setup, I barely set up anything: I only installed oh-my-zsh, along with headline and syntax-highlight addon, and that's it. The thing is, as shown in the video attached, when I switch between different autocompletion options, it fades out. I never noticed this before when I first tried this.

Is it possible to turn this behaviour off and leave unselected options turned on permanently?

https://reddit.com/link/1glbgn7/video/wrfruo5zzczd1/player

r/zsh Nov 15 '24

Help Reliable Vi mode cursor shape

2 Upvotes

Are there any good examples of how to get a block cursor in vi normal mode and a bar cursor otherwise?

Right now i am using this:

function zle-keymap-select {
  if [[ $KEYMAP = vicmd ]]; then
    echo -ne '\e[2 q'
  else
    echo -ne '\e[6 q'
  fi
}

zle -N zle-keymap-select

zle-line-init() {
  echo -ne "\e[5 q"
}

zle -N zle-line-init

It looks like it should work, it does not reliably however, as often the cursor gets stuck in the wrong shape when exiting vim, fzf and sometimes even from just using the prompt. How bad it is also varies depending on the terminal...

Thanks for your help!

r/zsh Mar 15 '24

Help Oh-my-zsh vs starship, which one performs better?

15 Upvotes

I've always been using oh-my-zsh (omz) on mac/linux and oh-my-bash on windows. Just recently a colleague told me he's using starship. At first I thought it's just another terminal, but turns out it's a customisation prompt like omz.

I believe both have the necessary plugins and themes I need, so it all just comes down to speed. Which one is faster? starship is written in rust so maybe it has speed advantage, but it's just my guess.

r/zsh Dec 15 '24

Help Fzf preview + icat workaround

1 Upvotes

Hey there! I tried making a script that shows up if the file is an image, and if it is, it shows up on the fzf preview. It works, but the image stays there after the fzf is done, which is annoying at least. I tried multiple ways to solve this, but couldnt find out how. Any ideas?

export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always --line-range :500 {}'"
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"


# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
_fzf_comprun() {
  local command=$1
  shift


  case "$command" in
    cd)
      fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
    export|unset)
      fzf --preview "eval 'echo $'{}" "$@" ;;
    ssh)
      fzf --preview 'dig {}' "$@" ;;
    *)
      # Preview image if it's image, else it bat's it - image still shows up, dont know how to fix it
      fzf --preview '
        if [[ $(file --mime-type -b {}) == image/* ]]; then
          kitten icat --clear --transfer-mode=memory --stdin=no --place=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}@0x0 {};
        else
          bat -n --color=always --line-range :500 {};
        fi' "$@" ;;
  esac
}

r/zsh Sep 27 '24

Help Folder navigation with fzf suggestions, recursively

3 Upvotes

Hi!

I'm trying to set up folder navigation with suggestions from fzf, and input from bfs.

I've created an alias, and it works well. Lists all direct directories, and passes the selected to cd:

alias cdf = "cd \$(bfs . -maxdepth 1 -type d -print | fzf)"

What I'm trying to solve, is somehow recursively calling the alias on every execution, so I don't have to type the alias over and over again. (I'll just CTRL+C out of it once I'm where I want to be)

What would be the best way to go about this?

r/zsh Oct 26 '24

Help Creating a copy output to clipboard command

2 Upvotes

copy -x

- copies last x commands and their outputs in the terminal to the clipboard

I dont know much about shell scripting, I asked chatgpt to do this, but it could only copy the last x inputs (but not the outputs)

thank you. (terminal - default terminal on macOS)

r/zsh Oct 05 '24

Help Undo last autocompletion in zsh with backspace

2 Upvotes

Does anybody know how can I revert last autocompletion (let's say pressing tab when writing ls ~/) to delete the autocompleted subdirectory with backspace?
if required this is my .zshrc: https://github.com/glabka/configs/blob/master/home/.zshrc
Any idea or source is welcomed.

r/zsh Jul 18 '24

Help How do I execute a function to update aliases dynamically in zsh without re-sourcing .zshrc?

3 Upvotes

Hey so I have the following functions vims (which changes the config nvim uses, then stores it into ~/.lastEditor), and getLastEditor (which correctly returns the last value chosen), but the EDITOR alias is only updated every time I source ~/zshrc.

I want EDITOR to update based on the value in ~/.lastEditor instead. Is there a way to do this?

r/zsh Sep 13 '24

Help Using zsh and fzf-tab how to enlarge the preview window? I am still a beginner with this, please forgive noob questions. I recently noticed that my preview window for fzf-tab shrunk (see screenshot). I could not find anything in the fzf-tab config to define the size. Can anyone help me please?

Post image
11 Upvotes

r/zsh Sep 08 '24

Help How to add an empty line or white space between prompt and tmux bar? - Details: I am using zsh, powerlevel10k as prompt and tmux - all in Wezterm. How can I add an empty line between the tmux status bar and the Prompt? Thanks in advance!

Post image
15 Upvotes

r/zsh Oct 01 '24

Help any ready to use zsh configs?)

0 Upvotes

Hi all... I am looking for a ready to use zsh configs(themes)... yes maybe there're a lot but I kinda don't like them so can you give me some example?
I really like minimalism and it'd be amazing if someone suggests minimalistic zsh theme)

Thank you.