Skip to main content

Questions tagged [zsh]

Zsh is a shell with many advanced command-line and scripting features.

Filter by
Sorted by
Tagged with
1 vote
1 answer
39 views

Be notified of new mail in any Maildir inbox under ~/Mail, in the Zsh shell

I have a cron job that fetches new mail from several mail servers every 20 minutes. The mail is automatically sorted into Maildir mailboxes in a hierarchy under ~/Mail. I want to be notified in the ...
Kusalananda's user avatar
  • 339k
0 votes
1 answer
40 views

zsh alias does not complete fully if not sourced once a day

vi ~/.zsh alias k='kubectl' complete -o default -F __start_kubectl k alias kga='k get all,ingress' If I do not source .zsh every day it does not take into account the ingress part of the kga alias. ...
dfs's user avatar
  • 1
1 vote
2 answers
49 views

Zsh script to filter array excluding a substring

I'm trying to create a filter that should exclude all items from an array except for those that match a pattern with a substring exclusion. Given myArr=(mySrv-dev-east-prj1 mySrv-dev-west-prj1 mySrv-...
Machtyn's user avatar
  • 113
0 votes
4 answers
112 views

To check whether first or last character of a string is x

I am trying to check whether the first or the last character of a string is x using zsh, and I get an error message instead: ./test.sh:2: bad substitution What is the problem here? string="2x3&...
jsx97's user avatar
  • 73
0 votes
1 answer
84 views

How to make '.zshrc' to search for sourced files in the specific folder and not in the folder from which the terminal has been opened

macOS 14.5, Zsh 5.9. ls -A -- ~/: .zshrc system-wide-clipboard.zsh cat -- ~/.zshrc: autoload -Uz zmv alias zcp='zmv -C' alias zln='zmv -L' . ./system-wide-clipboard.zsh If I open the Terminal ...
jsx97's user avatar
  • 73
-1 votes
1 answer
66 views

To execute a shell script: Using "zsh script.sh" and using "./script.sh"

To execute a random shell script, e.g. script.sh that contains only a single line echo 'foo', I can use zsh script.sh, and this works. But if I try to execute the same file using the dot syntax ...
jsx97's user avatar
  • 73
-1 votes
2 answers
67 views

In bash/zsh, how to compare the metadata in two directories including . and excluding .. and the contents inside subdirectories?

Let's say that in a script, you have a directory $1 and its copy $2 and you'd like to compare the metadata (names, permissions, sizes, full modification dates, …) of the files and directories inside ...
AlMa1r's user avatar
  • 1
1 vote
1 answer
89 views

incrementing file names in zsh

I am trying to write a script in zsh (Linux Mint 21.3 "Virginia") to move (or copy) a file from $source to $target with confusing results. I'm using yad file dialogs to select the files and ...
Terry 's user avatar
  • 35
0 votes
1 answer
43 views

Salesforce dataloader #!/bin/bash script errors mentions .zshrc

I'm trying to run a certain application (Salesforce dataloader v61) on MacOS. The entry point is a bash script: #!/bin/bash DL_INSTALL_ROOT="$(dirname "$(readlink -f "$0")")&...
Al Cher's user avatar
  • 101
0 votes
1 answer
36 views

Saving ZSH history across SSH sessions [duplicate]

Is it possible to keep zsh history consistent across SSH sessions to the same machine? To explain further, let's say I opened an SSH session to another computer, ran mkdir test-dir/, and exited the ...
WoaItsBren's user avatar
0 votes
1 answer
88 views

what is the nature of compgen under zsh (as opposed to bash)?

I am in the process of replicating my development environment under Ubuntu from Macos. A good deal of which consists of porting some utility zsh scripts from one machine to the other. One recurring ...
JL Peyret's user avatar
  • 105
-1 votes
2 answers
70 views

How to prevent duplicate $PATH entries?

I am trying to add $HOME/.local/bin:$PATH to my $PATH. I added it in .zshrc like so: export PATH="$HOME/.local/bin:$PATH" Each time I source the configuration file, the entry gets prepended ...
Kamil's user avatar
  • 7
