Zsh is a shell with many advanced command-line and scripting features.
23
votes
3answers
2k views
How to use `which` on an aliased command?
Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance,
alias vim='vim -X'
alias grep='grep -E'
alias ls='ls -G'
The problem is ...
71
votes
1answer
11k views
Difference between nohup, disown and &
What is the difference between
$ nohup foo
and
$ foo &
and
$ foo &
$ disown
16
votes
2answers
1k views
Display stuff below the prompt at a shell prompt?
Lets's say my prompt looks like this (the _ represents my cursor)
~ % _
Is there any way I could make it look like this
~ % _
[some status]
The question was originally about zsh, but now has ...
6
votes
1answer
251 views
What is the best way to detect (from a script) whether software is installed?
I've been frustrated before with differences in output from the which command across different platforms (Linux vs. Solaris vx. OS X), with different shells possibly playing into the matter as well. ...
2
votes
1answer
626 views
zsh equivalent of bash show-all-if-ambiguous?
In bash, if you hit tab when there are multiple possible completions you get a list of matches that keeps reprinting if you repeatedly press tab. In tcsh, setting autocomplete to enhanced also ...
30
votes
4answers
2k views
What features are in zsh and missing from bash, or vice versa?
As a Linux user, I've always just used bash because it was the default on every distro I used. People using other Unix systems such as BSD seem to use other shells far more frequently. In the ...
7
votes
2answers
1k views
Force title on GNU screen
By default, the title of a screen session is the name of the last command entered, which is fine for me, but in some cases I'd like to change it. I know the command Ctrl-A A, but it only changes the ...
6
votes
3answers
980 views
How to delete part of a path in an interactive shell?
Is there a shortcut in bash and zsh to delete one component of a path? For example, if I type ls ~/local/color/, and the cursor is at the end of line, is there a shortcut to delete the color/ at the ...
7
votes
3answers
3k views
How do I reverse a for loop?
How do I properly do a for loop in reverse order?
for f in /var/logs/foo*.log; do
bar "$f"
done
I need a solution that doesn't break for funky characters in the file names.
2
votes
1answer
426 views
Wrapping a command that includes single and double quotes for another command
I recently learned about watch, but am having trouble making it work with relatively sophisticated commands.
For example, I would like to ask watch to run the following command on zsh every three ...
26
votes
4answers
2k views
Is there any way to keep a command from being added to your history?
Is there any way to keep a command from being added to your history? I have a command that I want to keep out of my history file, and I really don't care to have it there when I search the history ...
10
votes
3answers
3k views
make my zsh prompt show mode in vi mode
I use bindkey -v (for bash-ers set -o vi I think that works in zsh too) or vi(m) mode. but it bugs me that I don't have any visual cue to tell me whether I'm in insert mode or command mode. Does ...
7
votes
2answers
143 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 ...
7
votes
2answers
1k views
Testing LS_COLORS in zsh
A few years ago I found an interesting code snippet that prints each type of file in its corresponding color according to the colors set up in LS_COLORS. Unfortunately, I can't remember the link ...
6
votes
1answer
252 views
Can I have my shell history record how wildcards expanded?
If I run:
$ ls *
foo bar buzz
$ history | tail -1
ls *
You can see that in my shell history it remembers that I ran ls * rather than ls foo bar buzz. Ideally, I'd like to record both in separate ...
2
votes
1answer
218 views
zsh history - full path
Suppose I do the following in zsh
cd ~
cd dir1
cd dir2
cd dir3
evince foo.pdf
zsh writes exactly the same in its history file.
Now my question is whether it is possible to have
cd ~
cd ~/dir1
cd ...
6
votes
2answers
1k views
16 Colors in ZShell
I only seem to be able to call 8 colors in my zshell prompt.
Example:
PROMPT="[%n@%{$fg[magenta]%}%m%{$reset_color%} %.]
%# "
Works fine. However,
...
3
votes
1answer
378 views
How do I filter a glob in zsh
Basically I can use a glob in zsh to a list. Often, it turns out, I would like to filter that list, grep'ishly I'm wondering though, if I need to do that.
Does zsh have a method to filter a list? ...
0
votes
1answer
1k views
Script failing with “command not found: ^M”
When I try to run the following script in zsh, via the command /bin/zsh ~/.set_color_scheme.sh I get the following error:
command not found: ^M
The script has u+x permissions and it used to work on ...
24
votes
5answers
1k views
When do you use brace expansion?
I understand what brace expansion is, but I don't know how best to use it.
When do you use it?
Please teach me some convenient and remarkable examples if you have your own tip.
22
votes
2answers
2k views
rebuild auto-complete index (or whatever it's called)
After installing new software, an already opened terminal with zsh won't know about the new commands, and cannot generate auto-complete for those. Apparently opening a new terminal fix the problem, ...
24
votes
1answer
636 views
Avoiding “BASH-isms” in shell scripts
Does there exist a tool similar to Perl::Critic that will inspect your shell scripts and point out flaws, portability issues, uses of non-standard programs without fallbacks, depreciated program uses, ...
17
votes
1answer
856 views
Using zsh's line editor to wrap around subprocesses
Is it possible to use zsh's built-in line editor (zle) to feed input to a subprocess? That is, I would like to run zlewrap mycommand where zlewrap is a zsh function and mycommand is any program that ...
11
votes
2answers
1k views
zsh wants to correct vim to .vim
I'm using zsh on Gentoo x64, and when I type sudo vim /path/to/file from my home folder, zsh asks:
zsh: correct 'vim' to '.vim' [nyae]?
I want to run vim not my .vim folder. How do I fix this?
...
6
votes
4answers
2k views
How can I detect if the shell is controlled from SSH?
I want to detect from a shell script (more specifically .zshrc) if it is controlled through SSH. I tried the HOST variable but it's always the name of the computer which is running the shell. Can I ...
6
votes
2answers
990 views
List elements with spaces in zsh
I've been studying zsh scripting for all of 2 hours at this point and I've hit a wall. I want to go through a list of files that may have spaces in them. I'm open to completely different approaches ...
5
votes
4answers
521 views
List X random files from a directory
Is there a way to list a set of say, 30 random files from a directory using standard Linux commands? (in zsh)
The top answer described here does not work for me (sort does not recognize the option ...
5
votes
1answer
1k views
ZSH: search history on up and down keys?
Currently, I have the following in my .zshrc:
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
However, this only seems to match the content of my current input before a space ...
7
votes
4answers
265 views
mv * folder (avoiding 'cannot move' error) [duplicate]
Anytime I want to move thousands of files to a new folder, I always encounter the same problem.
> mkdir my_folder
> mv * my_folder
mv: cannot move 'my_folder to a subdirectory of itself ...
5
votes
4answers
2k views
Adding paths to PATH using a multi-line syntax
As far as I understand, the usual way to add a path to the PATH environment variable is by concatenating paths separated by the : character.
For example, if I want to add three paths to it ...
5
votes
2answers
801 views
Pasting from clipboard to vi-enabled zsh or bash shell
I'd like to be able to paste from the system clipboard (or text selection) into my "vi-like" shell prompt using the keyboard. I normally use zsh and sometimes bash. In both cases, I have the shell set ...
5
votes
1answer
718 views
Is it possible to use named colors in Zsh beyond ANSI names?
I know there are ways to use ANSI color names in Zsh (such as red), but Zsh supports 256 colors by number. I'm curious if there's any way to refer to the non-ANSI colors by a name? (Without just ...
3
votes
1answer
96 views
Escaping quotes for scp
I needed to write a that behaves correctly with nasty (spaces, braces, etc..)
filenames.
scp -rv "$1" shiny:/Volumes/Seagate3To/\"$1\"
This function works, but I don't understand why the quotes ...
3
votes
2answers
412 views
The Right Distro for text-based needs
I'm searching for the right Linux Distro. My four current ideas are:
Gentoo
Grml
Arch
Debian
But I'm absoluty open to more alternatives. Now a little bit more about my needs:
I want it to be ...
6
votes
2answers
578 views
What is word splitting? Why is it important in shell programming?
I'm getting confused about the role word splitting plays in zsh. I have not been exposed to this concept when programming in C, Python or MATLAB, and this has triggered my interest of why word ...
5
votes
1answer
209 views
zsh - fully expand binary path on <tab>
In my current zsh behaviour, hitting tab after typing "sudo" just adds a space.
$ sudo ...
What I really want is for the tab to fully expand to the path of the binary it is about to execute when I ...
4
votes
1answer
101 views
How can I create a function in zsh that calls an existing command with the same name?
How can I write a function in zsh that invokes an existing command with the same name as the function itself? For example, I've tried this to illustrate my question:
function ls
{
ls -l $1 $2 $3
...
3
votes
4answers
117 views
Double and triple substitution in bash and zsh
Follow-up to the background part in this question.
In bash I can use {!FOO} for double substitution, in zsh ${(P)FOO}. In both, the old-school (hack-y) eval \$$FOO works.
So, the smartest and most ...
3
votes
4answers
136 views
Round/truncate digit in string in zsh (or with external tool)
I'm trying to do an interface to bc so it can be used intuitively and without the annoyance of getting "stuck" in it. I haven't got around to test it that much, because I got stuck on another detail, ...
3
votes
2answers
429 views
Zsh — more intelligent autocorrection
Is it possible to make Zsh stop trying to correct arguments that are not meant to be files with files from the current directory without turning off correction completely or limiting it to setopt ...
3
votes
1answer
1k views
Changing the default shell without chsh or administrator priviledges
I saw the following snippet in this thread: How to change from csh to bash as default shell
sleep 2
if (-x /usr/local/bin/bash) then
exec /bin/sh -c '. ~/.profile; exec /usr/local/bin/bash'
endif
...
2
votes
2answers
62 views
${!FOO} and zsh
${!FOO} performs a double substitution in bash, meaning it takes the (string) value of FOO and uses it as a variable name.
zsh doesn’t support this feature.
Is there a way to make this work the same ...
2
votes
1answer
120 views
Stop tab completion suggesting 'messagebus'
I've got a directory called build, which I cd into quite a bit.
If there isn't any directory bu* in the current directory, zsh tab completion: cd buTAB suggests messagebus/, which isn't in .. If I ...
2
votes
2answers
189 views
Piping paths with different types of quotes for slash substitution
I would like to use sed to convert a path with backslashes to the same path with forward slashes:
E.g.
I would like to pipe \\path\to\file\ and obtain /path/to/file
None of the following commands ...
2
votes
1answer
565 views
Set variables in ZSH precmd and reference them in the prompt
Is there a way to set variables in the precmd function of zsh and then echo them in the prompt?
Something like
function precmd {
GREETING='Hi Kevin!';
}
PROMPT="$GREETING";
