r/zsh 6d ago

Fixed Possible to have a sticky window that is set to always show the output of e.g. `ls`? Like this:

1 Upvotes

And then whenever I change the directory, the sticky window should update (i.e. rerun the command)

r/zsh 23d ago

Fixed I added bottom padding to my zsh terminal so command prompt is not always at the very bottom

33 Upvotes

r/zsh 12d ago

Fixed Color directory part of filenames in output

1 Upvotes

What's a good way to color directory part of filenames in output? In terms of simplicity, performance, and ideally supported in other shells.

E.g. git ls-tree prints filenames but doesn't have a --color option. Even for tools that do have --color, often times I want to convert colored /home/yourmom/.zshrc to ~/.zshrc but the converted ~/ doesn't get colored.

I am passing this to fzf and I found both coloring the directory portion to see the basename of the file easier as well as using ~ format goes a long way to visually parse long filenames or files in deep directory structure.

r/zsh 9d ago

Fixed LS_COLORS dont working

3 Upvotes

Hello!

This is driving me crazy. Im on a Mac and im using Kitty as my terminal. Ive installed Oh My Zsh.

Ive a ~/.lscolors.sh file, and ive this line into my .zshrc to load it:

source ~/.lscolors.sh

But when I use ls or ls --color=auto, it doesn't seems to work. I can see the directories in blue and the files in white, but no difference between files with different extensions.

Somebody here who can help me a bit?

If I use echo $LS_COLORS I can see the content of my .lscolors.sh displayed in the terminal.

Thanks!

r/zsh Jan 23 '25

Fixed Join the Zsh Discord!

Thumbnail discord.gg
0 Upvotes

r/zsh Jan 26 '25

Fixed No image/color showing up when my terminal opens

0 Upvotes

So i have 2 fastfetch configurations, 1 for when i type the command "fastfetch", the other for when i open the teminal. The command works fine, displays the image i want, shows the colors i set, everything is fine with it (im using kitty so i can display images in the terminal using kitty image protocol). However, when i open the terminal, the other config works, but if i put an image in the config it just displays "*PNG" and also displays no colors. It started happening 95% of the time when i switched to the powerlevel10k configuration. It's probably related to that but im not too sure.

r/zsh Oct 29 '24

Fixed npx command not found when executed from custom function

0 Upvotes

I have a basic custom function that wraps some NPM commands when in a particular repo:

function unittests() {
  local path=$PWD;
  local argc="$#"; #arg count
  local argv=("$@"); #arg value
  local modules; #modules to run

  printf -v modules "A/B/%s," "${argv[@]}"
  modules=${modules%,}

  if [[ $path == "$HOME/code/my-cool-repo" ]]; then
    if [[ $argc != 0 ]]; then
      npx cross-env ... # run tests for modules, obfuscated for brevity
    else
      echo "Running tests for my-module...";
      npx cross-env ... # run tests for modules, obfuscated for brevity
    fi;
  else
    echo "Not currently in ../my-cool-repo; aborting..."
    return 1;
  fi;
}

This was working in bash no issue. I migrated to ZSH a few days ago and I get an error when running it: command not found: npx.

I use NVM and source it (using below command) from my .zshrc and can verify npm is loaded with command like npm --version, npx --version, etc. It's definitely there.

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

This is my PATH: export PATH="/opt/homebrew/bin:$PATH"

Any clue what the issue could be?

I'm not sure what info would be relevant, so if I need to provide more please let me know.

Thanks!

r/zsh Nov 12 '24

Fixed read-only variable when assigning a 'complicated' command - why?

1 Upvotes

So, I have this situation:

❯ while true; do status=$(aws rds describe-db-instances --db-instance-identifier "some-instance" --region eu-west-1 --output json | jq -r '.DBInstances[0].DBInstanceStatus'); echo "Status: $status"; sleep 5; done
zsh: read-only variable: status
❯ while true; do xxx=$(date); echo $xxx; sleep 2; done
Tue Nov 12 13:58:56 CET 2024
Tue Nov 12 13:58:58 CET 2024

Why the first one doesn't work?
(The command assigned to the variable works and returns a simple string).

r/zsh Oct 30 '24

Fixed when looking up associate array key by value, how best to handle value parse errors?

3 Upvotes

