Zsh is a shell with many advanced command-line and scripting features.

learn more… | top users | synonyms (1)

3
votes
1answer
49 views

How do you use variables with values containing spaces in a Z-shell (zsh) script command?

I have the following Z-shell script: compiler=clang++ standard=-std=c++11 warnings="-Wall -Wextra -Wpedantic" ${compiler} ${warnings} ${standard} -o ${1} ${1}.cpp This does not work as the ...
0
votes
1answer
17 views

Run .zshrc when passing command via -c

I have a script that runs a command via zsh -c. However, when zsh runs, it doesn't appear to load ~/.zshrc. I understand a login shell flag exists, but even zsh -lc <command> doesn't seem to ...
3
votes
4answers
94 views

Efficient data extraction from multiple files to a single CSV file

I have a large collection of XML files with the same exact structure: $ cat file_<ID>.xml ... ... ... <double>1.2342</double> <double>2.3456</double> ...
0
votes
1answer
17 views

Determine the tmux session a shell session belongs to?

tmux provides a number of commands in the shell such as rename-session which operate on the session that the invoking shell belongs to. It also provides commands like list-clients which list out the ...
0
votes
2answers
27 views

“Quit and restart” control code?

I find myself frequently (after making some change to source) "Ctrl+C;↑ ing" to restart the program with changes. Is there a way to do this more quickly, without wrapping the program in a loop ...
0
votes
1answer
9 views

Bind tmux prefix to section symbol §

I usually use the backtick key as my prefix, but this keyboard has the section/stanza symbol § where the backtick usually (at least, for me in the UK) is. If I bind to this key, quoted or unquoted, ...
3
votes
1answer
35 views

How can I ignore / remove / exclude autocompletions in zsh?

I usually use rs+[tab] to get rsync but it's showing three options (on a new system): ➜ $ rs rsh rsync rsyslogd I seldom use rsh or rsyslogd - how can I prevent these from appearing ...
4
votes
1answer
93 views

What is this HOME command?

I'm able to run a command named "HOME" which appears to be equivalent to cd && echo "~". But I can't figure out where it's defined: $ pwd /tmp $ which HOME HOME not found $ type HOME HOME not ...
0
votes
1answer
28 views

Can I conditionally turn certain oh-my-zsh plugins off?

This is more of a long shot, but here we go: I use oh-my-zsh with the vcs-plugins git and svn on. I now started on a project where it would be most convenient to use sshfs. The problem that now comes ...
-1
votes
1answer
37 views

What does `zstyle` do?

zstyle seems like it's just a central place to store and retrieve data, like an alternative to export. Is that true, or is there more to it?
0
votes
1answer
26 views

Running a command on different shell

While reading the answers of question Can bash write to its own input stream?, I found following command runs on zsh but not on bash : print -z echo mnciitbhu 1 . Is -z is an extension to print ...
1
vote
1answer
46 views

What is the difference between `autoload` and `autoload -U` in Zsh?

What is the difference between autoload -U and plain autoload? For instance, here it is recommended to run: autoload -U run-help autoload run-help-git autoload run-help-svn autoload run-help-svk ...
1
vote
1answer
39 views

Configure tmux to use zsh

Right now I have my iTerm session configured to use zsh (/usr/local/bin/zsh), but I'm trying to configure tmux to use zsh as well, instead of /bin/bash/, which it's currently defaulting to. So far ...
1
vote
1answer
27 views

How to add a dir to fpath

I'm using zsh and prezto. I've adding the following line at the end of my .zshrc fpath=(/usr/local/share/zsh/site-functions $fpath) But unfortunately, the functions defined in this folder seems ...
2
votes
1answer
44 views

Source .bashrc in zsh without printing any output

In the past, I've used bash consistently, because it's everywhere. But recently I started to try zsh. I don't want to give up updating my .bashrc fil which is rsync'ed to all my servers . So, in my ...
6
votes
1answer
40 views

zsh I/O redirection: redirecting and then piping; what is going on?

