Questions tagged [zsh]
Zsh is a shell with many advanced command-line and scripting features.
2,940
questions
0
votes
0
answers
40
views
Upload a file with SSH and then give back the control to the user
I'm trying to create a script that, when you connect on a remote server with SSH, the script checks things and deploy your personals scripts before giving you back the stdin, all in one SSH connection ...
0
votes
1
answer
27
views
problematic script: query buku, select via fzf and then print using (again) buku
First and foremost, thank you for taking the time to review the question.
I have the following script: select an array of IDs from buku's database, and then use buku again to print information using ...
0
votes
0
answers
25
views
How can I remove aliases "which-command=whence" and "run-help=man"?
I'm running Artix Linux and using zsh, and these two aliases return no matter how many times I unalias them or remove them from my aliasrc:
run-help=man
which-command=whence
And they don't exist in ...
0
votes
0
answers
19
views
How to get exit status of a command in zsh precmd function?
I am using add-zsh-hook precmd with a function so that I can add some contextual information around a command being run.
That said, it seems the invocation of the precmd function does not provide any ...
1
vote
1
answer
32
views
How to disable "long descriptions" of commands in ZSH
I have a program named fhome that provides shell completion for Zsh:
$ fhome <tab>
config -- Manage system configuration
event -- Manage events
help h -- Shows a list of commands or ...
0
votes
0
answers
29
views
why does ZSH pass # and arguments following to process? [duplicate]
I did some experimenting and:
alex.mills@alex wss % node /Users/alex.mills/codes/vibeirl/wss/scripts/arg-test.js -v a # 3
[
'/Users/alex.mills/.nodenv/versions/14.17.0/bin/node',
'/Users/alex....
0
votes
2
answers
47
views
Function with aliased command works with eval but not shell expansion
Below is the function I am trying to execute. The issue seems to relate to the main_cmd being an alias for another command. I though this would only be an issue with sub-shells being spawned, so why ...
1
vote
2
answers
85
views
identify content inside base64 encoded content and replace the whole line
I have a script that outputs some information on my shell, like this:
field1: value1
field2: value2
...
fieldn: valuen
one such field/value can be:
CmdLine: C:\Windows\System32\WindowsPowershell\...
2
votes
1
answer
86
views
Pass ssh remote command from bash to zsh
I am running a remote putty session from windows to my Red Hat Enterprise Linux server.
Due to company restrictions, I am unable to change my Linux user's default shell from bash to zsh. I instead ...
0
votes
0
answers
19
views
OpenFOAM powerlevel10k integration error
I am trying to learn linux to become familiar with opensource CFD tool OpenFOAM. I did everything according to the installation guide and everything went fine. In Bash I had to add the line source /...
1
vote
0
answers
27
views
How to avoid constant rehash in zsh with local binaries?
I have a "virtual env" like setup, where a script prepends a bunch of local executables to $PATH. After setting everything up the script calls hash -r. In bash this works perfectly:
source ...
1
vote
1
answer
51
views
Solve ugly color in ls command
I installed zsh + oh-my-zsh in an archlinux environment.
after that ls command's output became like this:
How I can change folders' color ?
0
votes
2
answers
102
views
In terminal, how to delete a word when cursor is within the word?
I want to achieve functionality similar to c + a + w or d + a + w in vim
In terminal we have Ctrl + w for delete a word in the left and Alt + Backspace from the right But I was not able to find a ...
0
votes
1
answer
33
views
OSX13; how to mv series of x numbers of file chunks simultaneously to the series of directories
I have a following list of files;
260704 96 -rw-r--r-- 1 MacStudio staff 47131 Jul 28 20:18 ./GSM7673474_30_CC0022.barcodes.tsv.gz
260705 6264 -rw-r--r-- 1 MacStudio ...
0
votes
2
answers
68
views
Add a process to an already executing process? Like && or so
This question inspired me to another related question. Imagine that you start
% nohup a.sh &
and then want b.sh to execute when a.sh is finished (E.g., b.sh will process the output from a.sh. ...
14
votes
2
answers
2k
views
Run two scripts after each other in the background? && and & don't work?
I want to run two shell scripts after each other, in the background, preferably also using nohup.
I start with
% nohup a.sh &
This runs a in the background.
% nohup a.sh && nohup b.sh
...
0
votes
0
answers
32
views
Enable filepath autocompletion when adding files with Git in Zsh
Let's say following is the output of my git status command.
On branch LG-201
Your branch is up to date with 'origin/LG-201'.
Changes not staged for commit:
(use "git add <file>..." ...
4
votes
2
answers
552
views
How to get both the number of bytes and the sha1sum with single pass?
I want to get both the number of bytes and the sha1sum of a command's output.
In principle, one can always do something like:
BYTES="$( somecommand | wc -c )"
DIGEST="$( somecommand | ...
0
votes
0
answers
50
views
Is there a way to not exit a shell if jobs are stopped/suspended?
If one types exit and a job is stopped/suspended, the shell will print a warning message instead of exiting.
1: some_command &
[1] 4018347
2: exit
zsh: you have suspended jobs.
But if one types ...
1
vote
0
answers
20
views
How to enable sh emulation mode only when using zsh interactively
When using zsh interactively, I would like it to emulate the behavior of sh as much as possible. I have tried adding emulate sh to the end of ~/.zshrc, but since I am using zsh plugins that rely on ...
2
votes
1
answer
56
views
zsh: How to populate completion candidates with specific order
I would like to populate completion candidates with the exact order specified in the function. From what I understand, -o nosort should do the trick, but it is not working as expected. I must be ...
1
vote
1
answer
36
views
Why is the duration column in .zsh_history usually 0, although the "history -D" command displays it?
Why is the duration column in .zsh_history usually 0, although the "history -D" command displays it?
After testing this answer to What is the purpose of the column with the '0' after ...
0
votes
0
answers
52
views
How to create zsh/bash macro with partial arguments
I'd like to create some functions/aliases in my .zshrc to help with git, but I'm not sure how.
First one:
Full command: git commit -s -m "My message"
My desired end result: gsc -m "My ...
2
votes
1
answer
122
views
What is the purpose of the column with the '0' after the numeric timestamp in .zsh_history?
What is the purpose of the column with 0 after the numeric timestamp in .zsh_history?
: 1568128379:0;cp -a ~/.zshrc.pre-oh-my-zsh ~/.zshrc
: 1568128381:0;exit
Is it part of the timestamp or does it ...
-1
votes
1
answer
120
views
How to Add Space or Padding to Terminal Output?
I don't really know what would be responsible for this. I would bet on my terminal emulator itself (mine is Kitty), but it might be a Zsh (or Oh My Zsh) or Powerlevel10k responsibility.
Anyways, what ...
0
votes
2
answers
119
views
How can I automatically wrap every command in Zsh/Bash with a custom command before execution?
I'm trying to modify the behaviour of the Zsh (or Bash) shell to automatically prepend a custom command, named myapp for example, to all input before it's executed. Essentially, I want to intercept ...
0
votes
2
answers
96
views
Is there a syntax for a "for" loop over words or lines in a variable, that will work unmofdified in both bourne shell and zsh?
I have a variable that contains a list of strings, one per line, to be looped over in a for...in...do...done command.
I move regularly between bourne shell and zsh. As far as I can understand it, zsh ...
0
votes
2
answers
85
views
Cannot sudo a custom function in a zsh script
I want to copy my .dot files (and not .dot directory) in a directory. For this my OS (MacOS) asks me the user password. I created a functions that does that and want to incorporate it in a bigger ...
1
vote
1
answer
148
views
some_variable vs some-variable in zsh
Why is it that zsh seems to understand what to do with some_variable=1 command, but not some-variable=1 command? E.g.: $ fs_screen=1 mpv --fs-screen=${fs_screen} someFile.mp4 works fine but $ fs-...
1
vote
1
answer
162
views
zsh: check exit code of pipeline of commands
I have long pipeline of commands in zsh script:
pv /dev/sda > sda.raw | sha256sum > sda.raw.sha256 | cut -c61-64 | read SHASUM
how can I check inside an if statement, that all commands exited ...
0
votes
1
answer
239
views
zsh: no such file or directory error even though the file exists [duplicate]
I'm getting an error while executing a binary that the binary cannot be found. I can see it using other commands.
>> ls -alh ...
0
votes
0
answers
49
views
Can't restart a suspended process
I execute a long running Python-process. To stop the annoying noise from the fans I use AppPolice to prevent this process from using more than 20 % CPU (I don't care when it finishes).
I think that ...
0
votes
2
answers
90
views
Listing filenames with special characters
I have a zsh shell (with oh-my-zsh default config). Why I ls filenames with special characters, they are printed as:
''$'\316\262''=0.35-L=32-m=10.jld2'
This should be:
β=0.35-L=32-m=10.jld2
but the ...
0
votes
1
answer
83
views
bash: string variable contains asterisk. how to use this variable for searching etc with grep, sed?
Have a nice day
I have got text file (zz.txt):
Chemical name
3-Aminopropane-1-sulphonic acid
Synonym(s)
--
Homotaurine * Tramiprosate
--
Chemical name
Common name and synonyms
...
I have variable
s=&...
1
vote
2
answers
38
views
Write catalogue file names in to a file with additional string at the beginning end of a specific name
In specific directory
using ls | tee -a file.txt
gives me a list from this directory.
Example:
file1.txt file2.txt file3.txt
How to add specific strings inside ls command into final output simply ...
0
votes
0
answers
20
views
When is it more appropriate to use zsh options vs keybind?
Context: I was researching how to make my tab key perform menu completion in zsh. During my search, I found there's two ways (perhaps more) to get this behavior: options and/or keybind.
Is choosing ...
0
votes
0
answers
5
views
In oh-my-zsh, how do I get the bindkey keymap string for the key combination I'm pressing? [duplicate]
I'm trying to make the up and down keys go back and forward in command line history, respectively. While googling how to do this, I saw a lot of commenters giving their opinions on certain keymap ...
0
votes
1
answer
88
views
Using grep with ps and column width specification
I'm trying to limit the column width of the command column when running a ps command, but also trying to pipe that output into a grep command. However, this is not working.
This runs fine:
ps -eo pid,...
1
vote
1
answer
845
views
What does mean `^(*.c|*.md)`
I am sorry if it is a potential obvious question, but I have no idea what ^() means in
ls ^(*.c|*.md)
On zsh, this argument expands to everything but *.c and *.md files.
What is ^?
What does mean ...
1
vote
1
answer
107
views
Run `git commit -m` with single quotes in zsh
I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
1
vote
2
answers
61
views
String Length Always Returns 2 in ZSH Function
I'm trying to bowdlerize email addresses in a fixed length text file by generating a random string the same length as the input. I'm passing the string as a backreference in sed.
To simplify, this ...
2
votes
2
answers
103
views
How and why does using redirection or writing files within an if statement affect exit code?
In zsh
echo 'a string' > test.txt
echo $?
0
and
[[ $(echo 'a string') ]]
echo $?
0
whereas
[[ $(echo 'a string' > test.txt) ]]
echo $?
1
another example
curl -so 'curl-8.2.1.tar.gz' https://...
0
votes
0
answers
63
views
Zsh taking too long to launch on Fedora 38
I recently switched the default shell on my laptop to Z shell. However it randomly takes too long to launch, like 3-10 seconds at a time. I know this is not the norm especially from my experience ...
1
vote
2
answers
51
views
Shell one-liner for batch renaming music albums folders according to regexp – “zsh: missing identifier after `+'”
My music library consists of folders named after the following pattern :
METAGENRE - Subgenre(s) - ARTIST - Album (year)
I want to switch the year and album "tags" in the folders' names for ...
0
votes
1
answer
132
views
zsh ignores zshrc most of the time (but not always)
So when I open a new terminal (kitty) my ~/.zshrc is sourced perfectly fine, oh-my-zsh works, plugins are loaded as well as the p10k theme. But if I, for example, simply run zsh (or tmux) I get a ...
0
votes
0
answers
26
views
Bash equivalent of zsh alias at end of command (for pipes) [duplicate]
In zsh, I can set an alias at the end of a command, e.g. making G pipe through grep or L pipe through less.
Can I do something similar in bash? E.g. ls G key would expand to ls | grep key or ls L ...
1
vote
1
answer
84
views
What do these strings, '\M^?' and '^\M?', represent in zsh/ZLE?
In the documentation for the Zsh Line Editor, there is a section that says:
For either in-string or out-string, the following escape sequences are recognised:
\a
bell character
\b
...
5
votes
3
answers
389
views
zsh -z test meaning of "+x"
I am new to zsh and have been a bash user for years.
In an example zsh script I see a test:
if [ ! -z ${ZSH_MOTD_CUSTOM+x} ]; then
In bash I would expect:
if [ ! -z "$ZSH_MOTD_CUSTOM" ]; ...
0
votes
1
answer
95
views
When simply `| cat -`, I get file descriptor errors
Here's the working diff command:
$ diff -u <(echo 'foo:bar:baz' | tr : "\n") <(echo 'foo:baz' | tr : "\n")
--- /dev/fd/11 2023-08-30 13:11:50
+++ /dev/fd/13 2023-08-30 13:...
0
votes
1
answer
93
views
Why does zsh open at root directory "/"?
I'm using gnome-terminal with zsh on NixOs.
A fresh terminal window opens in the root directory "/". This is eventhough $HOME is correctly set to /home/user.
Next tabs opened in the same ...