Zsh is a shell with many advanced command-line and scripting features.
6
votes
4answers
2k 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.
...
0
votes
2answers
300 views
ls outputs multiple columns even if piped to grep with grml's zsh config
I just decided to give zsh a go against Bash and came across some unhandy behaviour about which I couldn't find anything on the net:
If you do a ls | grep foo in Bash, the ls only contains one file ...
1
vote
1answer
63 views
List all the matched files starting from an index
In zsh, there is the [m,n] glob qualifier which works as follows:
[beg[,end]]
specifies which of the matched filenames should be included in the
returned list. The syntax is the same as for ...
2
votes
0answers
182 views
Physical Terminal (DEC VT220) issues with ZSH
I recently purchased a VT220 and all the hardware necessary to hook it to my macbook pro. After several hours of fiddling I got it working with a shell - my only problem is my shell of choice, ZSH, ...
3
votes
3answers
243 views
Converting a history to a script?
Often times I've typed in a bunch of commands when I realize that I am going to keep typing them in and that I would really like a script.
Now I understand that no matter how I save my history, I am ...
6
votes
1answer
552 views
Displaying stdout of a background process in specific location of the terminal
I have a command that I run every time a new terminal is opened or a new login is made.
This program produces output (colored) which should be positioned before the command prompt. It can take a few ...
6
votes
2answers
360 views
zsh tab completion on empty line
I'd like a tcsh'ism that I haven't been able to find: On a blank line with no content, I want to press the tab key and see the equivalent of an ls. That is to say I want
$ <tab>
to do ...
0
votes
2answers
159 views
pwd not being set correctly in zsh prompt
If I type this in my PROMPT in my .zshrc file:
PROMPT="`pwd` >"
I expect that it will print the current working directory. However, pwd always prints /Users/kevin. Why doesn't it show my current ...
2
votes
1answer
508 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";
3
votes
1answer
209 views
ZSH takes two tabs to complete filenames
I love Zsh's tab completions, but it's frustrating when there is only one possible option and I have to tab twice to tab complete the filename.
For example, if this is a list of files in a directory:
...
1
vote
1answer
105 views
Files with no .sh extension not considered for autocompletion in zsh
I have noticed that unless I add an .sh extension to my shell scripts, Zsh does not suggest them for autocompletion for execution despite having them in my PATH. I have the same problem if I cd into ...
3
votes
1answer
366 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? ...
1
vote
1answer
825 views
Terminal does not source .zshrc with custom colors for ls and cd command
I customized the directory and file colors for ls and cd + TAB. Here is my configuration.
My configuration
My system environment.
Ubuntu 10.10
zsh 4.3.10 (x86_64-unknown-linux-gnu)
oh-my-zsh // ...
8
votes
2answers
2k views
In zsh how can I list all the environment variables?
I want to get a list of all environment variables (shell variables? exported variables?) and their values at a given time, in zsh.
What is the proper way to do this?
6
votes
3answers
925 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 ...
5
votes
1answer
200 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 ...
5
votes
1answer
80 views
What is Bash's string{ending1,ending2} construct called and what is the equivalent in zsh?
I've been trying to switch to zsh. Something I've missed so far is this:
#!/bin/bash
mv /very/long/path/to/file1.conf{,.old}
#bash expandes that to:
mv /very/long/path/to/file1.conf ...
1
vote
2answers
598 views
ssh-agent error on ubuntu server 10.04 LTS
I have an Ubuntu Server 10.04 installation on Linode. I am trying to use ssh-agent to stop typing my passphrase everytime I need to push some changes to GitHub. I am using the script provided by ...
3
votes
1answer
137 views
Pipe zsh auto completion list to file or less
zsh: do you wish to see all 923 possibilities (462 lines)?
Yes please, but in a file or less.
7
votes
3answers
346 views
What is the main problem someone migrating from bash to zsh should face?
A few times I have had problems in bash that other using zsh didn't have and they were gloating about how smart they are.
Also I have seen zsh users among people that I admire, and I have tried a ...
2
votes
1answer
1k views
How to run a specified codeblock with getopts when no options or arguments are supplied?
So I am writing a script that mixes options with arguments with options that don't. From research I have found that getopts is the best way to do this, and so far it has been simple to figure out and ...
10
votes
3answers
1k views
How to properly collect an array of lines in zsh
I thought the following would group the output of my_command in an array of lines:
IFS='\n' array_of_lines=$(my_command);
so that $array_of_lines[1] would refer to the first line in the output of ...
2
votes
1answer
267 views
vi mode doesn't display correctly on new term
This is a continuation of my previous questions. I currently have the following in ~/.zsh.d/functions.sh
function zle-line-init zle-keymap-select {
psvar[1]="${${KEYMAP/vicmd/}/(main|viins)/-- ...
3
votes
2answers
205 views
zsh autocomplete directory
I'm new to zsh and one thing that I do quite often is execute shell scripts that are in a directory of mine called Scripts. I'm not always inside of the Scripts directory, however... I may be in ...
6
votes
2answers
914 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 ...
3
votes
2answers
1k views
Stop ZSH from trying to correct command
$ knife cookbook download recipe
zsh: correct 'cookbook' to 'cookbooks' [nyae]?
How can I get zsh to stop trying to correct cookbook to cookbooks??
cookbooks is a directory where I run the command ...
1
vote
1answer
735 views
Errors after installing oh-my-zsh
I just tried to install oh-my-zsh. I get the following error when I try to run rvm:
zsh: command not found: rvm
I also get the following error when I try to open a new tab:
...
1
vote
1answer
137 views
How to access user's fpath as opposed to system's fpath with a script?
test.zsh:
#!/usr/bin/env zsh
for f in ${fpath}; do
echo ${f}
done
outputs:
...
6
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.
3
votes
1answer
237 views
Zsh autocomplete ls command with directories only
Suppose I have following files and directories:
% ls
bui00293 buiawer builds/ buiowpe/
I want to list the content of ...
3
votes
2answers
306 views
Renaming files in lexicographical order with a numerical pattern that increases sequentially with fixed padding
I have files such as
a
bb
ccc
abc
emrls
I would like to rename them so that, after sorting them (for example, lexicographically), each file gets the following name:
00001
00002
00003
etc
where ...
3
votes
2answers
90 views
Executables show with character * next to their name in output of ls
I noticed that when I list my executables with ls on my Z shell they show up with a character * next to their name (e.g. see the file in red .test_color_scheme)
What is causing ...
1
vote
2answers
145 views
Generate a list of files from a file containing a series of globbing patterns
I am looking for a way to build a list of files by parsing a file that contains a sequence of zsh globbing patterns.
The final goal is to pass this list of files to hg add in mercurial. For those ...
6
votes
2answers
555 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 ...
1
vote
1answer
451 views
FPATH in zsh: functions and site-functions
I noticed I have the following line near the beginning of my .zshrc file:
export FPATH=/usr/share/zsh/site-functions:/usr/share/zsh/4.2.6/functions:$FPATH
I can't remember if I typed this myself ...
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
...
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 ...
5
votes
2answers
752 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 ...
4
votes
2answers
72 views
If ^a^b replaces “a” once in the last command, what do I use to replace all occurrences of “a”?
In bash, if I run this command:
echo aaaaaaa
I get aaaaaaa (duh)
But then if I type in
^a^b
I end up with baaaaaa
What would I type to end up with bbbbbbb ?
7
votes
3answers
2k views
ESC key causes a small delay in terminal due to its Alt+ behavior
My terminal setup is gnome-terminal + tmux + zsh with vi bindings.
In applications like vim or even in the zsh's command line vi editing mode, I need to frequently hit the ESC key but there is a ...
3
votes
3answers
369 views
What does : ${param:=value} mean?
I read the following in A User's Guide to the Z-Shell:
A synonym for ‘true’ is ‘:’; it’s often used in this form to give
arguments which have side effects but which shouldn’t be used —
...
7
votes
1answer
2k views
256 colour prompt in Zsh
How can I set my prompt to be colourized in 256 colours? I am looking for an equivalent to the bash prompt:
local DEFAULT="\[\033[0;39m\]"
local ROOK="\[\033[38;5;24m\]"
...
6
votes
2answers
403 views
Difference between alias in zsh and alias in bash
I have searched around but could not find anything conclusive. Is there a difference between the alias command in zsh and the alias command in bash? If not, does it mean I can share a set of aliases ...
1
vote
1answer
103 views
Delete zsh auto completion suggestion
When I use tab-completion in zsh, the shell suggests me files and I discover that I'm in the wrong directory. How can I just delete the suggestion instead of backspace'ing it?
3
votes
2answers
481 views
Multidigit ranges of files in lexicographical order in zsh
I would like to specify a range of files (in lexicographical order) with two integers (e.g. 2 to 57) in zsh by globbing.
For example: "pick the files 2 to 57 in lexicographical order under the path ...
1
vote
1answer
158 views
Globbing with brackets and variables in zsh
I wrote the following snippet to delete several subdirectories selectively from a common ancestor. It doesn't work, but I can't tell why.
for x in *;
do rm -r "$x/foo/bar/{a*,b,c,d,g*}";
done
I ...
3
votes
2answers
247 views
How to cd into the named directory if command not found?
When I type something which is neither a zsh builtin and no such executable is found from $PATH, zsh just reports an error. Instead, I would like zsh to check if a named directory exists with that ...
0
votes
0answers
178 views
python error using an executable with Z shell
I'm getting this error from the Unix Z shell (I'm on Mac):
python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: No such file or ...
22
votes
1answer
623 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, ...
0
votes
2answers
647 views
SSH “command not found” for Zsh
Im using Zsh on the client and server. When I use ssh to run a command on the remote server it can not find the binary:
ssh gt "cd /home/****/app/staging && bundle exec rake db:migrate ...