Can somebody explain what is going on in this command: echo foo >&2 | grep foo Zsh (5.0.2) prints foo twice. One seemingly to stdout and one to stderr, since running these commands: { echo ...
1
vote
1answer
47 views

zsh: Disable “file exists:” warning with redirection

How can I override the file exists: warning from zsh? > echo > newfile.txt > echo > newfile.txt zsh: file exists: newfile.txt In these cases I prefer my shell to not complain and ...
2
votes
2answers
37 views

How do I find the actual binary/script using 'which' in zsh? [duplicate]

In zsh, when I enter which git it shows: git: aliased to noglob git How do I find out which git binary it actually invokes? (eg: /usr/bin/git vs ~/bin/git). Basically I want to bypass the aliases ...
1
vote
1answer
37 views

Completions stopped working after upgrading zsh

Previously I have been using this handy script with oh-my-zsh to set the tab color whenever I ssh into a machine: # iTerm2 window/tab color commands # ...
1
vote
1answer
40 views

How to edit shell prompt to show time?

I would like to edit my shell prompt to display time. Am currently using zsh, though I would like the customize the shell prompt to show time. I understand an echo $PS1 will give me the environment ...
3
votes
3answers
117 views

How to set HOSTNAME in zsh?

In bash, which sets $HOSTNAME for you, I was able to calculate the total length of prompt line simply by using something like: PS1_length=$((${#USER}+${#HOSTNAME}+${#PWDNAME}+12+${#PS1_GIT})) It was ...
2
votes
2answers
115 views

Zsh: export: not valid in this context

When running this script, I run into an error on this line (relevant snippet below): ... _NEW_PATH=$("$_THIS_DIR/conda" ..activate "$@") if (( $? == 0 )); then export PATH=$_NEW_PATH # If ...
0
votes
1answer
25 views

Should I move my custom commands from the end of ~/.profile to the end of ~/.zprofile when I install zsh and oh-my-zsh?

I am a new user of zsh and oh-my-zsh. Before I installed zsh and oh-my-zsh I configured my ~/.profile to start some programs automatically. For example, my ~/.profile would start guake after a 4 ...
1
vote
3answers
112 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 ...
2
votes
3answers
38 views

reuse the last command output at the given index/line-num

ls displays: entry1 entry2 entry3 How can I reuse the above output (not all of the entries but the entry at a given line, say n) in the next shell command? Something like: vi $(!!)@3 Must ...
2
votes
3answers
45 views

Local `set -e` for functions

Is there such a feature or can it be emulated reasonably easily? I want the same behavior except it should return where set -e would have caused a call to exit.
2
votes
1answer
77 views

Automatically colorize the output of tree

In plain zsh, tree is set similar to --color=auto by default. However, when I use Oh-My-Zsh, tree doesn't show colors. Since tree does not have a --color=auto option, how can I override the setting ...
1
vote
1answer
28 views

Setting backspace=2 in zsh with vi bindings

I just set my zsh to vi mode as I feel the word/WORD (w/b W/B) skip keybindings will help me work faster than plain ^a ^e in emacs binding mode. However, I'd like to set backspace=2 or set ...
2
votes
1answer
21 views

Overridable functions in Zsh

Consider the following two functions: function slow_git_prompt_info() { if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then ref=$(command git symbolic-ref ...
0
votes
1answer
29 views

Read a line with default input in zsh

This function can be used to help user input a modification of some text. function change { bash -c "read -ei \"$1\" temp && echo \$temp" } What is idiomatic zsh way to do something ...
5
votes
2answers
80 views

Elegant way to prevent command substitution from removing trailing newline

I'm customizing my zsh PROMPT and calling a function that may or may not echo a string based on the state of an environment variable: function my_info { [[ -n "$ENV_VAR"]] && echo "Some ...
2
votes
2answers
56 views

Split shell horizontally to show ls -al and pwd

I use zsh as my default shell on OSX. I would like for my shell to always have a horizontal split showing pwd and ls of the current directory I'm in. How do I go about it ?
15
votes
1answer
643 views

What's the magic that allows me to tab-complete remote files as I type an scp command?

Presumably this is a feature provided by some plugin I have enabled in my oh-my-zsh setup (I have been using zsh for many years now). I noticed ever since I added my public key to the server (now I ...
0
votes
1answer
50 views

Cannot get interface information using read

The following link has a script to get system information: z3bra' blog Specifically, network() { read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'` if iwconfig ...
2
votes
2answers
69 views

Reliably identifying the path to the directory containing the running script

There are plenty of answers in SO to address this question: Can a Bash script tell what directory it's stored in? Unix shell script to find out which directory the script resides? And there are a ...
0
votes
1answer
30 views

A generic cron wrapper that records all output

I am hoping to write a cron wrapper that records all output in a folder $CRON_LOG_DIR. It would be used as, e.g., follows: * * * * * $CRON_WRAPPER "<job name>" "command" which would record ...
0
votes
1answer
51 views

How to solve nsf-common related error when install zsh in ubuntu?

Everytime I install some kind of package, at the last phase, apt-get install could return a common-nfs related error. Why the installation can't be done without this error? detailed pastebin here ...
0
votes
1answer
31 views

zsh alias with linefeeds, commas and quotes

In my zshrc I have an alias like this: alias sl='screen -list' It fits my need (seeing what screens I have running), but the output is rather ugly: [pts/7]~% sl There are screens on: ...
2
votes
1answer
40 views

Clustering identical files ignoring spaces & linebreaks

Consider a folder with many XML files (10K small text files). Some XML files are identical, some are different. I would like to find out what files are identical (ignoring whitespaces, tabs and ...
2
votes
2answers
34 views

Replace screen process from within screen

I have configured my shell to exec screen when it starts, unless it's already running within a screen session. So in a TTY, the process tree will look like something like this: ...
0
votes
2answers
53 views

Best way to kill processes in a list

I've got this zsh script. Is there a more a graceful way to do this? export PROCESSES_TO_QUIT='puma rake sidekiq spring rails ruby-debug phantomjs zeus passenger guard resque "node server.js"' pgr() ...
3
votes
1answer
87 views

echo result from subshell in zsh

In zsh, the following 2 commands results differently: a=$(</etc/hosts) && echo $a echo $(</etc/hosts) The 1st prints contents line by line, while the 2nd prints contents as a whole in ...
4
votes
2answers
75 views

How to kill a bunch of jobs based on ps output?

Here is output from ps: $ ps aux | grep blob ubuntu 4286 0.0 0.1 34748 9592 ? S Jan14 0:00 /usr/bin/python /usr/local/bin/pynt start_blob_reader ubuntu 4287 0.0 0.1 34748 ...
2
votes
2answers
66 views

Does zsh expansion work differently in non-interactive scripts?

I'm currently working on a pretty simple zsh script. What I often do is something like: mv */*.{a,b} . When I run that within a zsh script, it seems to expand differently and fail while it works in ...
0
votes
3answers
72 views

read command in zsh throws error

In zsh, running the command read -p 'erasing all directories (y/n) ?' ans, throws the error, read: -p: no coprocess But in bash, it prints a prompt. How do I do this in zsh?
1
vote
1answer
86 views

zpool states that zones are in SUSPENDED mode

Zones are in suspend mode how can I bring them up online? Operating system: SunOS xxxxxxbase02 5.11 11.2 sun4v sparc sun4v While listing the pool in global zone I can see four hosts are in suspend ...
2
votes
1answer
28 views

Vim and unified diffs

In my daily work, I only deal with unified diffs, so I would like to define the alias alias diff='diff -puN' in my .zshrc. This alias is not respected when I use the shell from the vim command ...
18
votes
1answer
340 views

Why does exporting vim as EDITOR in zsh disable keyboard shortcuts?

My .zshrc looks like this: export EDITOR="/usr/bin/vim" Now when I open a terminal and enter a keyboard shortcut like ctrla to go to the beginning of the line, it doesn't work. Instead, the string ...
2
votes
1answer
57 views

zsh case-insensitive mid-word completion

I have the following in my .zshrc for case-insensitive tab completion. I encountered a situation where the tab completion fails, and I can't figure out why. autoload -U compinit && compinit ...
4
votes
3answers
574 views

Echo command with AND operator doesn't exit

echo hai && echo bye prints hai bye while echo hai && echo $? prints hai 0 When the first echo command's return value is 0, how does the echo statement after AND operator ...