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

learn more… | top users | synonyms (1)

1
vote
2answers
75 views

Arrays in Zsh. Check if any of the following variables is not defined

Say we have a set of variables that we want to test if they are defined, and set a condition if any of them are not. I am thinking of proceeding with something like the following: #!/usr/bin/env zsh ...
2
votes
2answers
73 views

For input redirection, are there functional differences between bash/zsh <<<“$(<file)” and the traditional <file?

I'm asking only about the usage which would have the similar effect as traditional input redirection from a file. <<<"$(<file)" as far as I can tell is equivalent to <file It ...
2
votes
1answer
144 views

Dynamic zsh autocomplete for custom commands

I'm trying to write completion functions for some custom functions I wrote, but seem to be really struggling with even the most basic ones. An example function is: function eb_instances() { if ...
12
votes
2answers
312 views

How can I make commands appear bold in zsh?

I have set up my bash shell so that any commands I type appear in bold and the commands' output is shown in normal weight: I did this by adding \e[01m at the end of my PS1 variable to turn on bold, ...
2
votes
2answers
649 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?
2
votes
4answers
74 views

Copy files to new directory only if name of file is in an array

I'm not much of a zsh buff but I imagine this should be an easy layup for someone: I can bulk copy files from sourcedir to targetdir with the following: $ find sourcedir -type f -exec cp {} ...
0
votes
1answer
134 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
0answers
114 views

How can I make my Zsh theme (“fade”) look good in urxvt?

I am using Arch Linux and as a newbie I don't have any preference for a terminal emulator yet. Since rxvt-unicode seems to be the most popular one, I thought I'd try that first. I'm configuring it ...
76
votes
2answers
6k views

Have backticks (i.e. `cmd`) in *sh shells been deprecated?

I've seen this comment many times on Unix & Linux as well as on other sites that use the phrasing "backticks have been deprecated", with respect to shells such as Bash & Zsh. Is this ...
3
votes
1answer
31 views

zsh-completion: Completing two parts of an argument, separated by a colon

I'd like to set up zsh completion for a command which has a single argument of the form scheme:parameter. Suppose I have commands which can return all possible schemes, and all possible parameters. ...
4
votes
3answers
1k views

oh-my-zsh completion on home directory names

I recently switched to zsh from bash, and I'm using oh-my-zsh. There's a completion behaviour I don't want: in any directory, the list of autocompletion candidates seems to include the names of all ...
0
votes
1answer
153 views

How to setup Mac OS X Terminal on bash and iTerm2 on zsh

I attempted to setup bash shell by default on Mac OS X (Yosemite) Terminal app and zsh shell by default on iTerm2 app. However, it is either bash shell or zsh shell for both the apps. $ chsh -s ...
5
votes
4answers
1k views

How to append / extend zshell completions?

I am using zsh with oh-my-zsh. Unfortunately, oh-my-zsh does not use file ~/.ssh/config for hostname auto-completion (see Issue #1009, for instance). This could easily archived by the following code: ...
2
votes
0answers
29 views

How to view current settings for all options?

I know that setopt with arguments will show the options that are set to values different from the default; e.g. % setopt interactive login monitor norcs shinstdin zle If you have memorized all the ...
0
votes
1answer
83 views

Running a command on different shells

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

sharing or synchronizing history between Zsh and Bash

I often find myself switching between Bash and Zsh, and using the history search functionality to recover a command. However, since Bash and Zsh have different history files, I often find that the ...
2
votes
1answer
51 views

How to interpolate ${:-=cat} within a double-quoted string?

(In the following cat is a stand-in for "any command in $PATH".) Consider this example: % TMP=${:-=cat} % FOO="blah blah blah $TMP blah blah blah" % echo $FOO blah blah blah /bin/cat blah blah blah ...
1
vote
1answer
42 views

What does the + do in $+commands[…]?

Here's another question that is impossible to search for: how to interpret $+commands[foobar]? I assume that it is a variant of $commands[foobar], but who knows. (With zsh, at least I never know.) ...
1
vote
1answer
74 views

Is there a built-in (or at least simple) way to check for the existence of a function accessible through $FPATH?

I want to define a function foo in a script (intended to be sourced), but only on the condition that some executable, shell built-in, function, or alias of that name doesn't already "exist". The ...
1
vote
1answer
180 views

Changing directory color with zsh + Prezto

I am using Prezto + zsh as my shell. I would like to change the color of directories when I ls my directory. For instance, here is what I currently have: Obviously, this is no fun, as I'm hardly ...
18
votes
3answers
1k views

How to fix tab completion so it doesn't hide entries?

I'm using oh-my-zsh on Mac OS X with homebrew'ed zsh 4.3.12. I stumbled recently on a weird problem. In scripts/not-used I have several .R files: breakdowns.R eventloop.R ...
3
votes
1answer
43 views

How to trace parameter parsing and expansion?

The example below illustrates the sort of "Daily WTF" that I take zsh scripting to be. I've pretty much given up hope of ever understanding zsh's voluminous rules well enough to be able to figure out ...
1
vote
1answer
32 views

Backward and forward search are reversed with vi mode in zsh

When I enter in vi mode with set -o vi, I enter in command mode, and I touch the key ? it produces a / and the reverse. Is it normal? How can I change this behavior?
2
votes
2answers
53 views

How to create hyphen alias for zsh?

I am using zsh and oh-my-zsh on Ubuntu. To change into the recent directory in the past there was an alias set to - which is the same as cd -. Somehow the alias disappeared at my machine. This might ...
3
votes
4answers
107 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 ...
1
vote
1answer
106 views

How to pass environment variables to a new ssh-initiated login session?

Suppose that some variable FOO is defined (and export-ed) in the current environment. Let me call this environment E0. Now, I log into some other Unix system using ssh. % ssh ...
2
votes
2answers
48 views

Command behaving differently when saved in a *.sh file

I was not able to find an answer to this question, so maybe one of you guys can help me out :) I wrote some shell scripts to help me automate things, and they work. However, what doesn't work is ...
10
votes
2answers
6k 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\]" ...
1
vote
2answers
89 views

