Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
0
answers
31
views
Unavailable executable still remains
Please note: This is not a question related to pip or python. I am trying to make sense of why I see a "permission error" instead of "path not found" error. I have done many installations and uninstallation for different softwares including python. So I can't recall how the setup was many years back...
Please note: This is not a question related to pip or python.
I am trying to make sense of why I see a "permission error" instead of "path not found" error.
I have done many installations and uninstallation for different softwares including python. So I can't recall how the setup was many years back.
My core question is why I see an "
zsh: permission denied: pip
" instead of "pip not found". When an executable doesn't exist, I would expect it to be say "not found" vs pointing to a possible permission issue.
And secondly; is there a way in linux\unix\mac to identify all commands\symlinks\aliases that are broken now?
Here is my terminal output
ayusman :$ pip
zsh: permission denied: pip
ayusman :$ which pip
pip not found
ayusman :$ type pip
pip not found
ayusman :$
Thank you.
Ayusman
(141 rep)
Aug 5, 2025, 12:26 AM
• Last activity: Aug 5, 2025, 12:33 AM
1
votes
1
answers
41
views
On start of an interactive shell, is there something that gets called between ~/.zshenv and ~/.zshrc? My PATH is getting changed between them
According to the docs, the order of .zsh files is ``` .zshenv .zprofile .zshrc .zlogin ``` As suggested by the docs, I put my $PATH in .zshenv. I echo it there and I can see it. But something is changing $PATH by the time .zshrc is called. I put an `echo $PATH` at the top of it and I see it has chan...
According to the docs, the order of .zsh files is
.zshenv
.zprofile
.zshrc
.zlogin
As suggested by the docs, I put my $PATH in .zshenv. I echo it there and I can see it.
But something is changing $PATH by the time .zshrc is called. I put an echo $PATH
at the top of it and I see it has changed.
So what could be changing it?
Mac OS btw
Paul C
(1005 rep)
Aug 1, 2025, 09:42 PM
• Last activity: Aug 2, 2025, 07:58 AM
0
votes
3
answers
3237
views
How do i bindkey the Right Control Key in zsh?
I searched the internet and could not find anybody asking this question. I was annoyed of moving right and the autocomplete `autosuggest-accept` being the same keybind. My closes guesses were ``` bindkey -v ' ' autosuggest-accept ``` and ``` bindkey '\xffe4' autosuggest-accept ``` but they did not w...
I searched the internet and could not find anybody asking this question. I was annoyed of moving right and the autocomplete
autosuggest-accept
being the same keybind. My closes guesses were
bindkey -v '' autosuggest-accept
and
bindkey '\xffe4' autosuggest-accept
but they did not work. How should I go at finding how to do this?
1ctinus
(78 rep)
Apr 13, 2021, 11:25 PM
• Last activity: Jul 31, 2025, 10:03 PM
5
votes
1
answers
119
views
How to configure ZSH to behave more like BASH
I recently upgraded KDE Plasma to v6, got ZSH instead of BASH in it and because I like some of its smart completion features and such, I decided to try to learn working with it. But I have a hard time getting used to it as a decades long BASH user. Maybe I'm searching wrong but I can't figure out ho...
I recently upgraded KDE Plasma to v6, got ZSH instead of BASH in it and because I like some of its smart completion features and such, I decided to try to learn working with it. But I have a hard time getting used to it as a decades long BASH user. Maybe I'm searching wrong but I can't figure out how to configure some basic stuff that I find convenient in BASH.
I'm having the following troubles:
1. `
(ALT+period) in BASH invokes the last word from the previous command. E.g., I do
ls file.txt , then
cat and I get
cat file.txt`. The caret (cursor) is after the word inserted by the key combo.
This doesn't work for me in ZSH. I can do !$
instead of ` but that's not too convenient. I also have working solution written by GPT but it throws me an error even tho it works. See my
.zshrc` below.
I have also found this question—[vi mode - How to use Alt + .
in zsh with Vim bindings - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/685008/how-to-use-alt-in-zsh-with-vim-bindings)—where I learned I can use +_
but that's not exactly comfortable either for two reasons: Firstly, underscore is bound to +-
on US and CZ keyboards which I use (so it's actually uncomfortable ++-
combo which has the potential to change keyboard layout with +
), and secondly, it produces the same error "No such shell function insert-last-word" as the binding I already have. I tried append-last-word
instead which doesn't work at all.
1. ` and
` to jump to the start/end of the current line.
I can do / to do the start/end jumps but that's not exactly convenient either.
1. I have there working binding to use +LEFT/WRITE_ARROW
to jump by words. However, this doesn't seem to respect $WORDCHARS
, e.g., if there's a path (includes /
), it jumps over it as a whole. What may I be doing wrong? My $WORDCHARS
:
$ echo $WORDCHARS
*?_-.[]~=/&;!#$%^(){}
4. Edit: one more thing: I just installed a package (sudo pacman -S hdparm
successfully. And right after that, when I try to invoke the command, I type hdpar
, expecting to get the hdparm
auto-completed. Nope, I get various completely random suggestions (cdparanoia gdparttopng
), none of them being hdparm
. When I type the command in full, though, it works, so that means it _is_ a valid command. Do I need to run some completion update? :o (sorry, confused and slightly disillusioned).
I found that bindkey -e # Use emacs key bindings
brings some things to life, such as `` for reverse search. But not all of them, see my biggest pains above.
Here's the config I have in ~/.zshrc
: (I'm posting it in its entirety but everything below line 52 is out of this question's scope, it works fine and is unrelated.) Please see the comments in the file for explanations of what doesn't work and how
# The following lines were added by compinstall
zstyle ':completion:*' completer _expand _complete _ignored _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|[._-]=** r:|=** l:|=*'
zstyle ':completion:*' menu select=2
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl true
zstyle :compinstall filename '/home/edison23/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.bash_history
HISTSIZE=1000000
SAVEHIST=1000000
unsetopt autocd
bindkey -v
# End of lines configured by zsh-newuser-install
#PS1='%d $ '
autoload -U colors && colors
PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}$ "
# Set key bindings to emulate Bash behavior
bindkey -e # Use emacs key bindings
# Should bind to inserting last word but it works only for the last word of *the same command*,
# e.g. cat foo; echo bar; cat
gives me cat foo
instead of cat bar
. Not desired.
# bindkey '^[.' history-beginning-search-backward
# This works but throws "No such shell function `insert-last-word'" error at the same time which is annoying, to say the least.
# Define the widget
zle -N insert-last-word
# Bind the widget to Alt + .
bindkey '^[.' insert-last-word
# Move to the beginning and end of the line using Home and End keys
# Doesn't work at all
bindkey 'Home' beginning-of-line # Home key to go to the start of the line
bindkey 'End' end-of-line # End key to go to the end of the line
# Move by words using (works)
# TODO: Any option to customize word delimiters?
bindkey "^[[1;3C" forward-word
bindkey "^[[1;3D" backward-word
# Everything below is fine and of no relation to the question posted on SO
# ls aliases
alias ll='ls -la -v --time-style=posix-long-iso --group-directories-first --color=always'
alias la='ls -A'
alias l='ls -CF'
#ls hidden files, no sorting
alias ls='ls -v --color="auto" --time-style=posix-long-iso --group-directories-first'
# CRC32 into filename
# rhash required, I think
alias embedcrc32='rhash -e --embed-crc-delimiter="."'
# Copy node path
# Use | xsel -bi
on X11
fpath() {
echo -n readlink -f "${1}"
| wl-copy
}
# color diff
alias dwdiff_rw='dwdiff -P -cred,green -A best -w [- -x -] -y {+ -z +}'
Thank you very much for your time, help, and patience with a ZSH newbie. Any bonus useful tips and tricks appreciated as well :)
edison23
(155 rep)
Jul 13, 2025, 01:10 PM
• Last activity: Jul 31, 2025, 08:14 PM
2
votes
1
answers
133
views
Semicolon in conditional structures after the closing double bracket in a bash/zsh script?
Continuing https://unix.stackexchange.com/questions/48805/semicolon-in-conditional-structures (which handles single brackets), what's the point of having a semicolon after the closing DOUBLE bracket `]]`? In my tests, running ```zsh #!/bin/zsh -- if [[ "a" == "a" ]] then echo "true" else echo "false...
Continuing https://unix.stackexchange.com/questions/48805/semicolon-in-conditional-structures (which handles single brackets), what's the point of having a semicolon after the closing DOUBLE bracket
]]
?
In my tests, running
#!/bin/zsh --
if [[ "a" == "a" ]] then
echo "true"
else
echo "false"
fi
if [[ "a" == "a" ]]; then
echo "true"
else
echo "false"
fi
if [[ "a" == "a" ]]
then
echo "true"
else
echo "false"
fi
if [[ "a" == "a" ]];
then
echo "true"
else
echo "false"
fi
yields
true
true
true
true
, and running
#!/bin/zsh --
if [[ "a" == "b" ]] then
echo "true"
else
echo "false"
fi
if [[ "a" == "b" ]]; then
echo "true"
else
echo "false"
fi
if [[ "a" == "b" ]]
then
echo "true"
else
echo "false"
fi
if [[ "a" == "b" ]];
then
echo "true"
else
echo "false"
fi
yields
false
false
false
false
No error is reported. In zsh, what's the difference between the conditionals with a semicolon ;
after the closing double bracket and the conditionals without a semicolon after the closing double bracket?
The same question goes for bash.
user743115
(1 rep)
Jul 26, 2025, 12:42 AM
• Last activity: Jul 26, 2025, 06:12 PM
1
votes
0
answers
60
views
mousepad with key combinations for bash, zsh, emacs, vi, or gnome on a German PC keyboard?
Recently, I noticed that it's possible to order cheap mousepads with customer-provided images on it. As I don't wish to reinvent the wheel: Has anyone of you folks, perhaps, already done the job of constructing an image with a list or lists of the most useful or frequent default key bindings of bash...
Recently, I noticed that it's possible to order cheap mousepads with customer-provided images on it. As I don't wish to reinvent the wheel: Has anyone of you folks, perhaps, already done the job of constructing an image with a list or lists of the most useful or frequent default key bindings of bash, zsh, emacs, vi, or Gnome for a rectangular mousepad of size between 22 cm × 18 cm and 25 cm × 20 cm? The key combinations should work on a
on a PC running Debian, if that matters.
In the positive case: could you share not only the image but, ideally, also the original document?

