Questions tagged [zsh]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
31 views

How to write into the actual editing buffer

I want "ls" to be written, but not executed, by stroking Control+r. I'm using the following code, but it writes the command into the buffer that will be used to execute after hitting Enter. I would ...
0
votes
0answers
21 views

zsh shell, can't find .zshrc

On a Redhat 7 platform I installed zsh from source. - download source - ./configure - make -j && make install - chsh -s $(which zsh) It is installed in /usr/local/bin/zsh, instead of '/bin/...
0
votes
0answers
33 views

Why do I lose my ZSH history?

Every once in a while I discover my zsh history has been truncated (or maybe lost entirely, difficult to tell), and I have to restore it from backup. For example, today: ls -lh ~/.zsh_history -rw----...
1
vote
1answer
22 views

How to use terminal as program runner with FZF

I have a thought. Can I use a terminal as program runner? Instead of dmenu / rofi I was thinking to list all the programs with FZF, run the selection, and then close the terminal after it runs. I ...
0
votes
2answers
22 views

How to move all files in a folder to a sub folder in zsh w/ Mac OS X?

This question is basically a duplicate of this: https://askubuntu.com/questions/91740/how-to-move-all-files-in-current-folder-to-subfolder But instead I'm asking how to do it in the Mac OS X terminal ...
0
votes
2answers
62 views

How to define the name of a bash function to be a regex

I've searched around and can't find an answer. I want to define a function like this function \d{2} () { echo $1_or_smth } Then if I say in my terminal 12 I want it to echo 12 back.
2
votes
2answers
49 views

zsh: for loop over newline-delimited entries

I have a variable: ❯ echo $numholds 409503 409929 409930 409932 409934 409936 409941 409942 409944 409946 I want to do a for loop of it, but the newline-delimitation doesn't work: ❯ for num in ...
1
vote
0answers
19 views

Disable completion of arithmetic expressions in ZSH

If I type: echo "$((1 + 2))" And then press Tab, ZSH will transform what I typed into: echo 3 How can I disable this behavior? I don't want ZSH to evaluate the arithmetic expression when I press ...
1
vote
1answer
22 views

Make normal mode the default mode for zsh when vim keys have been set

I have set bindkey -v in my ~/.zshrc so that vim keybindings are created whenever I open zsh. Because of that, viins (a.k.a insert mode) is the keymap with which a new instance of zsh starts. I ...
1
vote
2answers
42 views

Create keyboard shortcut that includes “Alt” not to be triggered by pressing “Escape”

