New answers tagged zsh
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.
...
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
...
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]...
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....
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 ...
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 ...
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!
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 ...
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,...
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 ...
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="...
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....
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 ...
-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 {...
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 ...
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 (|) ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 = ...
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 ...
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
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 ...
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 ...
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....
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
Top 50 recent answers are included
Related Tags
zsh × 2916bash × 553
shell × 511
autocomplete × 312
shell-script × 283
oh-my-zsh × 267
macos × 158
terminal × 152
command-history × 148
command-line × 121
wildcards × 119
prompt × 113
alias × 111
linux × 81
tmux × 73
environment-variables × 71
function × 63
keyboard-shortcuts × 61
path × 53
scripting × 51
ssh × 49
colors × 48
zle × 47
quoting × 44
array × 43