New answers tagged

0

Found the solution, I have to disable auto completion for sudo command. I just had to add following line to the end of ~/.zshrc file: alias sudo='nocorrect sudo'


0

try this echo "root ALL=(ALL) ALL" >>/etc/sudoers


1

watch is not an internal command: $ type watch /usr/bin/watch so make sure it installed on the system where you are running zsh.


1

When a command is not found, zsh invokes the function command_not_found_handler. A typical use for this function is to suggest a way to install the command, if it's part of a package that's part of your distribution but isn't installed. In zsh, if the function returns a nonzero status, zsh prints its usual error message. Bash has a similar feature (there ...


1

I tried the function with zsh -f (which I should have done before posting..), and found that it worked as expected. Something else is causing this issue, so I'm closing this question when able. EDIT: For those interested in what the issue was, and how it was solved, look below. I used the zsh framework ZIM which uses vcs_info to check if the current ...


2

As per the comments, I tried disabling oh-my-zsh, which fixed this problem. I then went through the oh-my-zsh source, selectively disabling modules. I previously had CASE_SENSITIVE="true", but commenting out this line fixed it for me. Apparently it's a known bug. To fix it, I could put the following line in ~/.zshrc after sourcing oh-my-zsh. zstyle ...


0

On top of what @cuonglm said, check for references to bash in your .tmux.conf. For example, I was using a typical integration for copying & pasting in iTerm on Mac: set-option -g default-command "reattach-to-user-namespace -l bash" ... which, to function properly with zsh had to be changed to: set-option -g default-command ...


2

When you press Enter (accept-line command), the current line is parsed and scheduled for execution. If the line is syntactically incomplete (e.g. echo \ or for x in foo), it isn't executed, but it's already stored. You can see that zsh is in this state because it shows the PS2 prompt instead of the usual PS1. As far as I know, there's no built-in way to ...


8

Use $^array. It turns the array into a sort of brace expansion of the array. As in when a=(foo bar baz), $^a would be a bit like {foo,bar,baz}. $ a=(foo bar baz) $ echo prefix${^a}suffix prefixfoosuffix prefixbarsuffix prefixbazsuffix For multiplexing arrays: $ a=(1 2 3) b=(a b c) $ echo $^a$^b 1a 1b 1c 2a 2b 2c 3a 3b 3c Naturally, if the prefix or ...


0

A similar question was asked here: zsh: stop backward-kill-word on directory delimiter and a workable solution given: add these settings to your zshrc: autoload -U select-word-style select-word-style bash


1

Ok, figured it out, I could just manipulate the different buffers directly: x-paste() { PASTE=$(pbpaste) LBUFFER="$LBUFFER${RBUFFER:0:1}" RBUFFER="$PASTE${RBUFFER:1:${#RBUFFER}}" } zle -N x-paste bindkey -M vicmd "p" x-paste


14

