Questions tagged [zsh]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
10 views

zsh command expansion applies esacping [duplicate]

I have a string S, for which I want to replace every b character with \\ (two forward slashes). So this is what I have: $ S="abc" $ A=$(echo $S | sed 's/b/\\\\/') In bash I get the expected ...
user avatar
4 votes
1 answer
31 views

zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?

Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
user avatar
3 votes
2 answers
34 views

Exporting zsh history separated by ‘\0’ characters instead of ‘\n’

I want to access zsh history with entries separated out by \0 instead of \n. The built-in parser can clearly handle multiline entries, because fc 123 brings up an editor with newlines preserved. ...
user avatar
  • 133
1 vote
1 answer
46 views

How to send output to next input line?

This my snippet alias hst="history 1 -1 | cut -c 8- | uniq | fzf ". when I run hst The output is $ ~ hst (the output from hst) $ This is what I want $ ~ hst $ (the output from hst) Example ...
user avatar
1 vote
2 answers
37 views

What is the different use for setopt and zstyle?

I don't understand why they are both needed since they seem that zstyle does the same as setopt and even more?
user avatar
  • 11
6 votes
2 answers
327 views

How to source some shell code not a file?

There is a description of a source command: source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period). For ...
user avatar
  • 271
1 vote
0 answers
21 views

How do diagnose occasional shell lag?

I am using zsh with a bunch of plugins (Python venv, git status, etc). Occasionally, when I cd to a directory, it waits for a couple of seconds before letting me type in commands. When I cd to the ...
user avatar
  • 205
1 vote
1 answer
43 views

Terminology: terminal command to be invoked from any directory?

Context: macOS Catalina zSh. The end goal is to be able to setup user scripts so that they can be invoked via CLI at an arbitrary data location. Question: What is the word (Terminology) for: the ...
user avatar
  • 1,114
0 votes
2 answers
43 views

How to get 'man gfind' when I enter 'man find'?

On my new-ish mac os/Darwin system, my find tool is an 11-year-old BSD version. I have used MacPorts to install a more current version: GNU's find, which MacPorts has named gfind, and placed in /opt/...
user avatar
  • 2,196
0 votes
1 answer
31 views

create zsh function with argument for ldapsearch

I have a couple commands I can run directly on the command line without issue, when I run them and replace $1 with the actual group name I want to check in LDAP. Now I want to turn it into a ...
user avatar
  • 103
0 votes
1 answer
26 views

Command to open new shell and block

My AUR helper runs a command to open the package files for inspection before proceeding to build and install. This needs to block, because after the program exits, the AUR helper will ask me to ...
user avatar
  • 205
0 votes
0 answers
13 views

add additional method to be displayed with auto complete to oh-my-zsh plugins

I recently migrated to oh-my-zsh and would like to add additional method besides the default plugin provided auto complete methods. is there a way I can do it? I know I can use alias but that will not ...
user avatar
  • 101
2 votes
0 answers
15 views

error: component download failed for rls-aarch64-apple-darwin: could not download file from

I want to using mirror address to speed up the rust package download, so I add the mirror address like this: RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install stable but ...
user avatar
-1 votes
1 answer
30 views

zsh: tab rotates between directories, what key to select and enter one?

I am trying to complete path within a directory tree. When I press tab at any directory level, completion rotates among all possible directory completions. Is there a way to bind a key to "select&...
user avatar
1 vote
1 answer
38 views

Retrieve last command when Chaining

When chaining commands in zsh using ;, && and ||, how can I access the previous command in chain (the command that is being executed before)? Example: rm foo ; echo ... In place of the dots, ...
user avatar
  • 13
3 votes
0 answers
48 views

ctrl+z doesn't send htop to the background

I'm using zsh on macOS 12.4, apple M1. When I run htop normally using the command htop and use ctrl+z it behaves as expected and sends the process to the background. I can evoke it again using the fg ...
user avatar
  • 83
1 vote
1 answer
47 views

Assigning an array value in zsh for gsettings keybindings automation

I think this script should work to set keybinds, but it's currently quite borked--UPDATE: it has been unborked, and now works. It is ugly though, and I'm soliciting ways to make it more elegant, as I ...
user avatar
0 votes
1 answer
51 views

How can i create sub directories within a directory? [closed]

I am trying to make a photo organizer with a zsh shell script. But i am having trouble creating sub directories within each main directory(based on date). Currently the script starts from a folder i ...
user avatar
1 vote
0 answers
30 views

Autocompletion not working for pass password manager in zsh in linux