user743115
(1 rep)
Jul 25, 2025, 02:14 AM
• Last activity: Jul 26, 2025, 03:29 PM
22
votes
6
answers
19143
views
zsh kill Ctrl + Backspace, Ctrl + Delete
How to configure zsh such that Ctrl + Backspace kills the word before point? How to achieve that Ctrl + Delete kills the word after point? I use urxvt as terminal emulator.
How to configure zsh such that Ctrl+Backspace kills the word before point? How to achieve that Ctrl+Delete kills the word after point?
I use urxvt as terminal emulator.
student
(18865 rep)
May 7, 2011, 09:08 AM
• Last activity: Jul 25, 2025, 06:36 PM
18
votes
2
answers
3501
views
zsh can't input to terminal when piping stdin and stdout with variable command that has tty output
System info: macOS Sierra 10.12.6 zsh 5.4.2 (x86_64-apple-darwin16.7.0) GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.3.0) Scroll to the **EXAMPLES** at the bottom if you just want to dig in to the simplified examples that I made. NOTE: I am not a big `zsh` user. --- I was looking at th...
System info:
macOS Sierra 10.12.6
zsh 5.4.2 (x86_64-apple-darwin16.7.0)
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.3.0)
Scroll to the **EXAMPLES** at the bottom if you just want to dig in to the simplified examples that I made.
NOTE: I am not a big
zsh
user.
---
I was looking at the [fzf
](https://github.com/junegunn/fzf) keybindings for [bash
](https://github.com/junegunn/fzf/blob/master/shell/key-bindings.bash#L59) and [zsh
](https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh#L73) .
Notice how they both run a variable command $(__fzfcmd)
. __fzfcmd
by default outputs fzf
to stdout and the parameter substitution just runs command (fzf
) resulting from the output.
One difference between the bash
and zsh
script is that the bash
one further pipes the output of $(__fzfcmd)
but zsh
just captures it inside an array. My guess is because of a problem in zsh
when you further pipe the output of fzf
where you can't input to fzf
and the process piped to by fzf
doesn't get any stdin. Your only choice is to ^Z
or ^C
. ^C
seems to background the process for some reason. Or maybe they just wanted it in an array so they could could [run zle vi-fetch-history
on it](https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh#L78) . The bash
version does some magic in the key binding with ["\e^": history-expand-line
](https://github.com/junegunn/fzf/blob/master/shell/key-bindings.bash#L83)
Now fzf
isn't important. It seems like you just need a program that outputs to the tty
to be called by parameter substitution to cause this problem. So I will show some simpler examples.
Here are some other commands that output to the tty
that can cause this problem in zsh
:
- [vipe](https://linux.die.net/man/1/vipe) (run editor in middle of a pipe)
- 'vim -'
(make vim read from stdin. similar to vipe but won't output to stdout)
---
In the examples below, replace every occurrence of vipe
with vim -
if you don't want to do a separate install. Just remember that vim -
won't output the editor contents to stdout like vipe
does.
**EXAMPLES:**
1) echo 1 | vipe | cat # works in both bash and zsh
2) echo 1 | $(echo vipe) | cat # works in bash only. zsh problem with no output until I hit ^C
:
^C
zsh: done echo 1 |
zsh: suspended (tty output) $(echo vipe) |
zsh: interrupt cat
# seems like the process is backgrounded. I can still see it in jobs command
3) cat >(cat) # works in both bash and zsh
# The following don't have and input pipe to vipe.
# Type something then send EOF with ^D
6) vipe | cat # works for both
7) $(echo vipe) | cat # works for both
Now, I'm mostly wondering why 2)
has a problem for zsh
but not for bash
and why 4)
and 5)
fixes the problem for zsh
.
The requirements for zsh
to have this problem to seem to be exactly what I put in the title:
- input pipe
- command run by variable/parameter substitution that has tty
output
- output pipe
**UPDATE**
I added another workaround that doesn't cause zsh
to have this problem, 5)
. It's similar to 4)
but instead of redirecting stdout
directly into stin
, I redirect it into a file that redirects into stdin
using process substitution.
dosentmatter
(536 rep)
Dec 18, 2017, 10:44 PM
• Last activity: Jul 24, 2025, 04:48 AM
5
votes
0
answers
95
views
Subsequent "git clone" commands influencing each other?
I'm currently part of a migration from GitLab to Azure DevOps. As part of that I wrote a little bash script that iterates over the migrated git repos and for each performs a clone from both gitlab and azdo and diffs the branches, tags and log. This works like a charm for 128 out of the 129 repos we'...
I'm currently part of a migration from GitLab to Azure DevOps. As part of that I wrote a little bash script that iterates over the migrated git repos and for each performs a clone from both gitlab and azdo and diffs the branches, tags and log.
This works like a charm for 128 out of the 129 repos we've migrated so far, but for one of them (not especially big or complex), the clone from azdo fails 100% of the time. Cloning it directly on the cmdline (same ssh binary & config) works, cloning in IntelliJ works, but it always fails in the script. Deleting and migrating it again doesn't make a difference.
The actual error varies seemingly randomly between these:
* Running into a timeout after
Sending command: git-upload-pack 'v3/[...]'
* Corrupted MAC on input. [...] ssh_dispatch_run_fatal: Connection to [...] port 22: message authentication code incorrect
* ssh: connect to host ssh.dev.azure.com port 22: Undefined error: 0
(once only so far)
After some experiments I've nailed it down to the "clone from gitlab, then clone from azdo" sequence in the script:
#!/usr/bin/env bash
#
# [...]
rm -rf "$WORK"
mkdir -p "$WORK"
git clone "${GL_URL}${GL_PROJECT}.git" "$WORK/gitlab"
git clone "${DO_URL}${DO_PROJECT}" "$WORK/azdo"
# [...]
If I comment out the gitlab line or switch the lines (cloning from azdo first) everything works like a charm.
And I can also replicate that 100% reliably without a script in my interactive shell (zsh):
* git clone ..gitlab.. ; git clone ..azdo..
=> clone from azdo fails
* git clone ..gitlab.. ; sleep 1 ; git clone ..azdo..
=> clone from azdo fails
* git clone ..gitlab..
and once it finishes paste & run git clone ..azdo..
=> clone from azdo fails
* (Edit) git clone ..azdo.. ; git clone ..gitlab..
=> clone from gitlab fails
* git clone ..gitlab.. ; sleep 5 ; git clone ..azdo..
=> everything works
I've diffed the output from GIT_SSH_COMMAND="ssh -vvv" git clone ...
from both failed and successful runs and found no difference prior to the error.
Soo - how can it be that two git clone operations, running one after the other, even with a few seconds in between, operating on different remotes and local dirs, reliably influence each other to the point of the second operation failing? Has anyone else experienced anything like this?
My environment:
* OS: MacOS Sequoia 15.5
* Interactive shell: zsh 5.9 (arm64-apple-darwin24.0)
* Script shell: GNU bash, version 3.2.57(1)-release (arm64-apple-darwin24)
* git version 2.47.0 (installed via homebrew)
creinig
(176 rep)
Jul 15, 2025, 08:37 AM
• Last activity: Jul 16, 2025, 08:26 AM
3
votes
2
answers
1277
views
Check if a number is in a range with zsh
Why is passing 0 as an argument results in a false positive (prints "True")? ``` #!/bin/zsh k="$1" if ((0 < k < 1)) then echo "True" fi ``` Note this script is called stitch_applier.sh Terminal ``` % ./stitch_applier.sh 0 True ``` This was run on a Linux system.
Why is passing 0 as an argument results in a false positive (prints "True")?
#!/bin/zsh
k="$1"
if ((0 < k < 1))
then
echo "True"
fi
Note this script is called stitch_applier.sh
Terminal
% ./stitch_applier.sh 0
True
This was run on a Linux system.
visual360
(41 rep)
Apr 20, 2021, 10:41 AM
• Last activity: Jul 7, 2025, 04:30 PM
2
votes
1
answers
112
views
In zsh 5.9-4+b6 on Debian, are INC_APPEND_HISTORY_TIME and SHARE_HISTORY really mutually exclusive?
In my .zshrc, I had ```zsh setopt HIST_IGNORE_ALL_DUPS INC_APPEND_HISTORY_TIME AUTO_CD ``` so that issuing `setopt` yielded ``` autocd histignorealldups incappendhistorytime interactive monitor shinstdin zle ``` However, opening two xterms in parallel and typing in certain commands in one shell and,...
In my .zshrc, I had
setopt HIST_IGNORE_ALL_DUPS INC_APPEND_HISTORY_TIME AUTO_CD
so that issuing setopt
yielded
autocd
histignorealldups
incappendhistorytime
interactive
monitor
shinstdin
zle
However, opening two xterms in parallel and typing in certain commands in one shell and, in parallel, other commands in another shell didn't transfer the commands from the history of one shell to the history of the other.
I changed the .zshrc options line to
setopt HIST_IGNORE_ALL_DUPS SHARE_HISTORY INC_APPEND_HISTORY_TIME AUTO_CD
so that, upon reopening the two xterms, setopt
yielded
autocd
histignorealldups
incappendhistorytime
interactive
monitor
sharehistory
shinstdin
zle
Only then did the commands typed in in one shell start appearing in the history of another shell (though the history got transferred to the other shell only after any command in the other shell had been issued).
In the Manual and Info pages of zshoptions, we read in the para for INC_APPEND_HISTORY_TIME:
“[…] This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are turned off. The three options should be considered mutually exclusive.”
So, apparently, I did the useless thing (having both options simultaneously), and it worked. Is the documentation outdated, or does some other magic happen?
To compare, I tried
setopt HIST_IGNORE_ALL_DUPS SHARE_HISTORY AUTO_CD
in .zshrc. This way setopt
produced
autocd
histignorealldups
interactive
monitor
sharehistory
shinstdin
zle
and the results were undistinguishable from having both SHARE_HISTORY and INC_APPEND_HISTORY_TIME: the commands typed in concurrently in two different shells merged after being issued (namely, after any next command typed into the shell where we read the history) while the two shells were running. However, the way I interpret the documentation, I'd expect that SHARE_HISTORY without INC_APPEND_HISTORY_TIME would write history commands of a shell to the history file only after the shell is finished; before the shell process terminates, its history would be unavailable for other zsh processes in RAM. That's another mismatch between the documentation and the behavior, isn't it?
user743115
(1 rep)
Jun 29, 2025, 05:08 PM
• Last activity: Jun 30, 2025, 05:44 AM
1
votes
1
answers
2168
views
Reset default key binding zsh
I've modified a key binding and know I don't know how to return to what it did before. Basically I've been trying what some key bindings did and which one worked for me and know I want to go back to the default.
I've modified a key binding and know I don't know how to return to what it did before.
Basically I've been trying what some key bindings did and which one worked for me and know I want to go back to the default.
user96101
May 7, 2020, 12:38 AM
• Last activity: Jun 25, 2025, 11:29 AM
1
votes
1
answers
2092
views
LS_COLORS not respected on Cygwin
Whilst trying to configure ls' colors on Cygwin (specifically the distro babun), I found that the custom extension colors that were in the LS_COLORS environment variable weren't being used. Here's an example: `di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:*.tar=...
Whilst trying to configure ls' colors on Cygwin (specifically the distro babun), I found that the custom extension colors that were in the LS_COLORS environment variable weren't being used. Here's an example:
di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:*.tar=1;31
Normally, the ls
command should output white text for every file EXCEPT .tar files, which should be red. However, what I'm getting is white text for everything INCLUDING .tar files. I wonder if it's a problem with MSYS ls
, or if it's a problem with my shell (zsh).
Basically, the custom file extension colors that I try and define fall back to the default file color.
Here's the corresponding part of my .zshrc
where I've defined the ls
alias and run the output of dircolors
.
eval "dircolors /etc/DIR_COLORS
"
alias ls="/bin/ls --color=auto"
IllinoisJackson
(11 rep)
Mar 21, 2017, 09:14 PM
• Last activity: Jun 22, 2025, 03:05 PM
6
votes
1
answers
232
views
bash & zsh friendly process substitution
In bash I'm using this common pattern where null-terminated list of process output is processed in a loop, e.g. ```sh declare -a commits while IFS= read -r -d $'\0' c; do commits+=("${c%% *}") done < <(git log --color=always --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -m -e --ansi --re...
In bash I'm using this common pattern where null-terminated list of process output is processed in a loop, e.g.
declare -a commits
while IFS= read -r -d $'\0' c; do
commits+=("${c%% *}")
done < <(git log --color=always --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -m -e --ansi --reverse --exit-0 --print0)
Is there a shell-agnostic way to achieve this process substitution, so it'd work both in bash & zsh? Latter hangs with this form.
laur
(790 rep)
Jun 19, 2025, 11:55 AM
• Last activity: Jun 20, 2025, 06:29 AM
9
votes
4
answers
3723
views
How can a zsh script test whether it is being sourced?
The [accepted answer][1] for a similar question for `bash` does not seem to work for `zsh`. In fact, if I copy basically the same code given in that answer, to produce the script #!/usr/bin/zsh - # test.sh [[ $_ != $0 ]] && echo "sourced\n" || echo "subshell\n" the output hardly ever corresponds to...
The accepted answer for a similar question for
bash
does not seem to work for zsh
. In fact, if I copy basically the same code given in that answer, to produce the script
#!/usr/bin/zsh -
# test.sh
[[ $_ != $0 ]] && echo "sourced\n" || echo "subshell\n"
the output hardly ever corresponds to the actual situation:
zsh% chmod +x ./test.sh
zsh% env -i /usr/bin/zsh -f
zsh% ./test.sh
sourced
zsh% /usr/bin/zsh ./test.sh
sourced
zsh% /bin/bash ./test.sh
sourced
zsh% source ./test.sh
subshell
zsh% . ./test.sh
subshell
zsh% env -i /bin/bash --norc --noprofile
bash-3.2$ ./test.sh
sourced
bash-3.2$ /usr/bin/zsh ./test.sh
sourced
bash-3.2$ /bin/bash ./test.sh
sourced
bash-3.2$ source ./test.sh
sourced
bash-3.2$ . ./test.sh
sourced
When the current interactive shell is zsh
, the script gets it exactly wrong every time. It fares a bit better under bash
(though in a way reminiscent of the stopped watch that gets the time exactly right twice a day).
These truly *abysmal* results give me little confidence in this approach.
Is there something better?
kjo
(16299 rep)
Apr 19, 2013, 02:20 PM
• Last activity: Jun 18, 2025, 12:41 PM
1
votes
0
answers
17
views
zsh: Menu is not activated for custom completion widget
A custom completion widget is defined as follows, and menu completion is enabled. With this config, when I press ` `, the candidates are displayed as expected, but the menu is not activated. The menu is activated when completing file names, etc. with ` `. Also strangely, once the menu is enabled for...
A custom completion widget is defined as follows, and menu completion is enabled.
With this config, when I press ``, the candidates are displayed as expected, but the menu is not activated.
The menu is activated when completing file names, etc. with ``.
Also strangely, once the menu is enabled for file name completion, it will also be enabled for `` from the next time.
I would like the menu to be enabled by `` even immediately after starting the shell. How can I do this?
setopt menu_complete
autoload -Uz compinit && compinit -u
zstyle ':completion:*' menu select=1
my-complete() {
local suggestions=(foo bar baz)
compadd -J word -o nosort -U $suggestions
}
zle -C my-complete .complete-word my-complete
bindkey '^O' my-complete
aosho235
(227 rep)
Jun 15, 2025, 12:15 PM
2
votes
2
answers
2732
views
Don't save failed command to history?
I'm using snippet code below to exclude all failed commands (return code 1) from saving to zsh history: ``` zshaddhistory() { whence ${${(z)1}[1]} >| /dev/null || return 1 } ``` But if the command is an alias `lsl` (alias lsl='ls -l') the failed command will still be inserted into zsh history: ``` l...
I'm using snippet code below to exclude all failed commands (return code 1) from saving to zsh history:
zshaddhistory() { whence ${${(z)1}} >| /dev/null || return 1 }
But if the command is an alias lsl
(alias lsl='ls -l') the failed command will still be inserted into zsh history:
lsl whatever_folder_doesnt_exist
whatever_folder_doesnt_exist
doesn't exist and I observe lsl whatever_folder_doesnt_exist
still in zsh history.
Here I want to exclude all command that return code is not 0
, how can I do that?
raring-coffee20
(1855 rep)
May 6, 2020, 07:54 AM
• Last activity: Jun 11, 2025, 09:56 AM
0
votes
1
answers
71
views
Unable to use zparseopts
I'm having issues with `zparseopts` and it looks like Brew didn't install it correctly. See this simple test below (all similar tests fail): ``` ❯ short_test_zpo() { autoload -Uz zparseopts || { echo "🔴 Autoload FAILED"; return 1; } local my_flag zparseopts -E -- f=my_flag -- "$@" # Use "$@"...
I'm having issues with
zparseopts
and it looks like Brew didn't install it correctly.
See this simple test below (all similar tests fail):
❯ short_test_zpo() {
autoload -Uz zparseopts || { echo "🔴 Autoload FAILED"; return 1; }
local my_flag
zparseopts -E -- f=my_flag -- "$@" # Use "$@" to pass args from func call
if (( ${#my_flag[@]} )); then
echo "✅ zparseopts PARSED the -f flag."
echo " Remaining args: $@"
else
echo "❌ zparseopts DID NOT parse the -f flag (or -f was not given)."
echo " Remaining args: $@"
fi
}
❯ short_test_zpo some arg
short_test_zpo:3: zparseopts: function definition file not found
❌ zparseopts DID NOT parse the -f flag (or -f was not given).
Remaining args: some arg
I read online that perhaps zparseopts
is expected to be under functions
, but that doesn't seem to be the case for me:
❯ ls -l $(brew --prefix)/share/zsh/functions/zparseopts
ls: /opt/homebrew/share/zsh/functions/zparseopts: No such file or directory
Reinstalling zsh works successfully (see the trace below), but does not seem to make a difference:
❯ brew reinstall zsh
==> Downloading https://ghcr.io/v2/homebrew/core/zsh/manifests/5.9-3
Already downloaded: /Users/amelio/Library/Caches/Homebrew/downloads/2913dc2cb6e58f61f4261bc20839152f766b9eaf2f55e601c528b77f4c91a364--zsh-5.9-3.bottle_manifest.json
==> Fetching zsh
==> Downloading https://ghcr.io/v2/homebrew/core/zsh/blobs/sha256:93cacab325d2a9
Already downloaded: /Users/amelio/Library/Caches/Homebrew/downloads/655b05f05860b07b382da3cd3866feb12706ed25b0a4d381ff276f1ba84c6d18--zsh--5.9.arm64_sequoia.bottle.3.tar.gz
==> Reinstalling zsh
==> Pouring zsh--5.9.arm64_sequoia.bottle.3.tar.gz
🍺 /opt/homebrew/Cellar/zsh/5.9: 1,579 files, 16MB
==> Running brew cleanup zsh
...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew
).
### My output from brew config
:
❯ brew config
HOMEBREW_VERSION: 4.5.3
ORIGIN: https://github.com/Homebrew/brew
HEAD: dc0f9d50fd170492a33fd7234d06de1b94df363c
Last commit: 4 days ago
Branch: stable
Core tap JSON: 28 May 05:12 UTC
Core cask tap JSON: 28 May 05:12 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 3.4.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.4/bin/ruby
CPU: dodeca-core 64-bit arm_blizzard_avalanche
Clang: 16.0.0 build 1600
Git: 2.39.5 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.5-arm64
CLT: 16.2.0.0.1.1733547573
Xcode: N/A
Rosetta 2: false
### My output from brew doctor
❯ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
icu4c@76
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libfido2.1.14.0.dylib
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.
Unexpected header files:
/usr/local/include/fido.h
/usr/local/include/fido/*
Warning: Unbrewed '.pc' files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.
Unexpected '.pc' files:
/usr/local/lib/pkgconfig/libfido2.pc
Any suggestions on what may be going on, or what I could try to diagnose further?
Amelio Vazquez-Reina
(42851 rep)
May 29, 2025, 09:38 PM
• Last activity: Jun 10, 2025, 01:19 PM
1
votes
1
answers
1923
views
why is zsh oh-my-zsh prompt slow on ubuntu 22.04
I need some help determining why my shell is slow and what I can do to fix it. This is a new machine running Ubuntu 22.04. Not only does it start slow, but enter/return is also quite slow. I have tried commenting out all the plugins and custom config that was added but after restarting the terminal,...
I need some help determining why my shell is slow and what I can do to fix it. This is a new machine running Ubuntu 22.04. Not only does it start slow, but enter/return is also quite slow.
I have tried commenting out all the plugins and custom config that was added but after restarting the terminal, I noticed no difference.
.zshrc
# If you come from bash you might have to change your $PATH.
zmodload zsh/zprof
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/kay/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work)
# See https://github.com/ohmyzsh/ohmyzsh/issues/5765
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git docker zsh-autosuggestions tmux brew)
#ZSH_TMUX_AUTOSTART=true
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run alias
.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
#
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
fi
}
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
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
eval "$(pyenv init -)"
[[ -s "/home/kay/.gvm/scripts/gvm" ]] && source "/home/kay/.gvm/scripts/gvm"
**set -x**
https://pastebin.com/zs7D035d
**zprof**
https://pastebin.com/H4zKA0yE
Kay
(113 rep)
Jul 17, 2022, 09:00 AM
• Last activity: Jun 6, 2025, 07:09 PM
2
votes
2
answers
2043
views
zsh autocomplete without completing prompt
Tried to find this answer, but could not. I am new to zsh, and I like it a lot on my Mac. I am looking for an option to set it to autocomplete, but without putting the completion in the prompt until I hit enter. For example, if I type: cd Documents/ and then press tab, it will highlight the options...
Tried to find this answer, but could not.
I am new to zsh, and I like it a lot on my Mac. I am looking for an option to set it to autocomplete, but without putting the completion in the prompt until I hit enter.
For example, if I type:
cd Documents/
and then press tab, it will highlight the options but ALSO add them to the prompt, so I have to either tab a ton to get to the one I want, or delete back. Here is what I mean:
cd Documents/ (press tab)
it shows:
$ cd Documents/Apple
Apple Banana Durian
Orange Starfruit Tamarine
But I am going through the list to get to Tamarine--I want to see the options and be able to continue to tab through them, but not have them added to my current prompt until I hit Enter.
Is this possible?
unsetopt automenu
Gets me close, but then I cannot tab through the options.
Does that make sense?
Thanks!
nomeelnoj
(21 rep)
Jul 2, 2017, 08:38 AM
• Last activity: Jun 4, 2025, 01:03 PM
Showing page 1 of 20 total questions