New answers tagged

1 vote

GNU Make target completion with Zsh with Included make files

zstyle ':completion:*:make:*:targets' call-command true zstyle ':completion:*:*:make:*' tag-order 'targets' this worked for me, for 2 level makefile "include": just add to your .zshrc file. ...
oba's user avatar
  • 111
2 votes
Accepted

zsh: check exit code of pipeline of commands

Two options: set the pipefail option from ksh (set -o pipefail), then the exit status of a pipeline will be that of the right-most pipeline component that failed. set -o pipefail if ! A | B | C; then ...
Stéphane Chazelas's user avatar
0 votes

Is there a zsh equivalent of bash builtin readarray?

There is one for zsh called mapfile, but it's a module and must be loaded to use, and it's not a function unlike readarray. zmodload zsh/mapfile filename='...' filelines=("${(@f)mapfile[$filename]...
smac89's user avatar
  • 1,284
3 votes
Accepted

zsh: no such file or directory error even though the file exists

Looks like you downloaded hyperfine for the wrong architecture, like you're on a GNU/Linux x86_64 system and you downloaded https://github.com/sharkdp/hyperfine/releases/download/v1.17.0/hyperfine-v1....
Stéphane Chazelas's user avatar
0 votes

Portable check empty directory

If you don't need to consider dot files: test your_dir/* = "your_dir/*" 2>/dev/null && echo 'empty' || echo 'not empty' Mind the difference between the path your_dir/* and the ...
hh skladby's user avatar
1 vote
Accepted

zsh ignores zshrc most of the time (but not always)

So after endless fiddling and even switching from NixOS to Arch on my desktop I finally figured out what the problem was! Turns out that when I set ZDOTDIR in my .zshrc zsh started ignoring not only ...
beccasaurus's user avatar
3 votes

Listing filenames with special characters

To answer my own question, setting export LC_ALL="en_US.UTF-8" in my .zshrc file solved the issue!
a06e's user avatar
  • 1,667
1 vote

Listing filenames with special characters

As pointed out by @kusalananda, the issue might be your locale. What are the values of your LC_* variables (e.g LC_ALL)? I managed to reproduce the issue by setting LC_ALL=C. To change your locale you ...
qqqq's user avatar
  • 21
0 votes

What is the difference between which and where

Difference 1: I would like to mention a nice functional difference I observed from your question itself: which will list the first path, the passed argument was found. where will list all of the paths,...
Kartikeya's user avatar
  • 101
1 vote

Write catalogue file names in to a file with additional string at the beginning end of a specific name

printf 'string1(%s)string2\n' * Would print a string1(filename)string2 line for each of the non-hidden files in the current working directory, sorted lexically, or fail with an error if there was no ...
Stéphane Chazelas's user avatar
3 votes
Accepted

bash: string variable contains asterisk. how to use this variable for searching etc with grep, sed?

For grep, you can use -F to use fixed strings instead of regexes. For sed, it's much more complex. I'd probably switch to Perl which can help you with its \Q/quotemeta function. #!/bin/bash s="...
choroba's user avatar
  • 45.9k
1 vote
Accepted

Write catalogue file names in to a file with additional string at the beginning end of a specific name

Adding a string to the beginning and end is quite easy: $ ls file1.txt file2.txt file3.txt $ ls | sed -e 's/^/string1/' -e 's/$/string2/' string1file1.txtstring2 string1file2.txtstring2 string1file3....
terdon's user avatar
  • 235k
0 votes

oh-my-zsh's prompt is slow: how to fix this

Mac users: +prompt_git is what's taking so long but a new Xcode license is the real culprit. If you use git that is bundled with Xcode, it's likely that there's an updated license that you needed to ...
h3rrmiller's user avatar
  • 13.1k
-1 votes

Is there a shell which can rapidly allow reordering arguments?

Answer Still Under Construction OK I took another crack at it today with a new helper (GPT4), and I got very far with it already. Take a gander at what we have already: function move-current-arg-left {...
Steven Lu's user avatar
  • 2,193
2 votes
Accepted

Using grep with ps and column width specification

Assuming sed supporting -E, limiting command to 30 characters: ps -eo pid,user,command | sed -E 's/^( +[^ ]+ +[^ ]+ +)(.{30}).*$/\1\2/g' using awk, pid column formatted to width 6 (assuming the pid ...
Vilinkameni's user avatar
11 votes
Accepted

What does mean `^(*.c|*.md)`

In Zsh, ^ is a glob operator available when EXTENDED_GLOB is set, matching anything except the following pattern. The parentheses group a pattern; this is useful in particular with disjunctions (|) ...
Stephen Kitt's user avatar
4 votes
Accepted

Run `git commit -m` with single quotes in zsh

TL,DR: don't. What you're asking for is impossible. When you write gc My $message here, this is an instruction to expand the value of the variable message and use the expansion as part of the ...
Gilles 'SO- stop being evil''s user avatar
0 votes

How and why does using redirection or writing files within an if statement affect exit code?

I conclude from this that using [[ ... ]] is not suitable for evaluating successful command execution, unless successful command execution is understood in a way such that the command's output results ...
pming's user avatar
  • 23
1 vote

String Length Always Returns 2 in ZSH Function

#!/bin/zsh IFS=$'\n' # make newlines the only separator set -f # disable globbing zsh -f, like csh -f is to skip reading startup files, not to disable globbing (except when in sh/ksh ...
Stéphane Chazelas's user avatar
2 votes

String Length Always Returns 2 in ZSH Function

A couple of diagnostic bits that show what is happening. With the line echo rand $1 ${#1} >&2 added to the randString function, this is the output: temp.txt 8 rand \1 2 rand \2 2 rand \3 2 me ...
Gairfowl's user avatar
  • 488
4 votes
Accepted

How and why does using redirection or writing files within an if statement affect exit code?

$? In the PARAMETERS SET BY THE SHELL section of man zshparam, or info zsh 'Parameters Set By The Shell' you'll see that, $? is the exit status returned by the last command. $(...) In man zshexpn or ...
aviro's user avatar
  • 3,905
2 votes
Accepted

What do these strings, '\M^?' and '^\M?', represent in zsh/ZLE?

^? is the byte 127 = 0x7f, which is commonly sent by the Backspace key (unless it's set to send ^H and the Delete key is set to ^?). \M^? or \M-^? is the same but with the upper bit set, i.e. 255 = ...
Gilles 'SO- stop being evil''s user avatar
2 votes

Shell one-liner for batch renaming music albums folders according to regexp – “zsh: missing identifier after `+'”

In zsh, you'd use zmv to rename files: autoload -Uz zmv # best in ~/.zshrc zmv -n '(*PESTE NOIRE*-)(*) \((<1900-2100>)\)' '$1 $3$2' Remove the -n (dry-run) to actually do it. Some problems in ...
Stéphane Chazelas's user avatar
1 vote

Shell one-liner for batch renaming music albums folders according to regexp – “zsh: missing identifier after `+'”

Use singlequotes ( ' ) instead of backquotes ( ` ) to quote the sed expression
Olivier Dulac's user avatar
0 votes

Recover overwritten .zshrc with still-running zsh

I had the same issue. Luckily, the ~/.zshrc.backup file had the previous contents of my .zshrc file. I copied its contents to restore. I suggest checking ~/.zshrc.backup if you haven't closed any tab ...
alph's user avatar
  • 1
5 votes

zsh -z test meaning of "+x"

${var+string} is the same operator as in the Bourne shell (from the late 70s) and in any POSIX shell (including bash). You can find it described in the zsh documentation in info zsh 'Parameter ...
Stéphane Chazelas's user avatar
3 votes
Accepted

zsh -z test meaning of "+x"

This is a parameter (variable) expansion syntax that's also found in Bash. Probably in most other Bourne-style shells, too. The only thing special to zsh in your example is the variable being tested....
Sotto Voce's user avatar
  • 3,923
3 votes

zsh -z test meaning of "+x"

This isn't due to test, but on zsh variable expansion. The construct ${foo+bar} will return bar if $foo is set. So, for example: zsh% unset foo zsh% echo ${foo+bar} zsh% foo= zsh% echo ${foo+bar} bar
Stephen Harris's user avatar

Top 50 recent answers are included