most recent 30 from unix.stackexchange.com2026-03-01T05:15:49Zhttps://unix.stackexchange.com/feeds/tag?tagnames=zshhttps://creativecommons.org/licenses/by-sa/4.0/rdfhttps://unix.stackexchange.com/q/2738242user541686https://unix.stackexchange.com/users/62522011-12-22T04:46:50Z2026-02-27T14:51:52Z
<p>How do I <em>properly</em> do a <code>for</code> loop in reverse order?</p>
<pre><code>for f in /var/logs/foo*.log; do
bar "$f"
done
</code></pre>
<p>I need a solution that doesn't break for funky characters in the file names.</p>
https://unix.stackexchange.com/q/7419494Nicole I.https://unix.stackexchange.com/users/5678592023-04-04T20:26:01Z2026-02-27T06:48:41Z
<p>I am running the latest macOS and using <code>zsh</code>, and I am having trouble writing a shell script. I do most of my work from the command line, and I wanted a script to automatically save and log all my input commands and output.</p>
<p>My most obvious choice was the <code>script</code> command, generally initiated on the command line as</p>
<pre class="lang-bash prettyprint-override"><code>script -a <filename>.txt
</code></pre>
<p>I wrote a shell script, <code>log.sh</code>, whose contents are below:</p>
<pre class="lang-bash prettyprint-override"><code>#! /bin/sh
echo "Welcome to the jungle."
# get date
now=$(date +%Y_%m_%d)
# create filename
fname='log_'$now'.txt'
# file save location
floc=~/path/to/directory/$fname
# start script
script -a -q $floc
</code></pre>
<p>This starts a script where the filename is today's date, and the transcript is saved in a designated directory. This works fine, except for the contents that are written to the file. Instead of just the expected plan text inputs/outputs, I get what I believe are ANSI characters, making the file difficult to read.</p>
<p>Here is what my command line looks like:</p>
<pre class="lang-bash prettyprint-override"><code>$ bash log.sh
Welcome to the jungle.
$ echo "Hello world"
Hello world
$ exit
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
</code></pre>
<p>And how it is recorded in the log file:</p>
<pre class="lang-none prettyprint-override"><code>[1m[7m%[27m[1m[0m
]7;file://<myname>/Users/<myusername>
[0m[27m[24m[J[36m<myusername> [38;5;246m~[39m$ [K[?2004heecho "Hello world! "[?2004l
Hello world
[1m[7m%[27m[1m[0m
]7;file://<myname>/Users/<myusername>
[0m[27m[24m[J[36m<myusername> [38;5;246m~[39m$ [K[?2004heexit[?2004l
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
</code></pre>
<p>I am aware there are a few ways to handle the ANSI keys after creating the file, such as using the <code>cat</code> command to display the text or a Perl script to remove the keys. However, using the <code>cat</code> command is annoying when I am trying to look through a large file, and manually cleaning it up is tedious. Is there any way I can record my command-line inputs and outputs <em>without</em> the ANSI keys?</p>
https://unix.stackexchange.com/q/6241680wardwhttps://unix.stackexchange.com/users/105062020-12-12T20:08:01Z2026-02-26T10:02:30Z
<p>I've noticed that calling <code>xdg-open</code> from a subshell will reliably block until the launched process is closed. I suspect there may be a reason for this, but I'm not sure as to why. For example, launching Nautilus doesn't block when calling <code>xdg-open</code> directly from the command line:</p>
<pre><code>xdg-open ~/dir ; echo foo # doesn't block
</code></pre>
<p>but invoking xdg-open from a subshell will reliably block the terminal</p>
<pre><code>var=$(xdg-open ~/dir ; echo foo) # blocks
{ xdg-open ~/dir ; echo foo ; } | cat # blocks.
</code></pre>
<p>My understanding is that <code>xdg-open</code> detaches the launched process from the shell session so that it's no longer a subprocess. I'd therefore expect this to be different to e.g. invoking <code>sleep 1 &</code> in a subshell for which it seems reasonable that the terminating subshell will block until all subprocess have completed, i.e.</p>
<pre><code>var=$(sleep 1 & echo foo) # also blocks, but understandable.
</code></pre>
<p>But if <code>xdg-open</code> is detaching the process, what's causing the subshell to wait?</p>
<p>In what may (?) be a partial answer, I've noticed that running</p>
<pre><code>{ xdg-open <file> ; ps ; } | cat
</code></pre>
<p>shows that depending on program launched by <code><file></code>, those that block are also the ones that keep the tty as their controlling terminal. That begs the question why this happens, why this happens only in a subshell and ultimately what's a good way to a launch desktop process from the terminal that will fully and reliably detach from it?</p>
<p>Edit: fix syntax on <code>bash</code>.</p>
https://unix.stackexchange.com/q/7102491Eyal Solomonhttps://unix.stackexchange.com/users/5341832022-07-18T07:13:47Z2026-02-23T20:04:25Z
<p>Using iTerm2 with tmux and zsh. I have an issue that new tmux panes doesn't source <code>~/.zshrc</code> file</p>
<p>I have customized my terminal (when running <code>source ~/.zshrc</code> manually it works) but when opening new pane (<code>C+b</code> and <code>c</code>) it doesn't source the file</p>
<p><code>~/.tmux.conf</code></p>
<pre><code>set -g default-terminal "screen-256color"
set -g default-command /bin/zsh
set-option -g default-shell /bin/zsh
</code></pre>
<p><code>~/.zshrc</code></p>
<pre><code>export ZSH="$HOME/.oh-my-zsh"
plugins=(git tmux)
ZSH_TMUX_AUTOSTART=true
source $ZSH/oh-my-zsh.sh
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='mvim'
fi
export TERM=xterm-256color
eval "$(starship init zsh)"
</code></pre>
<p>iTerm settings
[<img src="https://i.sstatic.net/vzFUV.png" alt="iTerm settings1" /></p>
<p>current terminal (on new pane)
<a href="https://i.sstatic.net/Jm9Mb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Jm9Mb.png" alt="current status" /></a></p>
<p>wanted terminal (on new pane)
<a href="https://i.sstatic.net/oIt9c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/oIt9c.png" alt="enter image description here" /></a></p>
https://unix.stackexchange.com/q/5622944Paul J. Lucashttps://unix.stackexchange.com/users/447332020-01-15T17:21:55Z2026-02-21T16:00:40Z
<p>I recently switched from bash to zsh. When typing a new command in bash (in vi mode), if I type Esc-_ (escape underscore), it inserts the last argument of the previous command. I want to do the same thing in zsh. (Currently, it just beeps at me.) How can I get what I want?</p>
https://unix.stackexchange.com/q/7101561Kayhttps://unix.stackexchange.com/users/4946102022-07-17T09:00:01Z2026-02-17T13:03:50Z
<p>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.</p>
<p>I have tried commenting out all the plugins and custom config that was added but after restarting the terminal, I noticed no difference.</p>
<p>.zshrc</p>
<pre><code># 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"
</code></pre>
<p><strong>set -x</strong></p>
<p><a href="https://pastebin.com/zs7D035d" rel="nofollow noreferrer">https://pastebin.com/zs7D035d</a></p>
<p><strong>zprof</strong></p>
<p><a href="https://pastebin.com/H4zKA0yE" rel="nofollow noreferrer">https://pastebin.com/H4zKA0yE</a></p>
https://unix.stackexchange.com/q/5743300BlackCaphttps://unix.stackexchange.com/users/1368282020-03-22T22:46:38Z2026-02-06T15:26:41Z
<p>How do I change the width of a tab, for indentation, in single- and multi-line commands in ZSH? This is not the same as literal tabs; when you hit the tab key, ZSH actually emit spaces to the terminal:</p>
<pre class="lang-bsh prettyprint-override"><code>zsh -f # Run without config
blackcap% echo $'\t.'
.
blackcap% .
blackcap% if
if> .
blackcap% tabs 4
blackcap% echo $'\t.'
.
blackcap% .
blackcap% if
if> .
</code></pre>
<p>This behavior is not affected by settings in my terminal emulator, <code>setterm --regtabs</code>, nor by the promising-sounding <code>IFS</code> variable mentioned in <code>man zshparam</code>.</p>
<p>I could obviously write my own version and bind it to tab, but this last-resort quickly gets hairy when the cursor is moved, lines wrap, there are more than one line- not to mention <code>>></code> and friends with vi-keys.</p>
https://unix.stackexchange.com/q/6385283weisbrjahttps://unix.stackexchange.com/users/4432652021-03-10T09:29:26Z2026-02-06T06:52:38Z
<p>I wanted to change the tab size (the amount of spaces a tab uses) used in my terminal, but it didn't work.
I then found out, that my shell (zsh) inserts a fixed amount of 8 spaces instead of a tab.
I was able to change the tab size in commands like <code>echo '\t.'</code> to 4 by doing:</p>
<pre><code>tabs 4
</code></pre>
<p>But I could not figure out how to change the amount of spaces zsh inserts.
Is there some way to change this?</p>
https://unix.stackexchange.com/q/3747502nomeelnojhttps://unix.stackexchange.com/users/2387252017-07-02T08:38:40Z2026-02-03T23:05:50Z
<p>Tried to find this answer, but could not.</p>
<p>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.</p>
<p>For example, if I type:</p>
<p>cd Documents/</p>
<p>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:</p>
<pre><code>cd Documents/ (press tab)
</code></pre>
<p>it shows:</p>
<pre><code>$ cd Documents/Apple
Apple Banana Durian
Orange Starfruit Tamarine
</code></pre>
<p>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.</p>
<p>Is this possible?</p>
<pre><code>unsetopt automenu
</code></pre>
<p>Gets me close, but then I cannot tab through the options.</p>
<p>Does that make sense?</p>
<p>Thanks!</p>
https://unix.stackexchange.com/q/6930643belkarxhttps://unix.stackexchange.com/users/5008072022-03-05T18:54:52Z2026-02-03T13:52:32Z
<p>When using Zsh, if I rename a file, the shell sometimes assumes I made a typo in the filename and suggests an alternative. Is there any way disable this specifically for the <code>mv</code> command?</p>
<pre class="lang-bash prettyprint-override"><code>$ mv diff1 diff3
zsh: correct 'diff3' to 'diff2' [nyae]?
</code></pre>
https://unix.stackexchange.com/q/46136011Bruce Johnsonhttps://unix.stackexchange.com/users/3044512018-08-08T19:38:58Z2026-01-27T17:11:17Z
<p>I'm seeing an issue with zsh where a glob character within a variable is not expanding as I would expect. The following example does a better job of explaining it.</p>
<pre><code>$ echo $0
-bash
$ echo $HOME/Downloads/zsh-test/*
/Users/bruce/Downloads/zsh-test/file1 /Users/bruce/Downloads/zsh-test/file2 /Users/bruce/Downloads/zsh-test/file3 /Users/bruce/Downloads/zsh-test/file4
$ file=*; echo $HOME/Downloads/zsh-test/$file
/Users/bruce/Downloads/zsh-test/file1 /Users/bruce/Downloads/zsh-test/file2 /Users/bruce/Downloads/zsh-test/file3 /Users/bruce/Downloads/zsh-test/file4
Macbook% echo $0
zsh
Macbook% echo $HOME/Downloads/zsh-test/*
/Users/bruce/Downloads/zsh-test/file1 /Users/bruce/Downloads/zsh-test/file2 /Users/bruce/Downloads/zsh-test/file3 /Users/bruce/Downloads/zsh-test/file4
Macbook% file=*; echo $HOME/Downloads/zsh-test/$file
/Users/bruce/Downloads/zsh-test/*
</code></pre>
<p>I would have expected the last command to expand like it does in bash. Any idea what I'm doing wrong?</p>
https://unix.stackexchange.com/q/37351917UTF-8https://unix.stackexchange.com/users/1477852017-06-26T18:13:29Z2026-01-27T16:53:05Z
<p>I stumbled upon this behavior of zsh when using FreeBSD:</p>
<pre><code>% dd if=/dev/zero bs=1M count=1 of=~/test2
dd: failed to open '~/test2': No such file or directory
</code></pre>
<p>This really confused me because the same thing works just fine in bash.</p>
<p>I can <code>touch</code> files using tilde in zsh, and then <code>ls</code> them:</p>
<pre><code>% touch ~/test2
% ls ~/test2
/home/christoph/test2
</code></pre>
<p>At first, I assumed that zsh doesn't realize that there comes a path after <code>of=</code> so it didn't expand <code>~</code>. But autocompleting file names works just fine. In fact, if use an existing file name, begin its path with <code>~</code>, and then hit Tab at some point, the path gets expanded in the command I'm typing in.</p>
<p>Why does zsh pass <code>~/test2</code> to <code>dd</code>, not <code>/home/christoph/test2</code>?</p>
<p>zsh behaves the same on Linux. In fact, I executed these commands above and copied their outputs on a Linux machine.</p>
https://unix.stackexchange.com/q/3071982Santhoshhttps://unix.stackexchange.com/users/1876812016-09-01T11:27:12Z2026-01-25T03:03:25Z
<p>I am using archlinux with zsh and python</p>
<pre><code>simha@gauranga ~ % echo $SHELL
/usr/bin/zsh
simha@gauranga ~ % python3 --version
Python 3.5.1
</code></pre>
<p>my .zshrc is</p>
<pre><code>export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
</code></pre>
<p>Once i open a new terminal</p>
<p>I could create a new virtualenv in the following way. (simha is the home folder name and gauranga is the computer name)</p>
<pre><code>simha@gauranga ~ % mkvirtualenv new2
Using base prefix '/usr'
New python executable in /home/simha/.virtualenvs/new3/bin/python3
Also creating executable in /home/simha/.virtualenvs/new3/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/preactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/postactivate
virtualenvwrapper.user_scripts creating /home/simha/.virtualenvs/new3/bin/get_env_details
</code></pre>
<p>Now i am entering the virtualenv</p>
<pre><code>simha@gauranga ~ % workon new3
simha@gauranga ~ %
</code></pre>
<p>if we see above there is no change in the prompt to shown which env in am in.</p>
<p>I have followed the <a href="http://virtualenvwrapper.readthedocs.io/en/latest/tips.html" rel="nofollow">http://virtualenvwrapper.readthedocs.io/en/latest/tips.html</a> for zsh prompt still its not working</p>
<p>the following are the postactivate and postdeactivate files</p>
<pre><code>simha@gauranga ~ % tail -f .virtualenvs/postactivate .virtualenvs/postdeactivate
==> .virtualenvs/postactivate <==
PS1="$_OLD_VIRTUAL_PS1"
_OLD_RPROMPT="$RPROMPT"
RPROMPT="%{${fg_bold[white]}%}(env: %{${fg[green]}%}`basename \"$VIRTUAL_ENV\"`%{${fg_bold[white]}%})%{${reset_color}%} $RPROMPT"
==> .virtualenvs/postdeactivate <==
RPROMPT="$_OLD_RPROMPT"
</code></pre>
https://unix.stackexchange.com/q/5193313Silverrockerhttps://unix.stackexchange.com/users/175612012-10-15T21:12:52Z2026-01-24T15:15:32Z
<p>I have noticed that zsh has a lot of things I see in emacs. I can make a selection with ctrl+space and selecting a region. I can make copies just like in emacs while I stay inside zsh. In emacs I'm able to use my system clipboard (previously with some additional configuration needed but this works out of the box now in emacs). In zsh I can't seem to paste from my clipboard using C-y and copying from zsh to my system cliipboard has the same issue. Is there a way around this?</p>
https://unix.stackexchange.com/q/38172114chrisl-921fb74dhttps://unix.stackexchange.com/users/77682012-05-08T20:02:06Z2026-01-20T21:36:51Z
<p>I'm looking to switch from bash to zsh but concerned about compatibility of bash scripts. </p>
<p>Are all bash scripts/functions compatible with zsh? Therefore, if that is true is zsh just an enhancement to bash?</p>
https://unix.stackexchange.com/q/766977-1Andreashttps://unix.stackexchange.com/users/5990732024-01-15T16:11:08Z2026-01-19T11:18:28Z
<p>I have set up iTerm2 to change its profile when I ssh to a specific machine. This works as intended (I am using <code>zsh</code> and <code>oh-my-zsh</code>).</p>
<p>The main thing I do for this is in my <code>~/.zshrc</code> file:</p>
<pre><code>echo -e "\033]1337;SetProfile=<profile_name>\a"
</code></pre>
<p>This sets the colors as defined in "Colors" in iTerm2's "Profile". So far, so good.</p>
<p>I have downloaded the <a href="https://iterm2colorschemes.com/" rel="nofollow noreferrer">color profile called "Harper"</a> and would like to use it with the "41m column" (in lack of a better term). As far as I understand that basically means I have to set the terminal's background color to "red" (which is what "41m" means).</p>
<p>But I cannot figure out how to do this...</p>
<p>I have tried (for example):</p>
<pre><code>echo -e "\033]1337;SetProfile=<profile_name>\a"
echo -e "\033]1337;SetColors=bg=c00\a"
</code></pre>
<p>or</p>
<pre><code>echo -e "\033]1337;SetProfile=<profile_name>\a"
echo -e "\033]1337;SetColors=bg=f00\a"
</code></pre>
<p>Which makes iTerm show a red background and use (for example) the foreground colors defined in the Harper color scheme. But that's not what I want.</p>
<p>My question is very similar to (not to say the same) what was asked in a Stackoverflow question: <a href="https://stackoverflow.com/q/34257198">Iterm2 colors - using the 42m or 41m options</a>. But that question does not have an answer.</p>
<p>By the way, I know that most instructions on the Internet seem to use a different OSC command (50 instead of 1337), but according to <a href="https://iterm2.com/documentation-escape-codes.html" rel="nofollow noreferrer">iTerm2's documentation</a>, that is outdated:</p>
<blockquote>
<p>The OSC command 50 used to be used but it conflicts with xterm, so it is now 1337.</p>
</blockquote>
<p>Is it even possible to do what I intend?</p>
https://unix.stackexchange.com/q/8032862pseyferthttps://unix.stackexchange.com/users/1504432025-12-24T17:08:34Z2026-01-17T22:37:35Z
<p>I'm writing a completion definition for the carbon tool and try to get the <code>carbon compile</code> subcommand right. from the help message, the interesting bits</p>
<pre><code>Subcommand `compile` usage:
carbon [OPTIONS] compile [OPTIONS] <FILE>... -- [<CLANG-ARG>...]
Subcommand `compile` positional arguments:
FILE
The input Carbon source file to compile.
CLANG-ARG
Additional Clang arguments. See help for `--clang-arg` for details.
Subcommand `compile` options:
…
--output=FILE
The output filename for codegen.
</code></pre>
<p>I already have the subcommand handling in place - this question is solely on the <code>[OPTIONS] <FILE>... -- [<CLANG-ARG>...]</code> part.</p>
<p>My current draft is</p>
<pre><code>_arguments -S \
"--output=-[output file]:OUTFILE:" \
"*:FILE: _files -g *.carbon" \
"--:separator" \
"*:CLANG ARGS: _dispatch clang -value-,CPPFLAGS,-default-"
</code></pre>
<p>i.e. I have</p>
<ul>
<li>the <code>-S</code> flag for <code>_arguments</code> such that <code>--output</code> doesn't get suggested after <code>--</code></li>
<li>the <code>*:</code> form for <code>CLANG ARGS and </code>FILE` because either can be multiple</li>
</ul>
<p>what's missing:</p>
<ul>
<li>currently the completion is ill-formed. two blocks of <code>*:</code> seem incorrect usage</li>
<li>if I comment out either of <code>FILE</code> or <code>CLANG ARGS</code>, they get suggested before and after <code>--</code>. What I am looking for is a way to say "these only before <code>--</code>" and "these only after <code>--</code></li>
<li>having the <code>--:separator</code> entry seems wrong</li>
</ul>
<p>I have been wondering that this might not be possible with <code>_arguments</code> alone and that I might need to write some zsh code to check if <code>--</code> is in the words array before the current word and then have then/else branches that call <code>_arguments</code> with the appropriate completions. I appreciate that this would certainly be possible, but would like confirmation that that's the only/canonical way to handle different positional arguments before and after <code>--</code> and that i'm not re-implementing something that <code>_arguemnts</code> already provides.</p>
https://unix.stackexchange.com/q/5487463Calebhttps://unix.stackexchange.com/users/19252019-10-25T15:50:19Z2026-01-13T14:21:51Z
<p>In spite of heavy <code>tmux</code> use and switching between panes, I still frequently find myself using shell job control. When something needs poking I'll background the tool I'm using with <kbd>Ctrl</kbd>+<kbd>Z</kbd>, poke the thing, then <code>fg</code> the tool again. The issue is sometimes the "poking" turns into using another tool and I want to go back and forth a couple times.</p>
<p>Would it be possible to bind another key that is trapped by the shell (i.e. not ever passed though to a foreground app) that backgrounds the current job and foregrounds whatever the most recent background job is?</p>
https://unix.stackexchange.com/q/8034050Kamilhttps://unix.stackexchange.com/users/5966182025-12-31T11:26:35Z2026-01-01T15:30:49Z
<h1>The problem</h1>
<p>In tmux, I use the <code>tmux-resurrect</code> plugin with <a href="https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_pane_contents.md" rel="nofollow noreferrer">pane contents restore</a> feature.</p>
<p>The plugin saves the state inc. the pane contents, but when I start the server again, two issues appear:</p>
<ol>
<li>2 empty lines with my command prompts are printed in <code>stdout</code></li>
<li>my CWD is lost (it goes back to home)</li>
</ol>
<ul>
<li><a href="https://drive.proton.me/urls/E062QNPDM8#riGx3scau4Xl" rel="nofollow noreferrer">Here is a screencast to better understand the long explanation</a></li>
</ul>
<p>For example, in a session window I have not used for 2 days the command prompt is printed 9 times.</p>
<p>I tested if a new command prompt line is printed with each restore inside every window of every session, but that is not the case. Not even just for the active session (currently focused, or focused). It's more arbitrary than that, but...</p>
<p>After a few days, the empty command prompt can take up the whole screen which is annoying and not as it ought to be.</p>
<h1>Env</h1>
<pre><code>System:
Host: debian Kernel: 6.12.38+deb13-amd64 arch: x86_64 bits: 64
Desktop: Xfce v: 4.20.1 Distro: Debian GNU/Linux 13 (trixie)
Tmux version: 3.5a
// tpm is up-to-date and it freshly sourced the plugins
</code></pre>
<p><code>tmux.conf</code>:</p>
<pre><code># Use Ctrl-Space as prefix
unbind-key C-b
set-option -g prefix C-Space
bind-key C-Space send-prefix
set -s prefix-timeout 1000
set -g status-style bg=red,fg=white
# make page up/down just work
set -g mouse on
setw -g mode-keys vi
#bind -n PageUp copy-mode -u
#bind -n PageDown send-keys PageDown
# sets zsh as default tmux shell
set-option -g default-shell /bin/zsh
# sets up right status bar
set -g status-right 'Continuum status: #{continuum_status}#{?client_prefix, #[fg=00ff00][PFX],}'
# sets up left status bar to remove [username]
set -g status-left-length 30
set -g status-left ' [#S]'
# Format for inactive windows (just the name)
setw -g window-status-format ' #{window_name} '
# Format for the currently active window (styled name)
# Using #[reverse] is a common way to highlight
setw -g window-status-current-format ' #[reverse] #{window_name} '
set -g status-justify centre
# Cyberpunk status bar
set -g status-style bg='#111111',fg='#00ff00'
#set -g status-left '#[fg=#ff00ff,bold]#S #[fg=#00ffff]#I:#P #[default]| '
#set -g status-right '#[fg=#ffff00]%H:%M #[fg=#ff00ff,bold]#H'
set -g window-status-current-style 'fg=#00ff00,bg=#000000,bold'
#set -g window-status-current-format '#I:#W#F'
set -g window-status-style 'fg=#555555,bg=#000000'
#set -g window-status-format '#I:#W#F'
# Plugin options set before initialising them
set -g @continuum-save-interval 15
set -g @continuum-restore 'on'
set -g @resurrect-capture-pane-contents 'on'
##### Always keep this at EOF #####
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'tmux-plugins/tmux-sessionist'
set -g @plugin 'tmux-plugins/tmux-open'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'
#run-shell ~/Repositories/Misc/tmux-pain-control/pain-control.tmux
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.config/tmux/plugins/tpm/tpm'
</code></pre>
<p>Note: I use tmux-sensible which you should know when investigating as it changes many defaults.</p>
<h2>Closing thoughts</h2>
<p>I suspect this might be related to how tmux handles login vs. non-login shells. Currently, I have default-shell set to /bin/zsh, but default-command is unset (defaulting to a login shell).</p>
<h1>Other</h1>
<pre><code>kamil ~/Documents/ai-prompts$cd / && exec /bin/zsh -l
kamil /$pwd
/
kamil /$ls -l /proc/"$PPID"/exe
lrwxrwxrwx 1 kamil kamil 0 Jan 1 12:09 /proc/4206/exe -> /usr/bin/tmux
kamil /$
</code></pre>
https://unix.stackexchange.com/q/7923401sidyllhttps://unix.stackexchange.com/users/70042025-03-12T13:11:31Z2025-12-26T19:58:34Z
<p>I'm using a git post-receive hook to perform some actions
after a git push to a remote server. This remote operates
over SSH:</p>
<pre><code>$ git remote -v
server user@server:repo.git
</code></pre>
<p>The problem is that this hook is written in Perl, and using
a Perl version different from the system Perl (managed with
Perlbrew). When the script executes, after the push (which
runs perfectly) it fails due to the script using a different
version — that is, the script supposed to run with the
modern Perlbrew Perl gets executed with the system Perl. It
is also important to note that the script starts with:</p>
<pre class="lang-perl prettyprint-override"><code>#!/usr/bin/env perl
</code></pre>
<p>I assume this happens because the SSH through git does not
read my <em>.zprofile</em> file, which is where all of the Perlbrew
setup happens. Why is that? If it is over SSH, shouldn't it
open a shell from my user and consequently read the profile?</p>
<p>Is there a way to make this work with my custom Perl?</p>
https://unix.stackexchange.com/q/1625182user72394https://unix.stackexchange.com/users/723942014-10-16T14:15:25Z2025-12-24T22:05:20Z
<p>How can I install oh-my-zsh from master on the machine behind firewall and without git and internet access?</p>
https://unix.stackexchange.com/q/6803530Profpatschhttps://unix.stackexchange.com/users/318102013-03-15T10:17:26Z2025-12-24T17:18:13Z
<p><code>${!FOO}</code> performs a double substitution in <code>bash</code>, meaning it takes the (string) value of FOO and uses it as a variable name.<br>
<code>zsh</code> doesn’t support this feature.</p>
<p>Is there a way to make this work the same in <code>bash</code> and <code>zsh</code>?</p>
<h3>Background:</h3>
<p>I’ve got a list of environment variables, like</p>
<pre><code>PATH MAIL EDITOR
</code></pre>
<p>and want to first print the variable names and afterwards their values.</p>
<p>This works in <code>bash</code> but not <code>zsh</code>:</p>
<pre class="lang-sh prettyprint-override"><code>for VAR in LIST
do
echo $VAR
echo ${!VAR}
done
</code></pre>
<p>It should be somehow possible “the old way” with <code>eval</code>, but I can’t get it to work:</p>
<pre class="lang-sh prettyprint-override"><code>for VAR in LIST
do
echo $VAR
echo `eval \$$VAR`
done
</code></pre>
<p>I’m never going to understand why I can’t simply do arbitrary deep substitutions like <code>${${VAR}}</code> or even <code>${${${VAR}}}</code> if need be, so an explanation for that would be nice, too.</p>
https://unix.stackexchange.com/q/7343431Konrad Rudolphhttps://unix.stackexchange.com/users/36512023-02-04T16:48:36Z2025-12-24T17:08:34Z
<p>I have a <code>PS1</code> set up in my <code>.zshrc</code> which includes multiple ANSI escape sequences. An equivalent definition works nicely in Bash, but in Zsh (v5.8.1) it seemingly causes the shell to calculate the width of the prompt incorrectly. As a consequence, when entering longer commands, the command line <em>suddenly vanishes</em>, and I am typing blind. And in cases it leads to the cursor being placed on the next line after the prompt, even though the <code>PS1</code> does not include a line break.</p>
<p>I am already using the <a href="https://superuser.com/a/301355/2269"><code>\001…\002</code> escape sequences</a> that are used by readline to adjust the length calculation around each ANSI escape sequence. Unfortunately this seems to be insufficient for Zsh (in the example below they don’t seem to have <em>any</em> effect, but in my real, more complex <code>PS1</code>, they seem to improve the situation <em>somewhat</em>, at least).</p>
<p>Here’s an example to demonstrate the issue (the comment underlines the ANSI escape sequence parts that I believe need to be bracketed by <code>\001…\002</code>):</p>
<pre><code>PS1=$'\001\e[38;2;1;1;1m\e[48;5;250m\002}\001\e[38;5;250m\e[48;2;1;1;1m\002} '
# \001--------------------------\002 \001--------------------------\002
</code></pre>
<p>With this prompt, and using an 80 column terminal, after I type 25 characters, the entire command including prompt vanishes. Using backspace does not make the characters reappear, but instead makes the cursor go to the previous line.</p>
<p><a href="https://asciinema.org/a/2GjmnytLQ01UvoqCNbdqwVSxr" rel="nofollow noreferrer">Here’s an Asciinema recording of this behaviour.</a></p>
<p>For this demo I have disabled all other customisation of my shell.</p>
<p>(In reality I am using the <code>nf-pl-left_hard_divider</code>, U+E0B0, from <a href="https://www.nerdfonts.com/cheat-sheet" rel="nofollow noreferrer">NerdFont</a> instead of the <code>}</code>s, but this does not impact the issue.)</p>
<p>What am I doing wrong? How are ANSI escape sequences supposed to be used inside a Zsh prompt definition?</p>
https://unix.stackexchange.com/q/8031690Marcus Müllerhttps://unix.stackexchange.com/users/1066502025-12-20T15:36:02Z2025-12-20T16:04:19Z
<p>I have a keybinding <kbd>ctrl</kbd>+<kbd>x</kbd> <kbd>ctrl</kbd>+<kbd>e</kbd> which uses a zshcontrib functionality (seemingly loaded by default on my Fedora machine) to edit the current command line in <code>$EDITOR</code>. (That function's name is <code>edit-command-line</code>.)</p>
<p>I'd like to always run <code>nvim</code>; that's fine, my <code>$EDITOR</code> is set to <code>nvim</code>.</p>
<p>How do I make sure <code>nvim</code> always interprets the temporary file containing the current line buffer as zsh script? It uses the default text type, because the file type can't be inferred.</p>
<p>Bonus: How do I figure out such things in the future?`</p>
https://unix.stackexchange.com/q/31068313Gabriel Devillershttps://unix.stackexchange.com/users/1669852016-09-18T17:32:35Z2025-12-17T13:03:17Z
<p>In most Unix shells, the arrow-up key <kbd>↑</kbd> replaces the command that is being edited by the previous command in the history.
The history can be seen using the command <code>history</code>.</p>
<p><kbd>↑</kbd> can be pressed more than one time to climb up in the history.</p>
<p>How can I configure my shell so that <kbd>↑</kbd> skips all commands identical to the current one?</p>
<p>Indeed I often enter many <code>make</code> in a row. When I want to enter again (or modify slightly) an older command I have to hit <kbd>↑</kbd> many times just to skip all the <code>make</code> commands.</p>
<p>Bonus:</p>
<ul>
<li>give a configuration for the Bash shell</li>
<li>preserve the history (knowing that you typed a command many times in a row can be useful)</li>
</ul>
https://unix.stackexchange.com/q/54761xenoterracidehttps://unix.stackexchange.com/users/292010-08-16T21:45:38Z2025-12-14T16:06:40Z
<p>I use <code>bindkey -v</code> (for bash-ers <code>set -o vi</code> I think that works in zsh too) or vi(m) mode. but it bugs me that I don't have any visual cue to tell me whether I'm in insert mode or command mode. Does anyone know how I can make my prompt display the mode?</p>
https://unix.stackexchange.com/q/7866333user172877https://unix.stackexchange.com/users/02024-11-14T14:07:12Z2025-12-11T14:02:19Z
<p>I would like to run some code when zle becomes active.</p>
<p>The only way I know how to do that is</p>
<pre class="lang-bash prettyprint-override"><code>zle-line-init() {
echo hi
}
zle -N zle-line-init
</code></pre>
<p>But AFAIK this will replace any potential existing <code>zle-line-init</code> hooks.</p>
<p>How can I either add to existing hooks (like how precmd has a <code>precmd_functions</code> array), or restore the previous state of <code>zle-line-init</code> after my function runs?</p>
https://unix.stackexchange.com/q/3988146Zolomonhttps://unix.stackexchange.com/users/6472012-06-02T14:42:44Z2025-12-10T15:45:18Z
<p>I want to change my shell from bash to zsh.</p>
<p>I have tried running the following while logged in as user zol:</p>
<pre><code>$ chsh -s /bin/zsh
$ sudo chsh -s /bin/zsh zol
$ su -c 'chsh -s /bin/zsh zol'
# The above all results with:
$ password:
$ chsh: Shell not changed.
# zsh exists in /etc/shells..
chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
</code></pre>
<p>What could be wrong? How can I fix it? </p>
https://unix.stackexchange.com/q/6289600shinhttps://unix.stackexchange.com/users/1202932021-01-13T11:39:13Z2025-12-09T18:03:55Z
<p>When I run <code>bindkey -L</code> I see the followings:</p>
<pre><code>...
bindkey "^R" history-incremental-search-backward
...
bindkey "^[n" history-search-forward
</code></pre>
<p>What is the difference between them?
When I try them I can't find any difference.</p>
https://unix.stackexchange.com/q/8015227CarriMegrabyanhttps://unix.stackexchange.com/users/5338872025-11-21T23:55:35Z2025-12-07T15:04:50Z
<p>I am trying to unzip a set of files (3 files). These files contain a lot of random files, duplicate files etc. To do this, I am first unzipping the list of the names of files into a text file, then clean up the files, and then unzipping the files.</p>
<p>I was originally extracting files by extracting all the necessary names of the files into a text file all at once, and then running them through unzip.</p>
<p>For example, I have 3 zip files (file1, file2 and file3) all from the same source. First, I extracted the list of the contents and cleaned them up into unzip.txt, then I ran the following script on the file unzip.txt:</p>
<pre><code>zipdir="/Volumes/filedir"
i=0
while IFS= read -r line; do
i=$((i+1))
for f in $zipdir/*.zip; do
# echo $f
unzip -qq $f $line
done
echo "$i"
done < unzip.txt
</code></pre>
<p>Not all of the files corresponding to each of the lines (in unzip.txt) are in 3 zip files, so I received a lot of errors. I suspect that's because I am unnecessarily running the lines which are not in file1, so it's wasting a lot of unzipping time. I am concerned about this, as I have a much larger set of files I have to run this on.</p>
<p>So I came up with a better way of handling the unzipping using chatgpt, but I am not sure what errors I made:</p>
<pre><code>function unzip1() {
f=$1
echo $f
while IFS= read -r line; do
printf "%s\0" "$line"
done < unzip1.txt | xargs -0 -n 1000 unzip $f
}
</code></pre>
<p>To explain this, I am now extracting only the files corresponding to file1, and then cleaning up the files and then unzipping the files in one single pass. Let's assume that the extraction of the lines into unzip.txt is ok, because I can see that the total number of lines came out to be the same.</p>
<p>The lines have a lot of random characters, so I have to pass it through <code>printf "%s\0" "$line"</code>, to first put a null delimiter at the end of each line, then I pass it through xargs. I have to use xargs because the number of lines in the unzip.txt is very large, so I can't just do a <code>cat unzip.txt</code>.</p>
<p>At the end of this, I was able to get an unzipped archive. However, when I ran the test on the first 3 files using method 1 and method 2, method 2 gave me half of the size of the archive compared to method 1.</p>
<p>Am I doing anything incorrectly?</p>
<hr />
<p>The error in the size of the files is happening because of something to do with xargs. When I use <code>xargs -0</code>, it gives me 30% fewer files, when I use <code>xargs -0 -n 1000</code>, it gives me 20% fewer files, and when I use <code>xargs -0 -n 10</code>, it gives me 5% fewer files. I am not sure what to do with xargs, and switched to the following method of running one line at a time.</p>
<pre><code>function unzip1() {
f=$1
echo $f
while IFS= read -r line; do
unzip -qq $f $line
done < unzip1.txt
}
</code></pre>
<p>There must be a bug in xargs, and how it works with unzip. Is this something that should be reported to xargs, or am I imagining this as a bug?</p>