zsh

Is there a way to switch Bash or zsh from Emacs mode to vi mode with a keystroke?

前提是你 提交于 2019-12-03 07:38:04
问题 I'd like to be able to switch temporarily from emacs mode to vi mode, since vi mode is sometimes better, but I'm usually half-way through typing something before I realize I want to use vi mode. I don't want to switch permanently to vi mode, because I normally prefer emacs mode on the command line, mostly because it's what I'm used to, and over the years many of the keystrokes have become second nature. (As an editor I generally use emacs in viper mode, so that I can use both vi and emacs

Customize zsh's prompt when displaying previous command exit code

旧城冷巷雨未停 提交于 2019-12-03 07:27:37
问题 Zsh includes the ability to display the return code/exit code of the previous command in the prompt by using the %? escape sequence. However I would like to have the following prompt: user@host ~ [%?] % when the exit code is different from 0 and: user@host ~ % when exit code is 0. If I use %? alone it is always displayed, even if %? is 0. In addition I want the square brackets but only when the exit code not 0. What is the simplest way to do this? 回答1: Add this in the position in PS1 where

Bower, Grunt & zsh: command not found:

a 夏天 提交于 2019-12-03 07:10:11
问题 I have installed Grunt & Bower & I'm using ZSH. when I type bower --help or grunt anything I get zsh: command not found: bower or zsh: command not found: grunt how can I fix this? 回答1: Add /usr/local/share/npm/bin/ to your $PATH environment 回答2: I couldn't get the above to work. Problem was that I had just reinstalled my Mac and forgotten to re-install grunt. You can test that grunt is actually installed and working properly outside of zshell by going back to bash with bash -l and running

Getting Emacs ansi-term and Zsh to play nicely

a 夏天 提交于 2019-12-03 07:08:09
问题 I've been trying to use Zsh within my emacs session, without emacs remapping all the Zsh keys. I found ansi-term works pretty well for this but, I'm still having some problems. I was getting lots of junk characters outputted with, I was able to fix it with: ## Setup proper term information for emacs ansi-term mode [[ $TERM == eterm-color ]] && export TERM=xterm But everything still doesn't work perfectly. Now I am having trouble with output being drawn offscreen , especially when using

Zsh `which rvm` or `which gem` returns the function contents instead of the path

假如想象 提交于 2019-12-03 07:02:25
I've never had this problem before with my other machines but for some reason in ZSH whenever I type which gem or which rvm I get the function contents: gem () { local result command gem "$@" result="$?" hash -r return $result } instead of it's path. For the life of me I can not figure out why this is happening. If I switch over to bash I do not have these problems. Gilles 'SO- stop being evil' This is normal behavior for zsh. The which built-in is equivalent to whence -c , which shows the definitions of functions. Use whence , possibly with a combination of options that does not include -f or

Anaconda not found in ZSh?

左心房为你撑大大i 提交于 2019-12-03 06:53:47
问题 I installed Anaconda via command line. The bash file. If Im in bash, I can open and use anaconda, like notebooks, ipython, etc. If I change my shell to ZSH, all the anaconda commands appear like "not found". How I can make it work in zsh? I use a Mac with OSx Sierra. Thanks in advance, 回答1: I had a similar issue. I checked in my .profile , .bashrc , and .bash_profile dot files in order to find any PATH information that I could copy over into my .zshrc file. Sure enough: # added by Miniconda3

Split string with zsh as in Python

折月煮酒 提交于 2019-12-03 06:40:41
问题 In python: s = '1::3' a = s.split(':') print a[0] # '1' good print a[1] # '' good print a[2] # '3' good How can I achieve the same effect with zsh ? The following attempt fails: string="1::3" a=(${(s/:/)string}) echo $a[1] # 1 echo $a[2] # 3 ?? I want an empty string, as in Python 回答1: The solution is to use the @ modifier, as indicated in the zsh docs: string="1::3" a=("${(@s/:/)string}") # @ modifier By the way, if one has the choice of the delimiter, it's much easier and less error prone

Is it necessary to specify traps other than EXIT?

牧云@^-^@ 提交于 2019-12-03 06:36:17
问题 I see a lot of shell scripts that do: trap cmd 0 1 2 3 13 15 # EXIT HUP INT QUIT PIPE TERM In every shell I have access to at the moment, all the traps other than 0 are redundant, and cmd will be executed upon receipt of a signal if the trap is simply specified: trap cmd 0 Is the latter specification sufficient, or do some shells require the other signals to be specified? 回答1: I think trap 0 is executed just prior to script termination in all cases, so is useful for cleanup functionality

what is ~/.npm dir for?

匆匆过客 提交于 2019-12-03 06:34:12
问题 I have installed the global npm package jslint and it lives here $ ls -la /usr/local/bin/jslint lrwxr-xr-x 1 lust admin 40 Feb 12 15:31 /usr/local/bin/jslint -> ../lib/node_modules/jslint/bin/jslint.js $ ls -la /usr/local/lib/node_modules/jslint/bin total 8 drwxr-xr-x 3 lust staff 102 Apr 16 2012 . drwxr-xr-x 10 lust staff 340 Feb 12 15:31 .. -rwxr-xr-x 1 lust staff 2330 Apr 16 2012 jslint.js $ which jslint /usr/local/bin/jslint $ head -3 /usr/local/bin/jslint #!/usr/bin/env node var linter =

alias with parameters

倖福魔咒の 提交于 2019-12-03 05:52:13
If there is any possibility to use the parameters in zsh aliases? Something like this: alias ssh_nokia="ssh root@<ip_parameter>" Usage: ssh_nokia 192.168.1.2 Michael Krelin - hacker In your particular case edit ~/.ssh/config (See Dave's answer below), or use: alias ssh_nokia='ssh -l root' Generally ssh_nokia() { ssh root@"$@" } is equivalent to alias (will produce ssh root@1stparam 2ndparam 3rdparam … ). I would use up ~/.ssh/config to create an alias for a particular connection, like so: Host=anyoldname Hostname=[hostname or ip address] User=root Then you can: $ ssh anyoldname More info: $