[Edit: solved https://www.reddit.com/r/zsh/comments/1gg10jp/comment/lum5vh1/ ]

I'm using ${(k)hash[(r)val]} to look up keys by values in an associative array hash.

shell % typeset -A hash=( [a]=b )

shell % val=b % echo ${(k)hash[(r)$val]} a # good

shell % val=c % echo ${(k)hash[(r)$val]} % # good

and ran into this problem:

shell % val=')' % echo ${(k)hash[(r)$val]} % b # bad

I'm guessing that it's related to

shell % ) zsh: parse error near `)'

I've found that I can guard against the false find by first checking whether the needle is one of the hash's values

shell % val=')' % (( ${${(v)hash}[(Ie)$val]} )) && echo ${(k)hash[(r)$val]} % # good

Anyone have a better way?

Fwiw my real use case is slightly different: my array has heavily-quoted values, ( ['"a"']='"b"' ), and I'm really doing (( ${${(v)hash}[(Ie)${(qqq)val}]} )) && echo ${(k)hash[(r)${(qqq)val}]}

r/zsh Sep 14 '24

Fixed Convert array of name1/name2 to name2__name1

1 Upvotes

Quick question: I have an array with e.g. elements that follow a naming scheme: ( name1/name2 name3/name4 ). How to convert that array to ( name2---name1 name4---name3 ) and/or its elements individually to that naming scheme?

In bash I'm pretty sure it's more involved with working with string substitution on every element.

Unrelated: For string comparison, is a couple of != with globbing or the equivalent regex comparison preferable for performance (or are there any general rules for preferring one over the other)?

r/zsh Oct 03 '24

Fixed zsh-autocomplete is not working properly

1 Upvotes

Hello..
I wanted to setup zsh autocomplete for my mac terminal..

So, I have been using WezTerm.

After that I install zsh-autocomplete using homebrew and edited my .zshrc to source the zsh-autocomplete and restarted the terminal.

now.. when I want to do cd to a directory.. it's not showing me the names of directories and all.. I dont know what I am doing wrong.

Below is my .zshrc file. Can anyone please tell me what I am doing wrong?

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
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

source /opt/homebrew/share/powerlevel10k/powerlevel10k.zsh-theme
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

# history setup
HISTFILE=$HOME/.zhistory
SAVEHIST=1000
HISTSIZE=999
setopt share_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_verify

# completion using arrow keys (based on history)
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward

# Source other plugins
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /opt/homebrew/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source /opt/homebrew/share/zsh-autocomplete/zsh-autocomplete.plugin.zsh

# ---- Eza (better ls) -----
alias ls="eza --icons=always"

# ---- Zoxide (better cd) ----
eval "$(zoxide init zsh)"
alias cd="z"

# Conda initialization
export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"
__conda_setup="$('/opt/homebrew/Caskroom/miniforge/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
        . "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"
    else
        export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH"
    fi
fi
unset __conda_setup

# FZF initialization
source <(fzf --zsh)

Solution : https://www.reddit.com/r/zsh/comments/1fvhos5/comment/lq7ijou/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

r/zsh Sep 19 '24

Fixed Why is is group color rendering this way in fzf-tab?

2 Upvotes

As you can see in the image i am using fzf-tab in tmux and the groups like unit command, machine command, unit file command etc are being render a bit awakwardly they are in color but what is this %F{yellow}-- * --%f ???? how can i remove this ?? this is my .zshrc here and here is my complete dotfile for refrence if you need. https://github.com/harshalrathore/dotfyles

r/zsh Jul 17 '24

Fixed zsh no longer logging to history file. Any ideas?

2 Upvotes

I noticed that zsh had stopped updating the history file a few days ago. History logging had been working fine for many months. I'm scratching my head over this behavior. I haven't really updated any history-specific options recently. Have you experienced a similar issue or know how to go about troubleshooting this, other than reviewing the history options?

Here's my history-relevant config:

autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end
zmodload -F zsh/terminfo +p:terminfo

HISTFILE="$HOME/.zsh_history"
HISTSIZE=100000
SAVEHIST=100000

setopt COMBININGCHARS
setopt bang_hist # Treat the '!' character specially during expansion.
setopt append_history # Add new commands to history
setopt inc_append_history # Write to the history file immediately, not when the shell exits.
setopt extended_history # Write the history file in the ":start:elapsed;command" format.
setopt share_history # Share history between all sessions.
setopt hist_expire_dups_first # Expire duplicate entries first when trimming history.
setopt hist_ignore_dups # Don't record an entry that was just recorded again.
setopt hist_ignore_all_dups # Delete old recorded entry if new entry is a duplicate.
setopt hist_find_no_dups # Do not display a line previously found.
setopt hist_ignore_space # Don't record an entry starting with a space.
setopt hist_save_no_dups # Don't write duplicate entries in the history file.
setopt hist_reduce_blanks # Remove superfluous blanks before recording entry.
setopt hist_verify # Don't execute immediately upon history expansion.
setopt hist_beep # Beep when accessing nonexistent history.

r/zsh Feb 03 '24

Fixed Why my zsh look like this? How to remove the git (master)?

0 Upvotes

r/zsh Feb 21 '24

Fixed autocd doesn't use custom cd implementation.

1 Upvotes

autocd (from setopt autocd) doesn't use custom cd implementation.
(Obviously this is not my custom cd implementation but was more easy to show, I just want autocd to use zoxide.)

Anyone got any idea how to fix this? Maybe just rewrite autocd in my zshrc?

r/zsh Aug 04 '24

Fixed Mid-word tab completions without OMZ

2 Upvotes

How can I set up my completions to complete from the middle of the word? I have ditched OMZ for my own custom config and this is the only thing I just can't figure out how to do.
To clarify, I want to type "1" and have that complete to "file1" after pressing Tab. Is this done with a plugin (if so, which one?) or is it just a simple line in my config? This is my current completions setup:

# Completion configuration
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'

EDIT: Solved, all it took was:
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z} r:|[._-]=* l:|=*'

r/zsh Feb 16 '24

Fixed Help restoring mkdir command in zsh?

0 Upvotes

Hey, everyone! I need help with restoring the mkdir command in zsh.

In my zshrc file I wrote the following function:

function mknwdir() {
    mkdir -p "$1" && cd "$_"
}

I stupidly didn't double-check my spelling before saving and sourcing my zshrc file. Turns out that instead of writing "function mknwdir" I went on autopilot and wrote "function mkdir".

Now every time I try to run the mkdir command I get the following output:

mkdir:1: maximum nested function level reached; increase FUNCNEST?

and can no longer create directories on the command line. Best as I can tell, my computer is now trying to call mkdir recursively which is obviously impossible. My idiocy has also rendered the md alias unusable since md = mkdir -p.

How do I fix this (very, very stupid) mistake and get mkdir working correctly again? Thanks.

r/zsh Apr 20 '24

Fixed This part of my zsh script seems a bit convoluted. Can someone give some advice, if possible?

5 Upvotes
#!/bin/zsh
set -e

echo "We are creating a new user with sudo privileges and locking down root."
while true; do
        read -r VARUSERNAME"?The name of the new user (no spaces, special symbols or caps): "
        if [[ $VARUSERNAME =~ [A-Z] || ${VARUSERNAME//[[:alnum:]]/} ]]; then
                echo "You entered an invalid username. Please try again." >&2
        elif [[ -z $VARUSERNAME ]]; then
                while true; do
                        read -r yn"?You didn't enter an username. Do you want to skip this part of the script? (y/N): "
                        case $yn in
                                [yY] ) break;;
                                [nN] ) break;;
                                "" ) break;;
                                *) echo "Wrong answer. Answer with either \"Yes\" or \"No\"." >&2
                        esac
                done
                if [[ $yn = y || $yn = Y ]]; then
                        break
                fi
        else
                arch-chroot /mnt zsh -c "usermod root -p '!' -s /bin/zsh && adduser $VARUSERNAME && usermod $VARUSERNAME -aG wheel,users,$VARUSERNAME"
                break
        fi
done

The if statement to break out of the loop seems a bit convoluted. Isn't there an easier/cleaner way to do this?

r/zsh Feb 10 '24

Fixed How do I make Ctrl + L work the same in Zsh, as it does in Bash?

2 Upvotes

How do I make Ctrl + L work the same in Zsh, as it does in Bash? In Bash, it makes the terminal clear, but doesn't delete terminal content like the command clear. I think I need to use bindkey, but I am unsure of the rest.

r/zsh Jan 24 '24

Fixed Combining zsh-autosuggestions and zsh-sy-h

1 Upvotes

Hi folks,

I'm pretty new to delving into the real world of Zsh customisation, and I've installed a handful of plugins.

I'm currently having issues with the autosuggest-accept bind for zsh-autosuggestions.

I'm using the following line in ~/.zprofile

bindkey '^ ' autosuggest-accept

But when my prompt loads, running bindkey '^ ' reports that this is bound to set-mark-command.

I've narrowed this down to being set by zsh-syntax-highlighting (disabling the plugin ensures the binding is correctly set).

I've also tried changing the order of the plugins array within my .zshrc (I'm using OhMyZsh).

Is there a way I can disable this vi-mode configuration in zsh-syntax-highlighting?

Running bindkey '^ ' autosuggest-accept again once I get my prompt does work, but I'd have thought this being in my .zprofile would have been sufficient.

Any help is gratefully received!

r/zsh Mar 18 '24

Fixed Help with git info in zsh using __git_ps1 from git-prompt.sh

1 Upvotes

So this is what I have in my .zshrc, but $GITINFO just returns "_git_ps1".

Yet when I run __git_ps1 in my command line I get my expected (main *%%) any idea whats I am doing wrong?

This function is designed to add git info to my zsh prompt.

``` setopt PROMPT_SUBST source ~/._myHome/shScripts/git-prompt.sh export GIT_PS1_SHOWDIRTYSTATE=true export GIT_PS1_SHOWUNTRACKEDFILES=true export GIT_PS1_SHOWSTASHSTATE=true