0 votes
2 answers
233 views

zsh: command not found: yt-dlp

The standalone executable yt-dlp recommended for macOS suddenly stopped working. I used it two weeks ago and it worked. I have not had any updates to my system, expect some brew updates/upgrades. ...
Kamil's user avatar
  • 7
3 votes
2 answers
304 views

Using zmv to batch rename files and resolve filename collisions

This is an approach to rename files to random filenames, suggested by Terdon. The advantage of this approach is that it automatically resolves filename collisions: randomname() { base64 < /dev/...
jsx97's user avatar
  • 73
0 votes
0 answers
69 views

How to setup zsh with fzf history backsearch in tmux (I get zle errors)

I am using tmux with the zsh shell. I try to setup fzf, and I do it like this (inside my zshrc): eval "$(fzf --zsh)" This works, as long as I am not in tmux. I can use Ctrl-R and get the ...
Nathan's user avatar
  • 173
0 votes
1 answer
21 views

Using vi command line editing, can't backspace before cursor after leaving motion mode [duplicate]

I have a minor but annoying issue that when I press Esc in a terminal to edit my command in the command line in vi motion mode, then move the cursor (like with 'w' to move by a word, or even move the ...
labyrinth's user avatar
  • 743
2 votes
5 answers
107 views

How to remove duplicate slashes from path to a file?

I have a path to a file that has duplicate slashes which would like to simplify. For example, if I have the following: /opt//bin//executable I would like to get: /opt/bin/executable
Thesevs SCUTULATUS's user avatar
0 votes
2 answers
88 views

Rename file and convert to lowercase

This command is to rename files using uuidgen: zmv '(*)(.*)' '`uuidgen | head -c 8`$2' Could someone show how to convert resulting string to lowercase?
jsx97's user avatar
  • 73
3 votes
4 answers
1k views

Rename files to random filenames (but not to checksums)

Sometimes I need to batch rename files on a macOS system to random or pseudo-random filenames, eight lowercase letters and digits only, e.g. from mcmurdo-station.png to something like a12bc0xy.png. ...
jsx97's user avatar
  • 73
3 votes
1 answer
367 views

cp -P * vs. cp *(.) vs. cp *(-.)

According to man cp, using cp -P * foo/ means that no symbolic links will be followed: -P: No symbolic links are followed. This is the default if the -R option is specified. But how to copy files in ...
jsx97's user avatar
  • 73
0 votes
1 answer
48 views

Matching numbers using Zsh glob operators: difference between '[0-9]' and '<->'

Is there any difference, either practical or not, to use [0-9] or instead <-> to match numbers, when using zmv? For example, I have tried the following two commands and they seem to work the ...
jsx97's user avatar
  • 73
2 votes
2 answers
191 views

Exclude certain filename suffixes when searching using glob qualifiers

How to exclude one or multiple filename suffixes when searching using glob qualifiers? Works fine, here we match the filename suffix, not exclude them: print -rC1 **/*.(txt)(.) print -rC1 **/*.(jpg|...
jsx97's user avatar
  • 73
3 votes
1 answer
139 views

To understand zmv ## patterns

This is zmv command to non-recursively replace any number of spaces with a single underscore (thanks to Stéphane Chazelas, who helped me with it): zmv -- '* *' '${f// ##/_}' And here is a command ...
jsx97's user avatar
  • 73
5 votes
1 answer
209 views

printf in Zsh does not shell escape exclamation mark

In Zsh 5.9, we can use printf to shell escape a string: $ printf '%q' 'One! Two' One\!\ Two This produces the correct output of escaping the ! and the space. Now let’s make it as a script: #!/bin/...
user137369's user avatar
3 votes
1 answer
167 views

Replace any number of spaces with a single underscore

How it is possible, using zmv, to replace any number of spaces with a single underscore? What I use currently is zmv -- '* *' '$f:gs/ /_' but it replaces each space, and so foo bar.txt become ...
jsx97's user avatar
  • 73
2 votes
1 answer
251 views

Does 'ls' ignore Zsh glob sorting qualifiers?

I try to understand how to use Zsh glob qualifiers with ls. An article on the internet says that to sort the files from largest to smallest, I can use ls *(oL). o<sort> - Sort files depending ...
jsx97's user avatar
  • 73
2 votes
0 answers
45 views

Can't unalias then redefine as a function in the same conditional [duplicate]

Here is a simplified implementation of an issue in my bash/zsh aliases file: alias foobar='echo bar' # this is out of my control if true; then unalias foobar echo we got inside the conditional ...
Adam Katz's user avatar
  • 4,012
0 votes
1 answer
103 views

I can't use the "cat" command

When I run the "cat file.txt" command, I get the response: cat file.txt zsh: command not found: bat This is on Kali Linux 2024.1 that I just installed on VMware Player, updated, and ...
miguele318's user avatar
0 votes
1 answer
68 views

zsh globs: permission denied

You likely don't need find if you're using Zsh. Zsh globs can do most of what find can do through its recursive globbing, extended globs and glob qualifiers. For example, your find ./test-folder -type ...
jsx97's user avatar
  • 73
1 vote
0 answers
34 views

Ignore Accent Differences in Zsh Autocomplete

Suppose I have a directory named cálculo in the current directory. How can I autocomplete its name after typing the starting characters without the accent? $ cd calc<tab> $ cd cálculo/ I failed ...
sidyll's user avatar
  • 207
0 votes
0 answers
195 views

How to debug/analyze a slow zsh prompt (oh-my-zsh)?

I'm using oh-my-zsh, and it used to work well until yesterday. Today, the prompt itself is incredibly slow: When I type a character it can take over a second until it appears on the screen (and the ...
bluenote10's user avatar
0 votes
1 answer
57 views

Aliases working in subjective conditions on Mac

I'm currently working on a dotfiles configuration (which runs zsh) which I've been using on my mini home server and and Linux CLIs on my PC. I've also utilised it on my work Macbook which runs MacOS, ...
Maabat's user avatar
  • 3
1 vote
1 answer
32 views

Relaunch a terminal using a terminal command

Today, to convert from Markdown to PDF using Pandoc, it was necessary to install pdflatex. I did brew install basictex and then it was necessary to relaunch Terminal. For this, I simply closed it and ...
jsx97's user avatar
  • 73
0 votes
1 answer
196 views

crontab /bin/zsh: can't open input file: test.sh

I am trying to create a crontab to run a script: * * * * * cd /Users/test3/Desktop/Scripts/backup/ && /bin/zsh test.sh > /tmp/cron-output.log 2>&1 where test.sh is in /Users/test3/...
Mihail's user avatar
  • 41
4 votes
1 answer
807 views

Zsh: How to workaround "no matches found" issue

I want to check whether filename extensions of my images are correct, that is, whether my JPEGs are really JPEGs, PNGs are really PNGs, and WebPs are really WebPs. For this, I use the following ...
jsx97's user avatar
  • 73
1 vote
1 answer
39 views

How do I tell if my shell is being run from within Dolphin's integrated terminal?

I'd like to choose whether or not to load zsh plugins if the shell is, at the moment, being run within Dolphin. Is this possible? I've considered: ps: ps, at least without any flags, does not seem to ...
Ernest Izdebski's user avatar
0 votes
1 answer
191 views

curl: (3) bad range specification in URL position 98

when I using this command to send a post reqeust on macOS(14.3.1) with zsh : ~ ⌚ 19:56:55 $ curl -X POST https://localhost:8081/infra/alipay/notification/v1/alipaySeverNotification\?...
Dolphin's user avatar
  • 639
1 vote
1 answer
23 views

Maintain position in terminal command history on macOS?

I enter many commands into the terminal. I enter command a, then b, then c, etc. I'm on command g now but I want to execute a, then b, then c, again. I press up (g), up (f), up (e), up (d), up (c), ...
Mario's user avatar
  • 163
1 vote
0 answers
31 views

Can a shell opened via SSH "inherit"/use the same environment as a local shell? Non-interactive shell on MacOS can, "sometimes", not access Keychain

I use Pushbullet and a third party Python script that allows me to send "pushes" from the command line. This script uses MacOS "Keychain" to access passwords and tokens used for ...
d-b's user avatar
  • 1,937
0 votes
1 answer
80 views

Why does find ....-execdir rename miss files? zsh

I'm using zsh on MX Linux 23.2. For years I have tried to figure out why a command like find . -depth -type f -execdir rename 's/_720p//' {} \; skips over files. I know my file manager can't be ...
Terry 's user avatar
  • 35
0 votes
0 answers
27 views

How to correct this script to detect OS type? [duplicate]

I'm trying to modify a Makefile so I can easily run my app by make run run: OUTPUT=${uname -a | awk '{ print tolower($1)}'} bin/${OUTPUT}_${ARCH}/${APP_NAME} Running uname -a | awk '{ print ...
anta40's user avatar
  • 421
0 votes
0 answers
46 views

How to show path after cd command with CDPATH set?

I came across this question and showing the current path after cd is exactly what I'm looking for. However, I can't manage to get this behavior. What I've tried is this: export CDPATH='.:/home/...
Alexander Zeitler's user avatar
1 vote
1 answer
24 views

zsh completion for custom script: URL + optional parameters

I have zsh completion for custom script, where one parameter must be URL (ie, string) and then there are several optional parameters: --AAA --BBB --CCC: _arguments -S : \ '--AAA' \ '--BBB' \ ...
Martin Vegter's user avatar
0 votes
0 answers
263 views

zsh module command not found

I recently switched from bash to zsh on CentOS 7. I am using oh-my-zsh I'm encountering an issue where modules cannot be loaded from a script. When I manually load the module in the login shell, it ...
Adupa Vasista's user avatar
0 votes
1 answer
75 views

Zsh zinit load OhMyZsh plugin skipping aliases

I want to use these plugins using zinit to load git completions in zsh zinit wait lucid for \ OMZL::git.zsh \ OMZP::git But I don't care about the aliases, there are really too much aliases I ...
fchastanet's user avatar
2 votes
0 answers
21 views

Feed GTK File Chooser Dialogue with recently visited directories from zshz database

Often, I find myself performing tasks in the zsh shell and later needing to open or save a file using the GTK File Chooser dialogue in a GUI application, typically located in a directory I recently ...
student's user avatar
  • 18.5k
1 vote
1 answer
61 views

Understanding effect of redirecting output of a function call that makes variable mutation not visible

I observed a weird behavior in zsh 5.9 in mac. (Following is a simplification to reproduce the error, it does not try to make sense). If I execute in a terminal $> function assigner() { OPTIONS=...
Whimusical's user avatar
0 votes
1 answer
53 views

How to specify that an optional argument requires 2 arguments in a zsh competition script?

I am writing a custom competition function for zsh. Currently, I have the following code _arguments \ ... '(-G --glitchpct)'{-G+,--glitchpct=}'[Controls how often the characters on screen glitch]' I ...
Alex.Kh's user avatar
  • 101
1 vote
1 answer
66 views

Why is FPATH not listed in `env` output?

I'm running zsh (on MacOS) and I just learned about $fpath. As usual, I then typed env to check it participating in my environment but to my surprise it was not there! Yet, $FPATH (and $fpath) is ...
Brandt's user avatar
  • 324
0 votes
2 answers
46 views

ZSH documentation for IFS=.- parts=( $=file )

This feature of ZSH (I presume) is used in an answer ZSH Syntax for splitting a string using multiple characters as delimiters Or you could use IFS splitting with $=var: IFS=.- parts=( $=file ) Can ...
alecail's user avatar
  • 1,643

1
2 3 4 5
61