zsh

oh-my-zsh使用篇

天涯浪子 提交于 2019-12-04 17:57:49
什么是Bash? https://www.gnu.org/software/bash/manual/bash.html#What-is-Bash_003f Bash是GNU操作系统的shell或命令语言解释器。这个名字是’Bourne-Again SHell’的缩写,是Stephen Bourne的双关语,他是当前Unix shell sh的直接祖先的作者,出现在第七版贝尔实验室研究版的Unix中。 Bash在很大程度上与sh兼容,并结合了Korn shell ksh和C shell csh的有用功能。它旨在成为IEEE POSIX规范(IEEE标准1003.1)的IEEE POSIX Shell和Tools部分的一致实现。它为交互式和编程使用提供了超过sh的功能改进。 虽然GNU操作系统提供其他shell,包括csh版本,但Bash是默认shell。像其他GNU软件一样,Bash非常便携。它目前几乎运行在每个版本的Unix和一些其他操作系统上 - 为MS-DOS,OS / 2和Windows平台提供独立支持的端口。 什么是Shell? 在它的基础上,shell只是一个执行命令的宏处理器。术语宏处理器意味着扩展文本和符号以创建更大表达式的功能。 Unix shell既是命令解释器又是编程语言。作为命令解释器,shell为丰富的GNU实用程序提供了用户接口

Why zsh tries to expand * and bash does not?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:48:04
问题 I just encountered the following error with zsh when trying to use logcat. Namely, when typing: adb logcat *:D I get the following error in zsh zsh: no matches found: *:D I have to escape the * like : adb logcat \*:D While using bash, I do not get the following error. Why would it be like this? 回答1: zsh warns you by default if you use a glob with no matches. Bash, on the other hand, passes the unexpanded glob to the app, which is a potential problem if you don't know for certain what will

Zsh color partial tab completions

左心房为你撑大大i 提交于 2019-12-04 17:23:29
问题 Is it possible to color the completed part of the partial completion results in Zsh? Fish does this by default (in Gentoo at least) as shown in the image below: Full size image: http://i.imgur.com/tN6w3.png 回答1: Yes, you can do it with things like that: zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==02=01}:${(s.:.)LS_COLORS}")' Just change the 01 and 02 colors so it matches your taste, for example to match your screenshot: zstyle -e ':completion:*

Completion when program has sub-commands

[亡魂溺海] 提交于 2019-12-04 16:20:20
问题 I have written a command-line tool that uses sub-commands much like Mercurial, Git, Subversion &c., in that its general usage is: >myapp [OPTS] SUBCOMMAND [SUBCOMMAND-OPTS] [ARGS] E.g. >myapp --verbose speak --voice=samantha --quickly "hello there" I'm now in the process of building Zsh completion for it but have quickly found out that it is a very complex beast. I have had a look at the _hg and _git completions but they are very complex and different in approach (I struggle to understand

How to pipe data to interactive bash script and pipe output to another command?

早过忘川 提交于 2019-12-04 12:49:48
I'd like to pipe data into an interactive command, and have the output of the interactive command be received as input to another command. For example, I'd like to be able to do something like the following: echo "Zaphod" | hello.sh | goodbye.sh and have the output be: BYE HELLO Zaphod Here's my initial crack at this, but I'm missing something ;-) I'd actually like the hello.sh to select from a list of things. hello.sh echo Please supply your name read NAME echo "HELLO $NAME" goodbye.sh MSG=$* if [ -z "$1" ] then MSG=$(cat /dev/stdin) fi echo "BYE $MSG" EDIT: By "select from a list of things",

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

谁都会走 提交于 2019-12-04 12:15:47
问题 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. 回答1: This is normal behavior for zsh. The which built-in is equivalent to whence -c , which shows the definitions of functions.

最强Linux shell工具Oh My Zsh 指南

馋奶兔 提交于 2019-12-04 11:09:57
引言 笔者已经使用zsh一年多了,发现这个东东的功能太强大了。接下来,给大家推荐一下。 以下是oh-my-zsh部分功能 命令验证 在所有正在运行的shell中共享命令历史记录 拼写纠正 主题提示(Agnoster,RobbyRussell,......) 目录历史 通过zshenv,zprofile,zshrc,zlogin和zlogout启动/关闭脚本 强大的自动完成功能。您可以使用TAB键浏览不同的选项,然后使用enter键选择正确的文件夹。例如Bash会打印所有选项。 添加插件:例如Git插件包含大量有用的Git别名。 此插件显示活动分支并提供有关Git状态的可视反馈: 绿色:如果没有发生变化的分支 黄色:未跟踪文件 带有加号图标的黄色:准备提交的文件 安装指南 我在我的Linux Mint上执行此安装指南。为了向您展示Oh-My-Zsh的基本功能,我将安装Git插件(Git-core)。此插件提供有关项目的Git状态的可视反馈。 安装必备软件包 $ sudo apt install git-core zsh 根据官方脚本安装Oh-My-Zsh # 通过curl sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

alias with parameters

淺唱寂寞╮ 提交于 2019-12-04 10:05:41
问题 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 回答1: 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 … ). 回答2: I would use up ~/.ssh/config to create an alias for a particular connection, like so: Host=anyoldname

Arrow keys no longer work in Python shell after upgrading Mac OS to Sierra

送分小仙女□ 提交于 2019-12-04 08:55:27
问题 I'm using zsh, iTerm2 (3.0.9), and pyenv (1.0.2) with pyenv global set to 3.5.2. In the Python shell, the up and down arrow keys used to work, to access the previous commands in the history. But now after upgrading to OSX 10.12, instead it shows control characters. For example up arrow displays: ^[[A I've tried installing readline as suggested in Seeing escape characters when pressing the arrow keys in python shell but that didn't help. I don't have the PYTHONSTARTUP variable but didn't used

Zsh: read lines from file into array

纵饮孤独 提交于 2019-12-04 07:51:46
I'm trying to read in a file as an array of lines and then iterate over it zsh, and the code I've got works most of the time, except if the input file contains certain characters (such as brackets). Here's a snippet of it: #!/bin/zsh LIST=$(cat /path/to/some/file.txt) SIZE=${${(f)LIST}[(I)${${(f)LIST}[-1]}]} POS=${${(f)LIST}[(I)${${(f)LIST}[-1]}]} while [[ $POS -le $SIZE ]] ; do ITEM=${${(f)LIST}[$POS]} # Do stuff ((POS=POS+1)) done What would be an easier way of doing this? I also need to count the number of lines in the file. #!/bin/zsh zmodload zsh/mapfile FNAME=/path/to/some/file.txt