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
2 votes
2 answers
36 views

zsh completion - ignore executable files with no dot in the name

I am trying to ignore files that are executable and have no dot in them, because when I am coding in C I don't want to open the binary executable files with neovim. Here is what I am trying to achieve:...
0 votes
1 answer
2k views

Launching a program via `xdg-open` from a subshell without blocking

I've noticed that calling xdg-open 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, ...
5 votes
1 answer
278 views

Zsh: Is it possible to disable history expansion inside double quotes?

Is it possible to disable history expansion inside double quotes? I do not want history expansion to be completely disabled, as I still use it, but I see no reason to expand the history inside a ...
3 votes
3 answers
1k views

Autocomplete of diff command not working in zsh / oh-my-zsh

On MacOS I am using oh-my-zsh with no customization that I know of. Autocompletion is mostly working quite nicely and I'm very happy with it. But for some reason the diff command is different. ➜ ls ...
1 vote
2 answers
2k 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 ...
0 votes
1 answer
21 views

Unzip files, excluding files based on wildcard

I'm trying to extract all the files from a ZIP file, except for files with a specific extension. Succeeds: > unzip myzip.zip Archive: myzip.zip inflating: ... Fails: > unzip myzip.zip -x *....
14 votes
2 answers
3k views

Why doesn't the process substitution <() work with ssh -F

I have some vagrant virtual machines. To log into them I issue the vagrant ssh command. I want to log into them using regular ssh command. The vagrant ssh-config outputs the suitable config file $ ...
3 votes
1 answer
192 views

Random debug messages appearing in terminal, vim, and zsh: "channel 0: window sent adjust [...]" on Ubuntu 22.04

When I use the terminal, vim, or zsh, a message randomly appears on a line, interrupting the text or command: debug2: channel 0: window 999072 sent adjust 49504 Is this a bug? How to fix it? Ubuntu ...
1 vote
1 answer
32 views

Zsh: completion not working for self-defined function based on git

