Hot answers tagged

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 ...


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 ...


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] ...


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 ...


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 ...


3

The chsh command only lets you change your login shell from a shell that's listed in /etc/shells, to a shell that's listed in /etc/shells. This is a security and safety feature: if an account has a restricted shell (not listed in /etc/shells), they can't upgrade their access by switching to another shell; and a user can't lock themselves out by switching to ...


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

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


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 () ...


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 ...


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 ...


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 ...


2

I have this alias alias sudo='sudo 'defined in a file which I sourced at the end of ~/.zshrc file which overwrote alias sudo='nocorrect sudo' which is defined in .oh-my-zsh/lib/correction.zsh alias sudo='nocorrect sudo' is required by zsh's auto-completion feature to work More: How to disable autocorrection for sudo [command] in zsh? But at same time I ...


1

You need to use p flag to make other expansion flags (follow p) recognize the escape sequence: $ printf '%s\n' ${(ps:\0:)VAR} 5 0 7 or using the shorthand: printf '%s\n' ${(0)VAR}


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

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 ...


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

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


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} )) }


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 ...


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 = ...


1

Homebrew provides it's own completion. You just need to link the file $(brew --prefix)/Library/Contributions/brew_zsh_completion.zsh to _brew somewhere in your $fpath.(See comment at the start of https://github.com/Homebrew/homebrew/blob/master/Library/Contributions/brew_zsh_completion.zsh) zsh-completions recently removed its _brew completion in favour of ...



Only top voted, non community-wiki answers of a minimum length are eligible