Zsh is a shell with many advanced command-line and scripting features.
1
vote
1answer
13 views
How can I use bindkey to run a script?
In the Z shell, how can I use bindkey to bind a key sequence to a script?
3
votes
2answers
54 views
cd to directory of a symbolically linked file
Before I write a script, anyone know an easy way to do the following:
$ pwd
/foo/bar
$ ls -l
lrwxr-xr-x 1 username admin 48 Apr 17 2012 foo.sh -> /bar/foo.sh
$ cd /bar
$ ls
foo.sh
i.e., in ...
5
votes
1answer
44 views
Change zsh completion to put completions above the prompt
I'm a long-time tcsh user that finally decided to try out zsh. I've been toying around with completion, but one thing I don't like is that when I hit tab for a completion that might have a lot of ...
2
votes
4answers
52 views
5
votes
2answers
57 views
Disk usage summary per user
Is there a way to get the disk usage per user under a given path? du doesn't seem to have an option to aggregate disk usage per user, and df only seems to report how much disk is left on the drive.
...
2
votes
2answers
47 views
Unable to concatenate files with find ./subdir/* -print0 | sort | xargs -0 cat > merge.txt
I am trying to concatenate thousands of files that result from processing the pieces output by split with
find ./subdir/* -print0 | sort | xargs -0 cat > full_merge.txt
The files under subdir ...
8
votes
2answers
419 views
How do I stop bash from syntax checking sourced files?
I have the following code in a file that is sourced by both zsh and bash.
if test $SHELLNAME = zsh ; then
lss() { l -l ${1:-.}/*(s,S,t); }
laf() { l ${1:-.}/.*(.); }
lad() { l -d ...
3
votes
3answers
83 views
Persistent shell arguments
I often find myself running a series of commands on a single set of arguments.
For example:
$ nmap -Pn -sS 192.168.1.5
$ ssh 192.168.1.5
$ curl 192.168.1.5
$ wget -r 192.168.1.5
This can be sped ...
3
votes
2answers
59 views
Passing quotes and full strings to bash -c or zsh -c
When I am in Perl and I call system(some_command), this invokes some_command on /bin/sh. I would like it instead to run some_command in another shell such as bash or zsh.
One way of running ...
1
vote
0answers
44 views
Zsh: quickly bookmark commands
I just had an idea, I'm sure it must exist though I could not find anything on the web.
This topic gets close to my idea but not enough:
How to quickly store and access often used commands?
I'd like ...
4
votes
2answers
53 views
Passing glob expressions to functions/scripts
The following script is supposed to concatenate multiple csv files in a path specified in the first argument into a single csv file specified in the second argument
#!/bin/zsh
set -x
set -v
...
1
vote
0answers
34 views
Getting “zsh: command not found: time” when running `time` in subshell
I installed ZSH (and Oh-My-ZSH) on a Ubuntu 12.10 64 bit machine a few days ago. I just tried to do:
time (time ls)
and got this error:
zsh: command not found: time
( time ls; ) 0.00s user 0.00s ...
3
votes
3answers
75 views
Portable way to get script's absolute path?
What is a portable way for a (zsh) script to determine its absolute path?
On Linux I use something like
mypath=$(readlink -f $0)
...but this is not portable. (E.g., readlink on darwin does not ...
0
votes
1answer
30 views
Weird behavior when sourcing .zshrc
I'm using zsh 5.0.2 (x86_64-apple-darwin12.3.0) on the latest MacOSX. If it makes any difference, I have also enabled oh-my-zsh.
The shell seems to be missing the .zshrc file when I want to source ...
3
votes
1answer
35 views
Ignore files for zsh's completion for SVN
I managed to configure zsh such that it does not suggest LaTeX temporary files when I use autocompletion for emacs by adding this line to my ~/.zshrc:
zstyle ':completion:*:*:emacs:*:*files' ...
0
votes
1answer
49 views
Issues using sublime text to edit command line in VI mode
I am using the following to edit the current command line in Sublime Text 2 (using a working subl alias)
.zshrc
set -o vi
EDITOR='subl'; export EDITOR
bindkey -M vicmd v edit-command-line
...
2
votes
0answers
54 views
zsh: Echoing every statement?
I have an odd problem with zsh when I switch between shells in a particular way:
Option 1 (works well):
I start a zsh shell. I switch to tcsh with /bin/tcsh, and I switch back to zsh with /bin/zsh
...
1
vote
0answers
38 views
Is there a postexec/predisplay hook for ZSH?
I know zsh has a preexec hook that fires before the command is executed, but is there one that fires after the command has been initiated but before the output is displayed to the screen? I ask ...
2
votes
2answers
195 views
/usr/bin/env: zsh -: No such file or directory
I get the error
/usr/bin/env: zsh -: No such file or directory
...when I run an executable zsh script that starts with the following shebang line:
#!/usr/bin/env zsh -
Also, FWIW, replacing - ...
5
votes
4answers
202 views
Hybrid code in shell scripts. Sharing variables
This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
4
votes
2answers
109 views
Wrap command in the prompt
Is it possible to insert a separator after the command in a prompt? This is an example:
~/Desktop: ls -al
-------------------------------------
total 80
drwx------+ 6 eddie staff 204B Apr 29 ...
4
votes
3answers
99 views
How to save current command on zsh?
I am typing a command, I remember I have to check something, if I press Ctrl+U the command disappears and I can type something else, but then the command I was typing is not in the history.
Is there ...
2
votes
1answer
41 views
What does %\/ do (zsh prompt expansion)?
What does the sequence %\/ do in zsh prompt expansion? man zshmisc doesn't contain the string %\, which is where the rest of the prompt-specific expansions are.
The sequence can be seen in Holmans ...
3
votes
4answers
74 views
Expansion with numbers in human readable format
So, I want to play some MP3s in a console player that takes file names as inputs. I have the following files, as given by ls -1 * where * get expanded by my shell (zsh):
1 - Main title.mp3
10 - End ...
2
votes
2answers
57 views
Stop Git submodule foreach from opening less for each module
I occasionally need to grep through git submodules for which I use:
git submodule foreach 'git grep x'
However, since switching to zsh I find a less prompt is opened for each submodule, even when ...
5
votes
2answers
46 views
Modifying zsh globbing patterns to use with cp
I'm trying to write a script to copy files recursively from a particular folder except files A.extn, B/*.extn and C/* where B and C are directories and extn is just some generic extension. This is ...
1
vote
2answers
59 views
How can a zsh script test whether it is being sourced?
The accepted answer for a similar question for bash does not seem to work for zsh. In fact, if I copy basically the same code given in that answer, to produce the script
#!/usr/bin/zsh -
# test.sh
...
2
votes
1answer
40 views
zsh - check arguments of a command before executing it
Question: Is there an easy way how I can teach zsh to check the command line before executing it? I know that I can completely wrap a specific program with an extra script, but this is not what I want ...
-4
votes
1answer
127 views
zsh: Is it worth the switch from bash? Is it the time? [closed]
I have been a bash user for years now. However, I find that zsh is increasingly gaining momentum. I came up with the following questions:
Is zsh really becoming that popular? Will it compete with ...
1
vote
1answer
52 views
How to avoid parsing /etc/* files
When starting my shell with e.g. exec zsh from the command line, how can I have it not parse any /etc/ files?
I read in the zsh guide that when a user starts a zsh shell, it processes the following ...
1
vote
2answers
34 views
Logging all input and output in zsh on demand
Is there any way to activate/deactivate the logging of all input and output on a zsh session?
I am using oh-my-zsh with a customized prompt with colors, etc. and I would like to preserve all of these ...
1
vote
1answer
40 views
Directory stack order in zsh
I am working on Zsh 5.0.2 (latest stable version), and I noticed that:
dirs -v
and
cd -<TAB>
show a different list of directories (or at least directories in different order).
Moreover, ...
3
votes
2answers
103 views
Preventing zsh from using aliases in CWD (prompt)
I have the following personalized theme activated with oh-my-zsh (latest version of zsh and oh-my-zsh):
local return_code="%(?..%{$fg[red]%}%? %{$reset_color%})"
local ...
1
vote
2answers
89 views
Excluding a directory name in a zsh recursive glob
I'm running zsh on Linux under setopt extended_glob ksh_glob glob_dots. I'm looking for something easy to type on the command line, with no portability requirements. I'm looking at a source code tree, ...
0
votes
2answers
52 views
Command in a variable [duplicate]
I am trying to run a statement where the name of the command is in a variable. For example:
my_command='/path/to/some/command'
$my_command -f foo -b bar -s something else
But the above does not ...
0
votes
0answers
19 views
difference between omz “plugins” and “themes”?
What exactly is the difference, operationally, between plugins and themes in oh-my-zsh? I.e. how would things break (if at all) if a plugin were instead put among the themes, or a theme among the ...
5
votes
1answer
181 views
What should/shouldn't go in .zshenv, .zshrc, .zlogin, .zprofile, .zlogout?
The title says it all. I'm looking for guidelines on what one should and should not include in the various startup files for zsh.
I understand the order of sourcing of these files, and the ...
1
vote
2answers
72 views
zsh is in /usr/bin, but also in /bin, what is the difference?
The /etc/shells says it has zsh installed in /bin/zsh, but also in /usr/bin/zsh.
brgr@envy17:~$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/tmux
...
3
votes
1answer
57 views
Per-directory history in zsh
I am happily using zsh since a while now, and I am quite satisfied with my history settings, which are:
# Write to history immediately
setopt inc_append_history
# History shared among terminals
...
2
votes
1answer
69 views
Why is `kill -s INT <zsh PID>` behaving differently from `Ctrl-C`?
Starting with:
% donothing () { echo $$; sleep 1000000 }
% donothing
47139
If at this point I hit Ctrl-C at the same terminal that is controlling the shell, then the function donothing does indeed ...
1
vote
0answers
71 views
preventing the screen from being cleared when exiting an ssh session
I have rdist set up to push out some of my dot files to all the remote machines that I need to ssh into. I also have zsh as my default shell on all of those machines.
When I ssh into a machine and ...
1
vote
1answer
47 views
Get zsh to report directory to emacs
From the emacs manual
Unlike Shell mode, Term mode does not track the current directory by examining your input. But some shells can tell Term what the current directory is. This is done ...
2
votes
1answer
104 views
dircolors on zsh: Unrecognized keywords: MULTIHARDLINK, RESET & CAPABILITY
I am trying to get the solarized color theme to work in my terminal. I read the instructions here but I get the following dircolors error:
dircolors: `/home/avazquez/.dircolors_zsh':90: unrecognized ...
2
votes
3answers
99 views
Treatment of backslashes across shells
How do echo and printf treat backslashes in zsh, bash and other shells?
Under zsh I get the following behavior:
$ echo "foo\bar\baz"
foaaz
$ echo "foo\\bar\\baz"
foaaz
$ echo 'foo\bar\baz'
foaaz
$ ...
5
votes
4answers
258 views
Is it recommended to use zsh instead of bash scripts?
Can I assume that enough people have zsh installed to run scripts with a
#!/usr/bin/env zsh
as shebang?
Or will this make my scripts un-runnable on too many systems?
Clarification: I’m interested ...
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 ...
3
votes
3answers
109 views
Delete all but largest file of specific type
I am trying to organise the album art in my music collection so that only one image is assigned to each folder.
My directory structure currently looks like:
/path/to/music/Album Name/
...
2
votes
1answer
69 views
How to print apparently hidden environment variables?
Environment variables can be shown with env; but, some are not shown. For example...
echo $EUID might produce as result of 1000 yet
env | grep EUID produces no result.
What is this type of variable? ...
5
votes
1answer
89 views
ZSH: What's the difference between `.` and `source`?
I used to think that the built-ins . and source are equivalent. This question agrees with me when it comes to bash. However I encountered the following using zsh:
desktop➜ ~/pst . env
...
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 ...