Passing variable definitions to specific shells in ssh

I would like to ssh to a machine with a pre-defined setting, specifically in zsh. To do so, I have tried doing the following from the client (inspired by this answer): $ ssh -t machine@domain ...
1
vote
2answers
85 views

How do you manage your bash/zsh Aliases?

How do you manage your bash/zsh Aliases? Is there a tool to do this more easily and less "think of an alias -> open .zshrc-sourced-file -> edit -> close, reload .zshrc -> use alias"?
6
votes
4answers
2k views

Getting relative links between two paths

Say I have two paths: <source_path> and <target_path>. I would like my shell (zsh) to automatically find out if there is a way to represent <target_path> from <source_path> as ...
1
vote
2answers
34 views

What does the `set — $args` line do here, and why does it behave differently between Zsh and Bash?

In the manpage for the version of getopt that comes with Mac OSX, an example is given that uses the construction args=$(getopt optstring $*); set -- $args. What does set -- $args do here? ...
4
votes
3answers
2k views

ZSH: `ls *(.)` lists regular files only but `ls *(/)` does not list directories only

I'm not sure I am using ZSH's globbing correctly, but I thought ls *(/) would just list the dirctories under pwd, but it doesn't, it recursively lists all files under every directory under pwd (I got ...
6
votes
3answers
480 views

Clear or disable aliases in zsh

I installed oh-my-zsh to make terminal use a bit easier. One thing that bugs me though is the prolific aliases added by it, like "ga", "gap", "gcmsg", "_", which are harder to remember than the ...
2
votes
1answer
253 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 ...
46
votes
4answers
6k 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 ...
37
votes
2answers
1k views

Completing avfs fake directories in zsh

How can I tweak zsh's completion system to complete “fake” files in some circumstances? More precisely, the AVFS filesystem exposes archives as directories by creating a “fake directory” next to ...
0
votes
0answers
96 views

Strange Highlighting Color In ZSH Menu

I am using Arch Linux and zsh. When selecting options from a menu in zsh the color appears to be off when moving down in the list. For example after pressing the tab key twice after typing cd results ...
3
votes
1answer
238 views

Exiting terminal running “nohup ./my_script &” => “You have running jobs”. OK to exit?

Say I run the following on a remote box with the idea of preventing killing the job when I disconnect the terminal. nohup ./my_script.sh & When I try to exit my terminal, I got the following ...
5
votes
2answers
75 views

how do I call git commands without 'git ' in front?

How do I tell my zsh to automatically try a command with git in front, if the command is not found? E.g. I want to run $ status and if there is no status in $PATH, my zsh should try git status.
2
votes
1answer
101 views

Bash/zsh tab autocomplete: Given initial command, ignore certain files in directory with autocomplete

What I'm asking is a little bit specific, and might be a different than other autocomplete questions on Unix Stackexchange. Suppose I have a directory that looks like this -rw-r--r-- 1 hlin117 staff ...
1
vote
1answer
51 views

How to manage configurations across multiple computers and shells?

I am a traveling technologist who does not always have a reliable connection to a home server. I tend to jump between zsh and bash on a few of my own machines. What advice or recommendation would you ...
0
votes
1answer
51 views

Where is zsh storing my history?

I have two terminals open, both running zsh. The history options which I currently have set are these: export HISTFILE=~/.histfile export HISTSIZE=10000 export SAVEHIST=10000 setopt ...
2
votes
0answers
100 views

How to setup zkbd (zsh keyboard bindings) in a server?

I have zsh shell in a Linux server, and connect to the server from screen sessions in different computers. I'm trying to get control keys, such as home and end, to function correctly. Because zsh ...
0
votes
1answer
48 views

Expand parameter in quotes in zsh

(Not sure the title is adequate, at least I tried my best…) I want to pass function arguments to zsh’s emulate to evaluate a command in bash emulation: $ .bash() { emulate bash -c "$*" } $ .bash ...
1
vote
1answer
50 views

Can up arrow command history for oh-my-zsh narrow down history by options/parameters given to the command

Not sure I'm wording the question very well, but an example is worth a thousand words of mine. eg., using oh-my-zsh : git <up arrow> Will cycle up all the git commands I have used... git ...
2
votes
1answer
16 views

Is it possible to use two characters (e.g. ^tm) in insert mode in zsh for a command binding?

in my current .zshrc file I have bindkey -M viins -s '^tm' '^[Iman ^[Ela ^[d$' and this doesn't work, however when I remove m from the shortcut and it is now only ^t the shortcut is working. I'd ...
1
vote
1answer
72 views

zsh capture and pipe output to another command

I had the zsh script printf '%s\0' www/scripts6/lib/* | xargs -0 -I{} -P 50 babel {} > {} and it worked (i think.). But I needed to actually copy the files to the scripts directory instead of ...
2
votes
1answer
77 views

zsh wait for jobs to complete

When I type the following in my terminal running zsh (each line is a command) babel www/scripts6/lib/data.js > www/scripts/lib/data.js & babel www/scripts6/lib/user.js > ...
4
votes
5answers
338 views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...