You could put a shell wrapper around a call to python (put this in .zshrc or .bashrc... depending on your shell), python () { if [ "$1" = manage.py ]; then command python manage.py && xyz else command python "$@" fi } But I suspect you are better off changing manage.py to run xyz at the end (see python subprocess ...


1

zsh keeps the position of the cursor in the variable CURSOR so: paste-from-clipboard () { CLIPOUT=`xclip -o` BUFFER=$LBUFFER$CLIPOUT$RBUFFER CURSOR=$(( $CURSOR + ${#CLIPOUT} )) }


0

The solution I found was to simply bind Ctrl-P to Ctrl-O in tmux. Add this line in .tmux.conf: bind -n C-o send-keys C-p


2

A simple way is to put code in your shell startup file to read an additional history file, and make sure that you store sufficiently many history lines in memory so that the sticky lines aren't forgotten. bash In ~/.bashrc: history -r ~/.bash_history.sticky Also make sure that HISTSIZE is at least HISTFILESIZE plus the number of lines in ...


0

You can force the ZSH to clobber on redirect with: >! Same as >, except that the file is truncated to zero length if it exists, even if CLOBBER is unset. or >>! Same as >>, except that the file is created if it does not exist, even if CLOBBER is unset.


0

In Zsh, I retain history for a long time. The HISTSIZE is 20000. (There are various settings involved in that, so I won’t list them here.) That buys me ~10 months worth. My history file (~/.zhistory) weighs in at 1.1 MiB and doesn’t make startup noticeably slower. I commonly pull in working history from other terminals with fc -R (when multiples are open — ...


1

In bash (don't know about zsh), you can set export HISTFILESIZE=-1 export HISTSIZE=-1 in your .bashrc to make your history forever. Not exactly what you're looking for, I know. For your favorite commands, I suggest to create aliases or functions, though.


1

My solution is a cron job and a big number of lines in .*sh_history file at the end of the day this cron entry runs (mine is set to 11 PM) 0 23 * * * cat /home/username/.bash_history >> /home/username/BIGHISTORY If the sticky command happens to get out of the regular history scroll buffer, I can find it in BIGHISTORY file with a simple grep command ...


3

This is typically done using the tcsendbreak C library routine. You can get to this from the shell by using a Python or Perl one-liner: python -c 'import termios; termios.tcsendbreak(3, 0)' 3>/dev/yourdevicename perl -e 'use POSIX; tcsendbreak(3, 0)' 3>/dev/yourdevicename


2

Uh, sure, just use export (works in any Bourne-style shell), or typeset -x, or a few other variants. To print specific variables, you can use typeset -p VAR1 VAR2 VAR3. These all print the values in a quoted form that can be re-read by zsh. If you want just VARIABLE=VALUE even if the value contains special characters, you can write a function: zprintenv () ...


1

Perhaps there isn't one because it would be non-POSIX. Further reading: getenv - Environment variable on Mac OS X and Linux Getting environment Variables as UTF-8 Strings in Linux Granted, zsh could implement an extension, but unless other applications can read the variables, they are of limited use. Shell variables and environment variables are ...


1

You misunderstand the meaning of subshell. A subshell is not a completely new process but a fork of the existing process. If you call zsh explicitly e.g. zsh -c 'echo "$$ $(date)" >> $HOME/.debug.zshenv' then the shell forks, calls execve() and by that starts a completely new shell which does the initialization again.


1

[ is a shell builtin command in bash and in zsh: $ type [ [ is a shell builtin From the Shell Builtin Commands documentation: Builtin commands are contained within the shell itself. When the name of a builtin command is used as the first word of a simple command (see Simple Commands), the shell executes the command directly, without invoking another ...


1

In both shells, bash and zsh, the [ utility is a shell builtin. This is the shells implementation of that tool, it is used in preference to the binary /usr/bin/[. The different results you encounter is caused by different implementations. In bash, the [ utility accepts CONDITIONAL EXPRESSIONS as the [[ compound command. According to bashs man page both = ...


16

It's not /usr/bin/[ in either of the shells. In Bash, you're using the built-in test/[ command, and similarly in zsh. The difference is that zsh also has an = expansion: =foo expands to the path to the foo executable. That means == is treated as trying to find a command called = in your PATH. Since that command doesn't exist, you get the error zsh: = not ...


2

And zsh, and bash give the same answer (type is builtin too for both shells): $ type -a [ [ is a shell builtin [ is /usr/bin/[


0

The arch wiki pages are a decent starting point for most of the confusing stuff here. You could start at: https://wiki.archlinux.org/index.php/xinitrc for example.


4

If you want to execute code whenever the value of a variable is read, you can't do that inside zsh itself. The RANDOM variable (like other similar special variables) is hard-coded in the zsh source code. You can however define similar special variables by writing a module in C. Many of the standard modules define special variables. You can use a coprocess ...


9

ksh93 has disciplines which are typically used for this kind of thing. With zsh, you could hijack the dynamic named directory feature: Define for instance: zsh_directory_name() { case $1 in (n) case $2 in (incr) reply=($((++incr))) esac esac } And then you can use ~[incr] to get an incremented $incr each time: $ echo ~[incr] ...


0

According to man zshzle you should be able to ctrl+n next history ctrl+p previous history man zshzle: down-history (unbound) (^N) (unbound) Move to the next event in the history list up-history (unbound) (^P) (unbound) Move to the previous event in the history list. Oh-my-zsh Also, not sure if you know already, but there is also ...



Top 50 recent answers are included