In my .zshrc file I have written a function based on git log: lg() { git log \ --abbrev=12 \ --graph \ --oneline \ --color=always \ --format="%C(cyan)%h %C(blue)%ar %C(...
2 votes
2 answers
68 views

Can you fix this error while creating alias for encryption and decryption by GPG in z-shell?

I wanted to make a .zshrc alias with the help of these previous aliases present to make an alias to convert a compressed gpg to its original uncompressed folder or file... However, I am facing this ...
1 vote
2 answers
521 views

Replace a string in a script without modifying the file, and then to execute it

I have both BSD (default) and GNU Awk implementations installed on a Mac (the latter is envoked using gawk instead of just awk), and I have a shell script with contents like this: awk -v maxLen=72 ' ...
11 votes
3 answers
6k views

In zsh, how can I more quickly disown the foreground process?

My method for disowning the foreground process takes too much effort. Suppose I have a process in zsh's foreground. I want to disown it, so I can close the shell without the process being sent a ...
0 votes
1 answer
119 views

Fastfetch colors not loading everytime

I have fastfetch installed and want a smaller configuration to be started, every time i open a terminal. This in itself works perfectly. However most of the times the colors don't load at all but i ...
4 votes
2 answers
4k views

zsh: locking failed for ~/.cache/zsh/zsh_history: file exists

I have a bind mount ~/.cache/zsh folder between multiple hosts with rw and defaults when doing mount. When I start both machine and zsh trying to lock zsh_history, it gives error zsh: locking failed ...
1 vote
0 answers
35 views

Going to the direcory of a file as fast as posible [duplicate]

Is there a way to get to the path of a file as fast as possible and in the least amount of keystrokes. Context: Type cd and then paste the path of a file and then have to go back and hit backspace ...
2 votes
2 answers
154 views

Repeating zsh brace expansion values in zsh to download multiple files using wget2

I want to download all files named ${n}x${n} from a directory on a website with wget2 on zsh, where n is the same number value both times, with n from 1 to 6000. I've found that specifying all the ...
0 votes
1 answer
38 views

Zsh: Non-reverse history search

In Zsh, to reverse search command history, the keyboard shortcut is Control-R. For example: echo foo echo bar echo baz Then press Control-R > Type ec > You will see echo baz > Press Control-...
5 votes
1 answer
833 views

How to use argument twice in printf in shell?

printf %s%s one two prints onetwo but I would like oneonetwotwo How can I do that?
1 vote
2 answers
106 views

7.5 * 2 results in 15., with a trailing dot. How can I get rid of it?

Using zsh: width=7.25; echo $(( width * 2 )): the output is 14.5 width=7.5; echo $(( width * 2 )): the output is 15., with a trailing dot This seems to be a very basic thing, but I haven't figured ...
1 vote
0 answers
19 views

How to get Zsh to tab-complete to the next file when already completed?

I have a series of files I want to open. I open the first like this: rifle ~/path/to/myfile-part1-title.mp4 I watch the video, close the terminal and the next day I want to watch part2. So I hit CTRL-...
1 vote
2 answers
9k views

"Argument list too long" in ZSH with any command

I wish I could be more thorough in my explanation, but I have been using my same Artix setup for a while now, without any issues I couldn't fix myself. However, after installing VirtualBox (Which I ...
6 votes
2 answers
474 views

Terminal autocomplete (tab) not completing when changing directory up one level (cd ../)

I'm a relative Linux noob: I've worked with the bash shell for quite a while via an Ubuntu install in WSL2 on a Windows 11 machine and recently took the plunge to switch over to Linux 100%. My ...
2 votes
2 answers
312 views

Assign variable a value and copy this value to the clipboard

I believe this is very simple, but I haven't figured it out myself. How is it possible to assign variable a value and copy this value to the clipboard in a really concise way? That is, something like ...
0 votes
2 answers
99 views

To make 'rmdir' and 'find -delete' ignore '.DS_Store' files

On macOS, there is a hidden file .DS_Store in some directories (well, in most of them). The problem with .DS_Store files is that rmdir and find . -depth 1 -type d -empty -print -delete don't delete ...
3 votes
2 answers
116 views

Zsh: Copy or Move symlinks to regular files, but not symlinks to directories (or vice versa)

In Zsh, to copy regular files, I can use cp source-dir/*(.) dest-dir/ to copy directories: cp source-dir/*(/) dest-dir/ to copy everything else, e.g., symlinks, pipes, and devices: cp source-dir/*(^./...
8 votes
1 answer
5k views

Glob character within variable expands in bash but not zsh

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. $ echo $0 -bash $ echo $HOME/...
1 vote
2 answers
675 views

Function to go forward one directory, if possible?

I use below code snippet (by pressing alt-h), to go backward one level of current directory. up-dir() { cd ".." zle reset-prompt } zle -N up-dir bindkey "^[h" up-dir I want similar ...
2 votes
1 answer
91 views

In zsh, annotate each line in a file to which both stdout and stderr have been redirected with the line's source (stdout or stderr)

In zsh, how can I annotate each line in a file to which both stdout and stderr have been redirected with the line's source (stdout or stderr)? I want output with the source name prepended to the line, ...
3 votes
2 answers
168 views

Concise zsh regular expression parameter expansion to replace the last match of a pattern

Is there any concise zsh regular expression parameter expansion to replace the last match of a pattern? I know very ugly way of doing it, but I'd prefer a cleaner, more concise syntax: # param, ...
130 votes
5 answers
178k views

How to define and load your own shell function in zsh

I am having a hard time defining and running my own shell functions in zsh. I followed the instructions on the official documentation and tried with easy example first, but I failed to get it work. ...
2 votes
2 answers
4k views

Installing oh-my-zsh without git

How can I install oh-my-zsh from master on the machine behind firewall and without git and internet access?
1 vote
2 answers
63 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 ...
3 votes
2 answers
170 views

Zsh: enable extended_glob inline in a filename generation glob

In zsh, how can I enable extended_glob inline in a filename generation glob? Say I want to run ls on all paths not named a, which can be done via: setopt -o extendedglob ls ^a But is there any way to ...
0 votes
2 answers
48 views

'ls *(/)' shows nothing if there is only one empty directory

I have a directory ~/test with two empty directories there: emptydir and emptydir2. ls ~/test/*(/) shows them both: ~/test/emptydir: ~/test/emptydir2: But if there is only one empty directory there, ...
2 votes
2 answers
283 views

cd 'old' 'new' with multiple "whole directory-name" substitutions

To move from ~/aaa/foo/bbb to ~/aaa/bar/bbb, one can use cd foo bar and from ~/foobar/foo/www to ~/foobar/bar/www: cd "/foo/" "/bar/" But how is it possbile, using the same ...
1 vote
1 answer
57 views

Use Zsh process substitution in place of mktemp

If you have Pandoc installed, the following script will retrieve its HTML template, write it into a temporary file, make some adjustments, and then pass this file as a parameter: template=$(mktemp ...
1 vote
0 answers
43 views

Key sequences for command/ctrl + backspace

I am trying to create a keybinding for CMD (on Mac)/CTRL (on Linux) + Backspace to delete everything before the cursor. I cannot for the life of me figure out what key sequence I should use. I am ...
7 votes
4 answers
30k views

How to edit a JSON file using shell?

I am building a shell script that uses a JSON file. { "property1": true, "list": [ { "id": 1, "name": "APP1" }, { &...
0 votes
1 answer
87 views

To move files only; To copy folders only

Tested in Bash and Zsh: copy nondot files | cp ~/dir1/* ~/dir2/ copy dot files | cp ~/dir1/.* ~/dir2/ copy both nondot and dot files | cp ~/dir1/{.,}* ~/dir2/ ...
-1 votes
1 answer
43 views

Copy dot files only

In Zsh, to copy regular files only, I use cp -a -- ~/dir1/* ~/dir2/ And to include dot files, I will add the D glob qualifier: cp -a -- ~/dir1/*(D) ~/dir2/ But is there a glob qualifier to copy dot ...
1 vote
1 answer
27 views

Autocomplection with description in zsh

General overview This question complete this other one. I try to set an autocomplete for --test parameter who should suggest a list of possible values (Here “foo” and “bar”). Until theire, it pretty ...
4 votes
1 answer
160 views

Why do backgrounded commands in Zsh functions not show correctly in jobs?

In Bash 5.2, the output of jobs after either of the following is identical modulo job numbers: sleep 3 # press C-z s() { sleep 3; } s # press C-z In both, jobs produces something like [1]+ Stopped ...
1 vote
1 answer
447 views

ZSH + VIM + CTRL-Z => prompt blocking

I open a vim instance in zsh. Afterwards I move it to the background with ctrl-z then again I return to it using ctrl-z again and then I close it using :q my prompt is blocked and I first have to ...
2 votes
1 answer
100 views

Duplicate text on console with SSH

When I SSH into my kali machine from Fedora and try to run a command and press TAB to autocomplete it as below... Then the moment I press TAB it does this: Notice that first sudo? It somehow just ...
3 votes
2 answers
375 views

"history" command ordered by most common

Can I get the output of history sorted in order of most-used? I know how to do it in a programming language, but not from the shell. In my case I'm on macOS with zsh. I know I could use uniq and sort ...
1 vote
1 answer
35 views

omz reload in zsh widget

I am using zsh+oh-my-zsh and I am using the following code to change .zshrc using a hotkey and I am trying to reload omz after the change: function f() { # ... update .zshrc here ... omz reload } ...
30 votes
6 answers
43k views

key bindings table?

Do we have a key bindings table that translates all the various ways of referring to a key press? I'm using zsh, but I presume that if there was such a table it would work for any shell. The reason I ...
1 vote
1 answer
36 views

zsh autocompletion for parametre value

General overview Here is my auto complexion file: _triumphum_complete() { _arguments \ '(- 1 *)'{-h,--help}'[show help options]' \ '(- 1 *)--tui[Run the game selection interface]' \ '(- 1 *)'{-r,...
72 votes
8 answers
61k views

Ctrl + left/right arrow keys issue

After the last system update the ctrl + left/right arrow command on zsh terminal doesn't do anything. Also ctrl+ u has something wrong because usually that command erase from the cursor to the ...
0 votes
2 answers
2k views

ZSH (O-M-Z + powerlevel9k) + glyphs + console only (Ubuntu server edition): How to get all 3 working?

So I have installed ZSH + oh-my-zsh + powerlevel9k on my Ubuntu server edition. While it's working including the colors (I used darkorange background to display current user), I cannot get the glyphs ...

1
2 3 4 5
62