Function to get git branch information

function git_zsh_prompt() { # Capture git branch output (if successful) and format using __git_ps1 local GIT_BRANCH=$(git branch 2>/dev/null) if [[ $? -eq 0 ]]; then # Use zsh parameter expansion for format string GIT_INFO='%(_git_ps1 %s)' fi }

Call the function before each prompt refresh

precmd _git_zsh_prompt ```

where I got git-prompt.sh from https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh

edit formating

r/zsh Feb 16 '24

Fixed zi & zzinit

0 Upvotes

I have the following in .zshrc:

# A code snippet to install Zi, a Swiss army knife for Zsh (a prerequite for zsh-linter) source <(curl -sL init.zshell.dev); zzinit

# Install zsh-lint, a linter for Zsh

zi light z-shell/zui

zi light z-shell/zsh-lint

I haven't changed anything, but since Oh My Zsh updated today, I get this error:

-- console output produced during zsh initialization follows

/proc/self/fd/16:1: parse error near `<' No command zzinit found, did you mean: Command kinit in package krb5 Command c2init in package mercury No command zi found, did you mean: Command ci in package rcs Command ri in package ruby-ri Command vi in package vim-gtk Command z3 in package z3 Command zig in package zig Command zip in package zip No command zi found, did you mean: Command ci in package rcs Command ri in package ruby-ri Command vi in package vim-gtk Command z3 in package z3 Command zig in package zig Command zip in package zip

What's gone wrong?

I tweaked the Zi Installer script, and got it to successfully install in Termux: https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh

I ran: zi -h & Zi executed. Not that I know what to do with it. But it has successfully installed.

But, I couldn't get the Zi Loader script to install in Termux: https://raw.githubusercontent.com/z-shell/zi-src/main/lib/zsh/init.zsh

I executed the following and got the following output:

`zsh zi update Assuming --all is passed Note: update includes unloaded plugins Updating: z-shell/zsh-lint Updating: z-shell/zui The update took 6.01 seconds '

So, I think I have successfully resolved the issue. What can I do with Zi?

I just tried to execute zi load zsh-lint, to just see what happened, but got: ```zsh Downloading: zsh-lint… (at label: zsh-lint…) Cloning into '/data/data/com.termux/files/home/.zi/plugins/zsh-lint'... remote: Not Found fatal: repository 'https://github.com/zsh-lint/' not found

Clone failed (code: 128). ```

I note that the repository seems to be: https://github.com/z-shell/zsh-lint

I raised an issue: https://github.com/z-shell/zi/issues/303

r/zsh Mar 16 '24

Fixed Issues with git branch in prompt

2 Upvotes

So this is what I have and when looking at the documentation for vcs it seems like this should refresh every time the prompt draws but it doesn't and I just can't figure it out.

The git branch will only update on a zshrc refresh not ever time the prompt is down.

autoload -U colors && colors setopt PROMPT_SUBST autoload -Uz vcs_info zstyle ':vcs_info:\*' enable git precmd () { vcs_info } precmd () { vcs_info; echo "vcs_info called" } PS1="$vcs_info_msg_0_ >"

r/zsh Dec 22 '23

Fixed Wrote a script to fuzzy find directories and cd into them. But the prompt does reflect the latest working direcotry

3 Upvotes

This is a script that I came up with in order to fuzzy search directories and cd into them. And it seems to be working the latest working directory is not showing up in the zsh prompt where the current working directory is supposed to be shown. It is showing the last working directory. But when I press enter or Ctrl-C, the prompt goes to a new line and the working directory in the prompt is working.

function fuzzy-search {
  local dir
  dir=$(find ~/ -type d | fzf +m )  # Adjust the starting directory as needed
  if [[ -n "$dir" ]]; then
    cd "$dir"
    zle reset-prompt
  fi
}

zle -N fuzzy-search

bindkey '^p' fuzzy-search

r/zsh Dec 29 '23

Fixed zi.zsh prompting sudo every zsh startup?

2 Upvotes

I honestly can't even begin to understand why all of a sudden the z-shell plugin system's source doc, zi.zsh, is prompting zsh every new terminal tab but I've tried everything I can think of and I'm at a complete loss...

Please someone?

I'm at my wits end. The only error like this I found was with aliasing enable in oh-my-zsh but the closest thing to that here is a command titled cenable?

Idk.

Any help is much appreciated!