I've created the following mapping in ~/.zshrc bindkey -s '^[u' 'whatever string' and I have enabled vim mode by setting the following rule in ~/.zshrc bindkey -v The problem I'm having is present ...
-1
votes
2answers
65 views

Shell *for* loop through file and for each line use sed to delete lines from other file

I'm trying to clean up long-cluttered-filename.txt by deleting the lines that match the strings in my delete-these-lines.txt... $ cat delete-these-lines.txt context platform server civicrm ...
2
votes
0answers
34 views

How to fix path typos?

When typing quickly, I often mistype cd ~/myfiles as cd ~?myfiles, resulting in: zsh: no matches found: ~?myfiles Is there a way ZSH can autocorrect such mistakes?
2
votes
0answers
22 views

How to save exit code in history?

So with setopt extended_history, extra information is saved in the history file (format: : <beginning time>:<elapsed seconds>;<command>). The information is certainly useful, but I ...
0
votes
1answer
30 views

Save command line history only if exit code is 0

I looked in ~/.bash_history and I can see all the commands I have executed, even those with typos. Is there a way to save only the commands that have succeeded (i.e. exit code 0)? Note: I am using ...
0
votes
1answer
32 views

How to set “less” and “lesspipe” correctly?

I had set less to a vim less functionality some years ago and I would like to reverse those changes. Therefore I started removing the alias from "~/.zshrc". Since after sourcing this file my system ...
0
votes
1answer
34 views

Having sudo and non-sudo parts in an alias - why does it not work with >>?

I was trying to use an alias which should run two commands, where the first is fine to be run with normal user privileges and the second one needs sudo privileges. alias hosts-get="scp user@host.com:...
0
votes
1answer
29 views

Launching Sway on login with zsh

I set up .bash_profile to exec sway on login, and then ended up switching to zshell as my default shell. When I log in it just stays it no longer auto launches sway of course. I'm wondering if there ...
1
vote
1answer
56 views

oh-my-zsh's prompt is slow: how to fix this

I'm using macOS 10.15.2 with iTerm2, zsh 5.7.1 and oh-my-zsh (theme robbyrussell). I noticed that the prompt print is slightly slow respect to the bash one. For example, if I press enter, cursor ...
1
vote
1answer
35 views

Zsh configuration - line navigation à la VSCode

I actually already asked the question on superuser and stackoverflow. I am using VSCode and I have this nice behaviour: when I do Alt+→ from the end of the line, it stops at foo/bar/test_wait_what ...
0
votes
1answer
56 views

List all directories in home folder with fd

I'm trying to write a shell function to rapidly cd into any directory in my home folder, using the fd and fzf programs. This is what I have so far function fdcd() { cd "$(fd --type d --ignore-file ...
2
votes
1answer
62 views

Zsh: timeout for vared builtin

I've got a while loop that uses vared to prompt for user input. I am looking for a way to have it timeout, execute a default variable and loop back to the prompt if there is not user input after a ...
1
vote
1answer
32 views

zsh script prompt reading single keystroke: add newline when appropriate?

I have a script that takes an -i flag (→ $interactive) and if set, asks a yes/no-default-no question for each target, à la rm -i and others. Zsh’s read -q is designed for this exact case—it accepts a ...
1
vote
0answers
31 views

Stop completion on certain characters

With the grep command, I tend to use various combinations of -irln and restrict it to include one or more of the same file types py, js, html, css. E.g. grep -ril --include=*{html,css} I'm ...
3
votes
1answer
46 views

command substitution does not respect err_exit sometimes

I have a weird situation where inserting any command that succeeds in the line above makes command substitution ($(I mean this)) not work as expected — it does not exit, even though the command fails ...
1
vote
0answers
24 views

How to get zsh to not save commands that have failed into history?

I would like to have zsh not save commands that have failed into the history file. The reason for this is to have a tidier output when I am searching through previous commands later on. I don't want ...
0
votes
0answers
10 views

zsh - run gpustat command after login

I am trying to execute the gpustat command after SSHing into a remote server. I am using z-shell + oh-my-zsh. I put the gpustat command into my .zshrc file. However, after logging in, I get the ...
0
votes
0answers
42 views

zsh startup - interactive shell not running .zlogin

I have just installed zsh on my Mac (OS X 10.15.2 Catalina), and now am trying to get it working right on a computer running Mint 19.3. The Mac has shared bash startup files with the Linux computer (...
0
votes
1answer
53 views

Proper way to trap in zsh script

I'm having trouble getting a trap function in a zsh shell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using Ctrl+C, and when I do I ...
0
votes
0answers
61 views

I want to create the launcher. When I click it, which open the shell and run `source ~/venv/bin/activate && cd ~/workspace/python_script`

-----New text------ My quention:How to create the launcher thet is like below. I want to create the launcher that include the 2 steps. First Step:Open the new tilix window(it call Zsh1). Second Step:...
0
votes
1answer
31 views

How to tell zsh to directly enter the auto-completion list?

When I am using zsh (default installation of oh-my-zsh) and press Tab it auto-completes the path which is very useful. If there is only one candidate the auto-completion system just add the candidate ...
1
vote
0answers
15 views

zsh testing existence of a key in an associative array via indirect expansion

So I know that you can test for the existence of a regular parameter via indirect expansion by doing something like: foo=1 bar=foo (( ${(P)+bar} )) && print "$bar exists" And I know you can ...
0
votes
1answer
43 views

$SHELL in tmux is different than $SHELL in the shell that I launched it from

Been wrestling with this for a few hours and it’s driving me crazy. When I SSH into my machine at home, my default shell is zsh. I can confirm this with echo $SHELL, which outputs /usr/bin/zsh When I ...
0
votes
0answers
22 views

I removed some files related to a zsh prompt. Now prompting keeps complaining. How do I `deregister` it?

I was cleaning up some files and deleted a theme I was using. Switching to another theme globally does not remove this warning. When my zsh session starts up, it warns because of promptinit. % ...
2
votes
2answers
110 views

Script to recursively replace invalid characters in filenames, not directories, with rename

I'm looking to write a script that will find and replace any characters other than [^A-Za-z0-9._-] in a specific file type (in this case .avi) with an underscore _. I want this to exec recursively ...
0
votes
0answers
12 views

zsh function to automatically capture byobu scrollback buffer and open in micro editor

I am attempting to create a zsh function in my .zshrc file so that I can have one command that will capture byobu's scrollback buffer into $BYOBU_RUN_DIR/printscreen (the default location) and then ...
1
vote
0answers
46 views

Alternative to fc command in zsh

I have below code: # CTRL-R - Paste the selected command from history into the command line fzf-history-widget() { local selected num setopt localoptions noglobsubst noposixbuiltins pipefail ...
0
votes
2answers
123 views

Which code works (with builtins) both in bash and zsh with the `time` keyword?

It is usual to do time cmd for many types of cmd(s) in bash: $ time true real 0m0.000s user 0m0.000s sys 0m0.000s The output format could be changed (even to a posix format with time -p): ...
1
vote
0answers
24 views

Ignore history when using zsh

I set the HISTORY_IGNORE variable in ~/.zshrc and it correctly prevents those commands from being written to ~/.zsh_history. But what I really want is for those entries not to show when pressing up ...
0
votes
1answer
48 views

bash alias that emulates Finder's archive with ditto?

So I find it useful to have a function defined in my shell such as the following: zip() { ditto -c -k --sequesterRsrc --keepParent "$1" "$1.zip" } How would I extend this to take any number of args ...
0
votes
1answer
68 views

`time <command>` is different in zsh than in bash

Format of time <command> in bash: $time ./test.sh real 0m0.000s user 0m0.006s sys 0m0.000s In zsh: $time ./test.sh ./test....
2
votes
2answers
202 views

Bash script throws “assignment to invalid subscript range” when running from zsh

Update Looking through this link, I updated the array subscript to start with 1 instead of 0 and seems like the array variable is read properly. #!/bin/bash #Root folders for Git update. ROOT[1]=...
1
vote
0answers
35 views

Why is zsh ignoring my -f switch when removing files? [duplicate]

I just moved to zsh from bash on my mac, i hope this is the right place to ask. Works great, although I've noticed that if I run rm, for example rm -rf my directory I always get a prompt asking me ...
0
votes
1answer
52 views

Zsh: complete the files in current directory no matter what command is

For example, when I just want to make cfiles without makefile: $ make a<tab> a1.c a2.c a3.c ... but seems that zsh would detect the command then completes nothing when I hit tab. It works ...
1
vote
1answer
56 views

zsh: insert last argument of previous command

I recently switched from bash to zsh. When typing a new command in bash (in vi mode), if I type Esc-_ (escape underscore), it inserts the last argument of the previous command. I want to do the same ...
1
vote
0answers
44 views

zsh: history with cursor at beginning of line

I recently switched from bash to zsh. One (annoying) difference is that when I do Esc-K (in vi editing mode) to move back in command-line history, the cursor is placed at the end of the line initially....
0
votes
1answer
63 views

Shell won't start after change from zsh to bash

I was using zsh for a couple of years on my ElementaryOS. I started to play with some settings yesterday and I wanted to switch to bash temporarily with chsh -s bash. Then I restarted the terminal and ...
1
vote
2answers
90 views

diffrence between ls -l *.<sometthing> | wc -l and ls -l | grep <something> | wc -l

I have a folder with a huge file list that I want to count. I was doing ls -l *.json | wc -l and it was working fine, till the list apparently gone huge enough that this command didn't work any more. ...
2
votes
1answer
20 views

find command can't find zcompile

Since I'm new-ish to zsh my entire concept could be wrong for all I know but I've noticed that my system can't find zcompile when I run it from a find command like so: find . -type f -not -name "*....
1
vote
1answer
16 views

How to cancel selection mode in zsh in other way than add text to $BUFFER?

zle widgets working by Ctrl-Right keys, Ctrl-Left keys (first widget is starting selection mode): c-sel-r-reg () { local WORDCHARS=${WORDCHARS/\/} zle select-in-word } zle -N c-sel-r-reg bindkey "...
4
votes
2answers
582 views

Why does arithmetic expansion work in Bash but not in Zsh?

I was demonstrating a piece of funny code (or so I think) to my students in class, and to my surprise, it did not work in zsh. I then switched to bash and it worked as expected. The code is the ...

1 2 3 4 5 37