Questions tagged [zsh]
Zsh is a shell with many advanced command-line and scripting features.
2,943
questions
0
votes
0
answers
19
views
export -f function results in invalid options in zsh [duplicate]
I want to make my aliases available to sub-shells like this in my ~/.zshrc
say_hello() {
echo "Hello!"
}
export -f say_hello
However when I'm sourcing my ~/.zshrc I get this error:
~/....
1
vote
3
answers
2k
views
Convert bash prompt in Terminal to zsh
I had recently updated Terminal to use zsh, after doing so the prompt on new terminal windows now displays: \[\033[1;92m\]\h:\[\033[0m\] \[\033[0;34m\][\W]\[\033[0m\] \[\033[0;31m\]\u$\[\033[0m\] ...
2
votes
2
answers
138
views
How to use `-s` option of `diff` command
I am using the command(diff) on macOS. The document says:
-s --report-identical-files
Causes diff to report files which are the same, which are
otherwise not mentioned.
...
0
votes
1
answer
29
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 ...
0
votes
0
answers
20
views
How to copy terminal output to a file without using mouse [duplicate]
Say I have a bunch of text in the terminal. I can use my mouse/cursor to copy to clipboard but is there a way to copy the last X lines from the terminal to a separate file using a terminal command?
2
votes
2
answers
4k
views
How to edit shell prompt to show time?
I would like to edit my shell prompt to display time. I am currently using zsh, though I would like the customize the shell prompt to show time.
I understand that an echo $PS1 will give me the ...
2
votes
0
answers
45
views
diff -s command says text files are identical when they are not, in zsh on macOS [duplicate]
I've observed unexpected behavior (that seems to be a bug) in diff in recent versions of zsh on macOS, the problem is specifically with the -s directive. diff -s lists difference, but it always adds ...
0
votes
1
answer
71
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 ...
1
vote
1
answer
58
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 ...
1
vote
2
answers
92
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\...
0
votes
1
answer
28
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 ...
66
votes
7
answers
53k
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 ...
176
votes
1
answer
76k
views
When is double-quoting necessary?
The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of $...
1
vote
1
answer
34
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 ...
28
votes
7
answers
22k
views
How to remove the last command (or current command for bonus) from zsh history
Sure there's a super simple smart way to do this, but since history in zshell seems to be aliased to fc, there's no way to use the tricks mentioned in How to remove a single line from history?.
Any ...
2
votes
1
answer
94
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 ...
8
votes
1
answer
4k
views
bash like autocompletion for ssh command in zsh shell with /etc/hosts file?
zsh is great so far.
I am using zsh-completions but still I am unable to get autocompletion for ssh commands like in bash as shown in below screenshot:
How to get hostnames from /etc/hosts for ssh | ...
0
votes
0
answers
23
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
28
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 ...
3
votes
1
answer
454
views
Key binding to swap shell foreground/background jobs
In spite of heavy tmux use and switching between panes, I still frequently find myself using shell job control. When something needs poking I'll background the tool I'm using with Ctrl+Z, poke the ...
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 ...
136
votes
4
answers
95k
views
Unlimited history in zsh
In zsh, I want to have unlimited history. I set HISTSIZE=, which works in bash. Now I import an old history
mv old_history .history
which is pretty big
wc -l .history
43562 .history
If I now close ...
1
vote
1
answer
53
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 ?
3
votes
2
answers
152
views
Disabling the secondary prompt in zsh
When you don't properly complete a quote or a complex command in zsh before pressing Enter, you're prompted to complete it with the secondary prompt defined by PS2, e.g. >.
Is there any way to ...
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. ...
117
votes
14
answers
131k
views
How can I search history with text already entered at the prompt in zsh?
In zsh, I know that I can search history with Ctrl+r. However, oftentimes I start to type a command directly at the prompt, but then realize I should be searching history. When I hit Ctrl+r, it brings ...
5
votes
1
answer
4k
views
Make zsh use readline instead of zle?
Is there a way to make zsh use readline reading /etc/inputrc and ~/.inputrc instead of zle module?
I keep my command-line key bindings in inputrc to be applied globally to all other "shells" who use ...
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
...
2
votes
1
answer
2k
views
Python virtualenvwrapper and ZSH prompt
I am using archlinux with zsh and python
simha@gauranga ~ % echo $SHELL
/usr/bin/zsh
simha@gauranga ~ % python3 --version
Python 3.5.1
my .zshrc is
export WORKON_HOME=~/.virtualenvs
source /usr/...
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
33
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>..." ...
0
votes
1
answer
67
views
Modify tmux run-shell PATH
I am creating a few scripts that I'm saving at $HOME/.local/bin; path which is added to the PATH in $HOME/.zshrc. If I execute them through the terminal, all is good. However, when I do tmux run-shell ...
30
votes
3
answers
40k
views
String comparison in single brackets in zsh [duplicate]
Bash code to print all folders:
for f in ~/*;
do
if [ $f == '/home/sk/.' -o $f == '/home/sk/..' ]; then
true
else
echo "$f"
fi
done
It works on bash. When i ran the code on z shell,...
8
votes
3
answers
2k
views
Equivalent of PSReadLine for bash
For my Windows Terminal using Powershell I have the plugin PSReadline which gives me some pretty handy features. For instance a navigatable list view of my history when I start typing. So if I type cd ...
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 ...
0
votes
2
answers
127
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 ...
1
vote
0
answers
21
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
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
vote
1
answer
37
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 ...
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 ...
4
votes
3
answers
9k
views
How to clear tmux and zsh history with one keypress?
How to clear both tmux history (tmux clear-history) and zsh (zle clear-screen) with one key combination?
A common way of clearing screen is ^L, and I tried adding the following to .tmux.conf:
bind -...
0
votes
0
answers
56
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
3
answers
651
views
executable wrapper, run original executable from tail of PATH
There's an executable /usr/bin/foo which I and other scripts use, but it misbehaves a bit so I made a Bash wrapper of the same filename in /usr/local/bin/foo where I fixed its misbehaviour. My PATH is ...
0
votes
2
answers
2k
views
I cannot set env variable on zsh
I am using Kali linux:
lsb_release -a
"
Distributor ID: Kali
Description: Kali GNU/Linux Rolling
Release: 2021.2
Codename: kali-rolling
"
i set env variable
export DB_USER=...
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
87
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 ...
0
votes
3
answers
2k
views
Assign $pwd to $PATH variable conditionally
I want to add my current working directory with its project-specific bin directories to my $PATH when the directories are present.
So I added these lines to my .zshrc:
[ -d "$(pwd)/vendor/bin" ] &...