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

learn more… | top users | synonyms (1)

1
vote
1answer
40 views

How to declare some aliases dynamically in zsh?

I would like to declare a few shortcut commands to switch between my various coding projects, so I have come up with the following script. projects=$(ls -d ~/Workspace/*/) ...
5
votes
2answers
192 views

What is causing `diff` to run `git diff`?

I'd like to use diff as described here and in the documentation I see when I type man diff. However, when I type diff, what I get is this: ~ ❯❯❯ diff usage: git diff --no-index <path> ...
1
vote
1answer
28 views

strange setopt behavior

For certain options, setopt doesn't have an effect. ➜ ~ setopt | grep history extendedhistory ➜ ~ setopt appendhistory ➜ ~ setopt | grep history # appendhistory apparently didn't get set ...
3
votes
1answer
52 views

How to create an alias for two Git commands that use a parameter? [duplicate]

I regularly have to delete a local and remote Git branch. Therefore, I run the following commands: $ git branch -d feature-branch $ git push --delete origin feature-branch Since I mostly execute ...
4
votes
1answer
78 views

How to create string with invalid unicode characters, in Zsh?

For some testing purposes I need a string with invalid unicode characters. How to create such string in Zsh?
3
votes
3answers
168 views

Repeating command with different filenames

Here's a layup for someone... I'm having to run a command repeatedly: $ wp input csv MyCSV01.csv directory_name $ wp input csv MyCSV02.csv directory_name $ wp input csv MyCSV03.csv directory_name ...
3
votes
2answers
80 views

How to know why and where the $PATH env variable is set?

I'm using zsh 5.0.8 version in iterm2 on OSX. I start my computer and printenv shows me the $PATH variable: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin from my understanding, ...
0
votes
1answer
46 views

How to create multiple dot files using brace expansion?

I want to create a bunch of dot files using brace expansion, but it doesn't work: touch .{a..h} the result is a file .{a..h} is created instead of .a .b .c ...
2
votes
3answers
371 views

Why rm exclude using ! doesn't work in zsh?

I have 10 files in current directory: 10test 1test 2test 3test 4test 5test 6test 7test 8test 9test I want to remove all file except 2test and 3test, but I run command rm !(2test|3test) doesn't ...
3
votes
1answer
64 views

move files based on pattern with zsh/zmv

How could I move files to subdirectories based on the common part of their names? For example, with files named as comment_LastName.pdf and comment_LastName.md and sub-directories named as ...
9
votes
7answers
290 views

Check variable is an array in Bourne like shell?

In Bourne like shell which support array variable, we can use some parsing to check if variable is an array. All commands below were run after running a=(1 2 3). zsh: $ declare -p a typeset -a a ...
0
votes
0answers
29 views

Fill the name of last-run program in Bash

Suppose I execute some command: ls -l ~/some_dir. I would like to create an alias, such that I could execute man with the name of the last-run program as a parameter, i.e., man ls in this case. ...
0
votes
0answers
43 views

How to change theme with zsh

I am using this configuration on my mac(unix) to customize my shell. I am using zsh instead of bash and there are too many things along with zsh. This .dotfile configuration contains vim, zsh, git, ...
2
votes
2answers
124 views

Shell valid function name characters

Using extended Unicode characters is (no-doubt) useful for many users. Simpler shells (ash (busybox), dash) and ksh do fail with: tést(){ echo 34; } tést But bash, mksh, lksh, and zsh seem to ...
1
vote
2answers
48 views

how to grep for packages on basis of uncompressed file-size?

In Debian when you look at a package, you get lot of info. Including the uncompressed file size of the package. Is there a way to grep through the file-listing so that packages appear either from ...
4
votes
1answer
80 views

What is the best way to pipe the output of a command through a pager if (and only if) it is too long?

I'd like to be able to be able to wrap a command so that if its output doesn't fit in a terminal it will be automatically piped through a pager. Right now I'm using the following shell function (in ...
8
votes
4answers
179 views

Right-to-left shell brace expansion

In zsh (and other shells), if I include an argument like (for example): {a,b,c}{d,e,f} brace expansion turns it into: ad ae af bd be bf cd ce cf For my purposes, the argument order is important, ...
5
votes
3answers
106 views

Is “Arithmetic Expansion” the expected action on vars inside `[[` tests?

This script: a=2 [[ "$a" -eq 2 ]] && echo yes1 [[ $a -eq 2 ]] && echo yes2 [[ a -eq 2 ]] && echo yes3 [[ "a" -eq 2 ]] && echo yes4 Does not work in dash (and ...
0
votes
0answers
21 views

Setting tmux session title in zsh

There was a similar question about screen regarding this here, but I was unable to get this working with tmux. From what I understood printing a string with prepended with \033k and appended with ...
5
votes
1answer
65 views

In zsh, what's the difference between &! and &|?

In my adventures with disown, I also discovered that in zsh, program &! starts and immediately backgrounds and disowns the program, so you can close the shell without the program getting a SIGHUP. ...
3
votes
2answers
66 views

Shebang line for “run with $SHELL”

I'm looking for what to put on my_zsh_script.sh's "shebang line" that would have the same effect, portably, as $SHELL my_zsh_script.sh IOW, I looking for the valid equivalent of #!$SHELL or ...
6
votes
1answer
142 views

Replace current process by its coprocess/child

I have a program P that expects to receive "Hello" and output "Why?" before providing a feature. This feature is used by other programs that are not aware that it is common courtesy to start a ...
2
votes
0answers
18 views

On using $hash_array[$(global_alias)]

Identical code works on one system, fails on another: % zsh --version zsh 5.0.7 (x86_64-pc-linux-gnu) % typeset -A frobozz % alias -g foo='echo xyz' % frobozz[$(foo)]=9 % echo ${(kv)frobozz} xyz 9 ...
2
votes
2answers
27 views

Forcing the expansion of a global alias in part of a word

I have a couple of scripts /tmp/foo/bar.sh and /tmp/foo/baz.sh, the look like this: # /tmp/foo/bar.sh alias -g __FILE__='${(%):-%x}' alias -g __DIR__='${${(%):-%x}%/*}' printf "sourcing %s\n" ...
1
vote
0answers
30 views

`ls\` logs out of terminal session?

Like many, I have an alias ll=ls -l[.]+ set. A moment ago, I typed ll and then accidentally hit \ on the way to return. I hit return again to finish the command (on the continued line prompt), ...
2
votes
0answers
39 views

How to avoid namespace collisions/pollution in a script meant to be sourced?

I want to implement a script foo.sh that culminates in the an execution of a command bar (with some arguments). The command bar modifies the current shell environment, which means that foo.sh must be ...
2
votes
1answer
28 views

How to reuse file pattern in .gitignore in bash/zsh?

Here is the content of the .gitignore cron.yaml build target webview *.pyc *.sublime-workspace .idea *.rej .coverage app/tools/temp_*.py app/tools/*/temp_*.py I am currently iteraring files in a ...
4
votes
4answers
205 views

Prefer file types in command line

Often I have to annotate multiple pdf documents using xournal. If I start with a directory of "fresh" pdf files, I just open them all with xournal: for f in *pdf; do xournal $f&; done When I ...
12
votes
2answers
321 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
75 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
165 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 ...
1
vote
2answers
77 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
0answers
117 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 ...
3
votes
1answer
32 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. ...
0
votes
1answer
167 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 ...
7
votes
3answers
108 views

'switch' based on shell

I would like to source (i.e. not call) a script from any shell (bash/csh are the primary targets, but fish, zsh, ksh, and rc would also be interesting). I would like if the script can be a single ...
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
2answers
84 views

Unexpected prompt in zsh

Can someone explain to me why I am getting this shell prompt when I'm in the /home directory, and how to get rid of it?  I am using zsh. I want it to display only the following: user@host ~ % but ...
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.) ...
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
385 views

Installing powerline fonts for zsh + Prezto theme

I am currently using Zsh + Prezto for my scripting shell configuration. I have been using the sorin theme but am a little dissatisfied with it. I'd like to switch to the paradox theme! It is supposed ...
6
votes
7answers
241 views

How can I apply `cut` to several files and then `paste` the results?

I often do operations like paste <(cut -d, -f1 file1.csv) <(cut -d, -f1 file2.csv) which is very tedious with more than a few files. Can I automate this process, e.g. with globbing? I can ...
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
78 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 ...
2
votes
4answers
77 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 {} ...
1
vote
2answers
196 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 ...
2
votes
2answers
56 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
118 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
109 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
49 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 ...