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

learn more… | top users | synonyms (1)

1
vote
1answer
30 views

How to update prompt on directory change

For example with following: prompt_git() { local PL_BRANCH_CHAR () { PL_BRANCH_CHAR='!' } local ref mode repo_path repo_path=$(git rev-parse --git-dir 2>/dev/null) if $(git rev-...
3
votes
1answer
109 views

No zsh-syntax-highlighting within tmux

I experience proper zsh-syntax-highlighting (see here) when first opening a shell session, but as soon as I enter tmux, the syntax highlighting no longer appears. I found this Github issue ...
3
votes
1answer
38 views

Shell that tab-completes prefix?

I would like tab completion to behave differently when the cursor is at the beginning of a word than when the cursor is at the end of a word. I've only ever seen shells that tab-complete the suffix, ...
1
vote
1answer
190 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, ...
1
vote
1answer
32 views

store file with invalid characters

Some files we get from a customer could not be processed properly because they were declared as US-ASCII but contained invalid characters. In order to validate a software fix, I am trying to copy ...
3
votes
1answer
21 views

how can I profile prompt rendering time in zsh?

short version: How can I profile each rendering of a zsh prompt? long version: I've recently came across a plugin (rupa/z) that, when installed, hit my zsh prompt rendering time by a noticeable ...
2
votes
1answer
27 views

zsh completion: menu and unambiguous prefix with a single tab?

I'm in a folder where I have the following files: aaa1 aaa2 aaa3 bbb1 bbb2 bbc1 bbc2 and I have typed cd a at the prompt. Currently, pressing Tab completes to cd aaa then another Tab brings ...
1
vote
1answer
33 views

zsh keeps sharing history even when shared history is disabled

I'm using zsh with prezto (on OSX and inside tmux, not sure if it matters), and from time to time history gets shared between multiple terminals. I already added unsetopt share_history and also ...
3
votes
1answer
25 views

Loop over a string in zsh and Bash

I would like to convert this Bash loop: x="one two three" for i in ${x} do echo ${i} done in such a way to work with both Bash and zsh This solution works: x=( one two three ) for i in ${x[...
3
votes
1answer
43 views

How can I use a key other than <ENTER> to exit zsh's completion menu/widget?

Like alot of zsh users I have completion configured so that when I am at a command prompt and I invoke completion a menu appears that can be navigated with the directional arrow keys. i.e. in my ~/....
51
votes
6answers
11k views

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is ...
0
votes
2answers
75 views

Wildcard not working in quotes

The script is supposed to loop over subdirectories and match all the filenames (FLA.*Image.*file.jpg and FLA.*Image.jpg) in subdirectories and process it. It also create output folder inside the ...
1
vote
2answers
20 views

Best way to browse different versions of a backup of a directory

I am using a rsync backup script (see here: http://codereview.stackexchange.com/questions/29429/push-backup-script) which creates directories like back-2015-07-02T21_18_01 Now suppose I am in ...
4
votes
2answers
62 views

paste url into terminal(urxvt, zsh) failed, some characters get escaped

In recent months, I find that if I copy the url in chrome and then Shift Insert in the urxvt, the pasted url is escaped. For example, the original url is: http://example.com/?a=c the pasted ...
2
votes
2answers
37 views

Measure execution time of a command including expansion of command substitution

How would I go about measuring the running time of commands that are expanded by the shell? For example: ➜ time sleep $(sleep 3; echo 1) sleep $(sleep 3; echo 1) 0.00s user 0.00s system 0% cpu 1....
0
votes
1answer
26 views

zsh alias with arguements

I have an alias for neovim-qt thus defined: gvim='nvim-qt --geometry 500x320 --' This allows me to call gvim foo.py ook.py and have a QT window running neovim with two tabs, one for each file. ...
0
votes
0answers
29 views

command substitution within c style for loop in Zsh

I have a function printing a number myFunc() { echo 11 } Now I want to use the number in expression in c style for-loop: for (( i=1; i<=$(myFunc); i++ )); do echo "$i" done Zsh gave ...
1
vote
1answer
29 views

List names of aliases, functions and variables in zsh

I need a way to list the names (without the body/content/value) of aliases, functions, variables, arrays in zsh. Optimally its behave like compgen: compgen -a # will list all the aliases you could ...
1
vote
1answer
36 views

What causes this behavior when defining a function named ':'

If I create the following function function :() { echo "hi" } then any time I type any character, the function is executed as soon as I type it, and before I hit return! This seems to be ...
0
votes
0answers
91 views

Run console printing command after tmux starts up

I'm starting tmux from zsh with the window split into two panels. The only issue I'm having is screenfetch starts up and prints to both windows. Ideally I only want it printing on the left window. I ...
0
votes
2answers
53 views

Shutdown as a Mac

I have a iphone app that can remotely shutdown a mac computer. I would like this app to shutdown my Ubuntu computer. I'm getting following messages from the application when trying to shutdown: When ...
1
vote
2answers
36 views

zsh displaying my name weird

Upon installing zsh, the shell has displayed my name like [\u@\h \W]\$ I tried adding PROMPT='%n>' to my .zshrc, but it does not seem to have helped.
1
vote
1answer
32 views

$* variable of zsh function leads to unexpected results

I have this function (defined inside my ~/.zshrc): function graliases { if [[ "$#*" -lt 1 ]] then echo "Usage: graliases <regex>" else echo "$*" grep -E '*"$*...
2
votes
1answer
19 views

zsh auto completion certain parts of directory

I currently have zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' which will ignore the case when auto completing directories. However is it possible to type a certain part of the directory and ...
2
votes
0answers
37 views

How can I programmatically access zsh completion?

zsh has a completion system, activated by pressing tab: llama@llama:~$ git st<Tab> Completing main porcelain command stash -- stash away changes to dirty working directory status -- ...
1
vote
0answers
10 views

How did I get the git commits to show up in autocomplete?

Git tab completion on my mac: Git tab completion on my Ubuntu server: On my mac and my Ubuntu server I get very different output from tab completion despite having the same version of zsh, same ...
7
votes
0answers
123 views

How to make the zsh “correct” functionality, remember my spell-correction decisions

I have enabled correction (I wouldn't call it autocorrection specifically because of this issue) in zsh by enabling setopt correct in my .zshrc. Now, when I type dtae in a terminal, I get: dtae ...
9
votes
4answers
39k views

Change font in echo command

Is it possible to change the font attributes of the output of echo in either zsh or bash? What I would like is something akin to: echo -n "This is the font: normal " echo -n $font=italic "italic," ...
4
votes
2answers
565 views

How change prompt of subshell

I'm trying to create a simple script that, among other things, will create a subshell: #!/bin/sh # setup "${@:-$SHELL}" # teardown The question is: I need to change the default prompt, so for ...
1
vote
1answer
910 views

Colors not rendered correctly in oh-my-zsh themes

I'm trying to use colors in oh-my-zsh themes. It works fine on my home computer (ubuntu), but in a work computer (Scientific Linux i.e. Enterprise linux) the prompt colors are actually spelled out. ...
7
votes
4answers
131 views

How do I determine if a program is running when I start a shell and start that program if it is not already running?

When I start a shell, in my case bash and/or zsh, what lines do I need to add to .zshrc and/or .bashrc to check to see if a program is already running, and if the program is not already running, start ...
2
votes
1answer
27 views

Backspace in zsh stuck

In set -o vi mode in bash, when I press Esc+k to get the last entered command, and then A, I end up in the insert mode, which allows me to press backspace to start deleting the end of the last command....
1
vote
1answer
33 views

Printing all variables starting with foo in zsh

In bash: foo_a=1 foo_b=2 declare -p ${!foo_*} Outputs: declare -- foo_a="1" declare -- foo_b="2" How do I do this in zsh? Why won't pasting the above into zsh fail to even set the variables? ...
1
vote
1answer
40 views

Copying current command line to clipboard [duplicate]

In bash with set -o vi, I use bind '"\C-]":"\C-[A\C-u cb <<"EOF"\n\C-y\nEOF\n"' to make ^] in insert mode cat the current line to my clipboard wrapper (cb). How do I emulate this in zsh (...
1
vote
0answers
41 views

Can I change how zsh autocomplete works?

I love the zsh autocompletion for navigating in files with commands like cd, but some commands have weird autocompletion, for example: when i type snap ins, bash autocompletes that to snap install, ...
1
vote
1answer
34 views

binding key shortcuts to shell functions in zsh

In zsh, how do I bind a keyboard shortcut to a function? In other words, how do I translate: bash: hw(){ echo "hello world"; } bind -x '"\C-h": hw;' to zsh?
5
votes
1answer
461 views

Keyboard bindings from bash to zsh?

I have the following entries on my .inputrc for bash: "\C-p": history-search-backward "\C-n": history-search-forward "\e[A": history-search-backward "\e[B": history-search-forward "\e[C": forward-...
0
votes
0answers
35 views

tmux ctrl-k to erase the line from cursor to end of line

Outside tmux I use ctrl-k to erase the line in my terminal with zsh from the cursor to end of line. When I'm in tmux it doesn't work. Below is my tmux.conf: set-option -g prefix C-a # From: https://...
1
vote
1answer
32 views

How to change the key for autocompletion in ZSH?

I'm on Ubuntu Mate 16.04 using terminator as my terminal. And using ZSH version 5.1.1. I'd rather change the keybinding to the left arrow key to emulate fish in a way. Anyone know how?
37
votes
1answer
10k 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 $...
1
vote
1answer
24 views

New keybindings in ZSH are not saved

I just switched from bash to zsh on my arch linux install and want to change my keybinding so that ctrl + arrow skips a word forward/backward. If I add bindkey "^[[1;5C" forward-word bindkey "^[[1;5D"...
0
votes
0answers
30 views

How to map Ctrl-c to normal mode in zle?

In zsh with vi bindings, I want to leave insert mode not only using Esc but also using Ctrl-c. I tried this as suggested in another answer. bindkey -M viins '^C' vi-cmd-mode Pressing Ctrl-c still ...
10
votes
4answers
985 views

Why does cut fail with bash and not zsh?

I create a file with tab-delimited fields. echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input I have the following script named zsh.sh #!/usr/bin/env zsh while read line; do <<&...
3
votes
2answers
71 views

obtain shell prompt in python

I want to obtain the (zsh) shell prompt in a python script. Simply using import os prompt = os.environ['PS1'] seems not to be the right way, because PS1 is usually not forwarded to subprocesses. In ...
1
vote
0answers
27 views

highlighting of zsh correction

When zsh's autocorrection suggests a change in long filename, it may be hard to spot which change is actually suggested: The example is of cause artificial as tab completion would've done the job (...
2
votes
0answers
33 views

custom zsh autocomplete

I'd like to write a zsh completion for pytest. Where do I Start? I'm using oh-my-zsh. in .zshrc: fpath=($HOME/.mycompletions $fpath) autoload -U compinit && compinit -u in $HOME/....
1
vote
1answer
15 views

zsh vi mode: browse recent commands starting with

I've recently switched to vi-mode in my zsh and there is a feature from emacs-mode that I cannot find how to do in vi-mode. The feature is browsing history by lines starting by something I've already ...
2
votes
1answer
21 views

how to have a custom zsh auto_cd command

Instead of the normal cd I've created my own function function cd { builtin cd "$@" && ls -F } This works great for when I use commands like cd someDir/subDir but not when I change ...
3
votes
1answer
35 views

Write warning while typing in zsh prompt

I know that it is possible to display text "outside" of the zsh prompt where you are typing. Common example is completions: myhost Wed 8 10:06 ~/sandlot $ e .py█ Press Tab, et voilá: myhost Wed 8 ...
2
votes
2answers
268 views

Ctrl-Arrow does not work anymore after installing Prezto

I have this in my .inputrc: "\e[A": history-search-backward "\e[B": history-search-forward set show-all-if-ambiguous on set completion-ignore-case on # mappings for Ctrl-left-arrow and Ctrl-right-...