I already used pass program for password managing on MacOS with zsh (where the autocompletion worked flawlessly out of the box) and now trying to move on linux on a raspberry pi 4b 4GB, installed zsh ...
user avatar
  • 329
2 votes
0 answers
62 views

How to paste selection from vi-mode to clipboard

I want to access the content of what I copied in the buffer with the vi-mode of the clipboard via the command ctrl + v or ctrl + shift + v in the terminal. I copied in my .zshrc the following: (from ...
user avatar
  • 329
4 votes
3 answers
607 views

Print exit status code after each command in terminal

I would like to print at every lauched command in zsh exit code value. E.g. $ cat file_not_present cat: file_not_present: No such file or directory Exit code 1 I only know that I can print error code ...
user avatar
-2 votes
2 answers
53 views

How to compress a simple shell script onto one line?

a friend of mine made this super cool shell script that I want to convert into one line of code. After converting it and executing it, I noticed it wasn't working as it was meant to. There are no ...
user avatar
2 votes
1 answer
36 views

Two Enter Keys are behaving Differently

I am using the alacritty terminal emulator under Zorin 16. My two enter keys are giving different output. % showkey -a Press any keys - Ctrl-D will terminate this program ^M 13 0015 0x0d ^J 10 ...
user avatar
  • 1,329
2 votes
2 answers
154 views

How to get unix time of 11PM, and 11PM CST tonight using BSD's date command?

BSD's date -j -f seems to mix seconds and minutes from the current time of the day while still accepting '%H%p' in the time format. All I want to do is convert input format to correct unix time. Also, ...
user avatar
0 votes
0 answers
38 views

Weird issue occurs when using the Alacritty terminal emulator

I have tried asking this on Alacritty's GitHub issues tab and just got this: This is an issue with your system, likely related to _TERM_ or your _PS1_. The issue is as follows: SOMETIMES, when a ...
user avatar
  • 3
1 vote
1 answer
41 views

zsh function with fzf selection requires Enter

I wrote a simple zsh function which allows me to select from the dirs-stack via fzf. My .zshrc looks like DIRSTACKSIZE='99' setopt PUSHD_IGNORE_DUPS # change to directory from the dirs stack fzf-...
user avatar
  • 239
0 votes
2 answers
31 views

ZSh script to batch process filenames containing spaces and substitute extension

Is there a zsh script that can convert a directory files in one music format and be converted into Ogg opus format. The filenames have spaces in their names. For example, a directory contains 10 ...
user avatar
  • 101
1 vote
1 answer
37 views

repair arch linux console

I was configuring my new arch linux that I just installed. When I was installing zsh, I executed the command usermod --shell /usr/bin/zsh $USER, after executing that I got I realized that I forgot to ...
user avatar
  • 11
0 votes
1 answer
33 views

Run cargo command in subdirectories with user-specified arguments

I've a directory structure like: rust/ ├── dir1/ │ └── Cargo.toml └── dir2/ └── Cargo.toml I want to create a zsh script that'll run from the rust directory, and for each subdirectory with a ...
user avatar
1 vote
0 answers
12 views

define hierarchy of history files for ZSH

My zsh syncs history across terminals. Sometimes this is useful. But many times I just need the last command ran on a specific terminal. So I'd like to have two history files in use by each terminal ...
user avatar
1 vote
1 answer
30 views

How to automate the process to open 3 shells and run 3 commands?

I set up something so that I'd open up 3 shells and run the programs one by one: cd foo/bar ./foo.sh cd foo/bar node bar.js cd foo/bar ruby foobar.rb However, since it is time consuming, so I wrote ...
user avatar
1 vote
1 answer
26 views

Find recursively minimum one *.flac file, if no *.cue file in same dir print directory name

I need help doing a search for folder(s) with minimum one *.flac-file, but only prints the folder name(s) if there is NOT a *.cue-file(s) in the same folder. Is there echo, find, grep, ls, perl, ...
user avatar
0 votes
2 answers
83 views

Rookie Question: Regex in ZSH Script

I think my problem is very simple. I want to construct a new filename, which has a fixed prefix and a number (two digits), which is part of the old filename. Example: I have a file 'blableblub23.pdf' ...
user avatar
  • 1
0 votes
2 answers
40 views

What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully?

Say that https://example.nosuchtld https://example.net https://example.org https://example.willfail is the content of urls.txt. I want to run <command> <url> for every URL/line of urls....
user avatar
0 votes
0 answers
30 views

Linux bash not working properlly [duplicate]

I am trying to run the following script on a OpenSuse machine: OUR_REPO=$(git branch | grep "*" | awk '{print $2}') THE_REPO_THAT_OURS_IS_BASED_ON="origin/$OUR_REPO" GIT_COMMIT=$(...
user avatar
  • 121
1 vote
1 answer
44 views

ZSH: How to set an associative array name and content dynamically?

I'm setting my associative array this way: $ foo=test $ set -A $foo "a b" "1 2" "c d" "3 4" $ for key val in "${(@kv)test}"; do echo "$key -> $...
user avatar
0 votes
1 answer
40 views

zsh: how to get associative array length?

As seen in another post for arrays, I tried this: test[1]="hello" test[7]="foo" test[3]="world" echo ${#test[@]} 7 But it gives me the last index of the associated array....
user avatar
0 votes
1 answer
42 views

zsh in tabby separate history for each tab

I want to keep history separated for each tab (even for split windows within one tab). I therefore found a solution to add these two lines after source $ZSH/oh-my-zsh.sh: source $ZSH/oh-my-zsh.sh ...
user avatar
  • 101
10 votes
1 answer
635 views

Different behaviour of subshells and && in bash vs zsh

My understanding of running commands in subshells is that the current shell is forked, and the subshell then does a further fork and exec on the desired commands. I see strange behaviour when running ...
user avatar
1 vote
3 answers
65 views

How to get a shorter Path prompt in powerline10k / zsh?

everyone! In my iterm2 (with zsh, oh-my.zsh and powerline2) terminal if I go to certain directories I have a prompt like this: $ pokemon/electric/pichu/pikachu/raichu I'd like to have a shorter, but ...
user avatar
  • 11
0 votes
1 answer
22 views

How can I suppress *:// from tab completion suggestions for 'open'?

I have experience this in OS X in zsh shell, man page for open. $ type open open is /usr/bin/open $ man open OPEN(1) General Commands Manual OPEN(1) ...
user avatar
  • 229
3 votes
1 answer
43 views

zsh - How do I prepend a string to every element of an array?

Say I have a zsh array ARRAY=(a b c), and want to prepend my_ before every element in the array to get (my_a my_b my_c), how do I do that?
user avatar
  • 421
0 votes
1 answer
17 views

opening default path for root user

It may be trivial what I say, but I need to change the default opening path that OH My ZSH has. since no matter where I preposition myself in a file path (example: /home/username/Downloads/owt), when ...
user avatar
0 votes
1 answer
29 views

Which file(s) are being sourced while opening a terminal on Mac?

So there are these files, which are being known for keeping environmental variables, aliases, custom shell functions etc.: .bash_profile .bashrc .zshrc and after installing oh-my-zsh (which I'm using)...
user avatar
  • 101
0 votes
2 answers
22 views

match number range with non significative zeros in zsh

I have in a directory files like this : booklet-001.pdf booklet-002.pdf booklet-003.pdf … booklet-997.pdf booklet-998.pdf booklet-999.pdf Then, I whant to match the files numbered from 079 to 256. ...
user avatar
  • 960
1 vote
1 answer
49 views

evaluate terms in zsh without a command

I am using zsh with the prezto configuration framework. I want to be able to type in terms like 1 + 2 * (3 / 4) and get "2.5" out of it. Those terms could be recognized because they only ...
user avatar
  • 113
1 vote
0 answers
12 views

Disable necessity hitting character when a suggestions lines count is larger than the window height in zsh-autosuggestions

When I start typing any command, for example git , plugin zsh-autosuggest make suggestions that is working right. However, if my window is small, suggestions don't fit into the screen and "At Top:...
user avatar
0 votes
1 answer
475 views

Error while trying to source a .zshrc file

What am I doing wrong here? % echo "export HOMEBREW_GITHUB_API_TOKEN=XXXX">> ~/.zshrc; % source ~.zshrc; zsh: no such user or named directory: .zshrc
user avatar
1 vote
1 answer
97 views

Variable Scope in ZSH: How to access global variables from within function?

I have an ever-expanding .zshrc file that was getting out of hand so I decided to try to fix it by breaking it into modular files and sourcing each of them. This works for the most part, but I seem ...
user avatar
  • 123
1 vote
1 answer
48 views

zsh parameter substitution

This page has a demo function as follows: ~inews> namedir () { $1=$PWD ; : ~$1 } But when I try it on my machine, it produces the following error: namedir: no such file or directory: test=/home/...
user avatar

1
2 3 4 5
53