Tag Info

New answers tagged

1

Zsh on RHEL 7 behaves the same a way, i.e. during ssh logout the terminal is cleared. (Depending on the terminal the last terminal output is lost, or it is just scrolled out of view.) This is because of /etc/zlogout - which is part of the zsh package - is containing: clear (it does not contain other commands) You can override this clearing in your own ...


0

To extend mrb answer: Indeed ^[b is ESC+b or (Meta/Alt+b). You can display character literally by proceeding it with Ctrl+v. In this case you will find the following: Ctrl+v Ctrl+b ^B Ctrl+v Meta+b ^[b Ctrl+v ESC b ^[b Additionally you will find in zsh manual: backward-word (ESC-B ESC-b) (unbound) (unbound) Move to the beginning of the previous ...


1

The ^ notation is commonly used in the GNU world for control characters, where ^a is Ctrl-A (ASCII 1 where A is ASCII 65). In other words it is shorthand for "use the character 64 slots before this on". The ESC key is ASCII 27 which is 64 steps before [, hence ^[ is shorthand for ESC. In the GNU Emacs editor several modifier keys were used, CTRL, META ...


1

^ is usually control, but ^[ actually means Escape or Alt (or meta, if you like emacs). So you can press Escb or Escf for those key combinations. By default, Alt doesn't work on Mac terminals, but iTerm2 has a setting: "Option acts as [ ] Normal [ ] Meta [ ] +Esc". You want +Esc.


2

Actually ^[ is the Alt key. So in your case the terminal (Iterm2) uses Alt + b and Alt + f to go backwards and forwards a word. This is controled by your terminal and has nothing to do with zsh.


0

Go to a machine that has internet access and/or git, download the complete repository or copy the .oh-my-zsh/ directory, then after doing a backup, replace the ~/.zshrc file with the one from the templates: cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc And (re)start your zsh.


0

As regards variables, I have the impression that you are missing modules & modulefiles [1]. Once you start doing so, it will be easy to create common profiles for various shells (incl. bash & zsh), python, perl and even more environments, all from the convenience of a single module file. It is also possible to define aliases in the same way; ...


7

Different, documented behavior in zshmisc A list is a sequence of zero or more sublists, in which each sublist is terminated by ;, &, &|, &!, or a newline. This terminator may optionally be omitted from the last sublist in the list when the list appears as a complex command inside (...) or {...}. When a sublist is terminated ...


3

Buried in zshmisc(1) is the following line: If a sublist is terminated by a &',&|', or `&!', the shell executes the last pipeline in it in the background, While it doesn't specifically state that the other pipelines in the sublist are executed in the current shell, that does seem to be what it is implying, and the behavior you ...


1

If you don't want any of oh-my-zsh's aliases, but you want to keep other aliases, you can save the aliases before loading oh-my-zsh save_aliases=$(alias -L) and restore them afterwards. eval $save_aliases; unset $save_aliases If you want to remove all aliases at some point, you can use unalias -m '*' (remove all aliases matching *, i.e. all of them). ...


1

This kind of behavior is configured through styles (except for a few fundamentals that have options). You'll want to turn off path-completion. By default, filename completion examines all components of a path to see if there are completions of that component. For example, /u/b/z can be completed to /usr/bin/zsh. Explicitly setting this style to false ...


3

You can use unalias with -m option: unalias -m '*' to delete all defined aliases


0

Zsh -f makes the problem go away. I parsed the .zshrc file, and found it to be a setting that I'd kept in the process of moving to Arch - "export TERM=uxterm". Removed this line, and the problem was gone. Thank you for your help!


1

To retain the / added after completing directories or symbolic links to directories, turn off the option auto_remove_slash which is on by default. setopt no_auto_remove_slash For many commands, retaining the trailing slash makes no difference for directories, but causes the command to act on the target directory instead of the symbolic link if the ...


3

As I understand it you're looking for the value of "Foo". This is really easy to do with the shell command-line tool jq. It is something like sed in that it implements its own kind of parser language. Given your example: json=' { "Reservations" : { "OwnerId" : "1345345", "Groups" : [], "SecurityGroups" : [ ...


2

This is an answer to your objective, but not your question. Meaning you can accomplish your goal without using a JSON parser. The AWS cli util has the ability to only output select fields using the --query argument. This is documented here. For example: $ aws ec2 describe-instances \ --query 'Reservations[0].Instances[0].SecurityGroups[0].GroupName' \ ...


2

Replace the last line of your script with echo ${(kv)opts}. Running with 4.3.6 and 5.0.6 should show that 4.3.6 interprets -K to reset opts if any options are given, while 5.0.6 only resets opts[--opt1] when --opt1 is used (leaving --opt2 or any other entry alone). (Note this appeared to change sometime between 5.0.2 and 5.0.6; you might want to ask on the ...


3

I think you are looking for :- parameter substitution: $ restofarglist='abc,def' $ echo ${(s/,/)${:-arg1,arg2,$restofarglist}} arg1 arg2 abc def From man zsh: ${name:-word} If name is set, or in the second form is non-null, then substitute its value; otherwise substitute word. In the second form name may be omitted, in which ...


5

I'll stick to scripting features. Rich interactive features (command line edition, completion, prompts, etc.) tend to be very different, achieving similar effects in wholly incompatible ways. What features are in zsh and missing from bash, or vice versa? gives a few pointers on interactive use. The closest thing to bash would be ATT ksh93 or mksh (the Korn ...


3

This question is rather too broad. Both mksh and zsh are shells that support a lot of GNU bash-specific extensions, but there are always some that are not understood. zsh supports more stuff, but only in its native zsh mode, which is not compatible with POSIX shells (such as GNU bash, AT&T ksh93, mksh). Also, mksh is much leaner and faster and more ...


1

ZSH Comparison of Shells In recent years there has been a certain amount of crossover in the extensions, however. Zsh (as of 3.1.6) has bash's ${var/old/new}' feature for replacing the text old with the text new in the parameter $var. Note one difference here: while both shells implement the syntax${var/#old/new}' and ${var/%old/new}' for anchoring the ...


1

You can also try alias -g LL='|& less' |& is a shorthand for 2>&1 |, so basically both versions should work. Perhaps you have aliased earlier less itself and now this command means something different?


1

Try: alias -g LL='2>&1 | less' You had an space in alias assignment, causing the alias failed.


0

When you ran zsh -v, this started a new instance of zsh. You aren't seeing your previous history because you're now interacting with a different process. Type Ctrl+D or run the command exit to exit this instance and go back to the parent instance. You can use the set builtin to turn options on and off: set +v turns off the verbose option, set -v turns it ...


2

In an escape sequence like ^[[31m, the escape character ^[ is non-printing, but the other characters [31m are printing characters. So sort -i won't help you: it ignores the escape characters but still sorts [31mred[0m before [32mgreen[0m. A generic way to sort data according to criteria that go beyond the built-in abilities of the sort utility is to double ...


3

-k option of sort takes two numerical arguments: field and character. You want to sort on 6th character of first field. It is 6th character because %F{green} is replaced by ESC[32m. So this should work: print -lP "%F{green}"${^$(setopt)} "%F{red}"${^$(unsetopt)} | sort -k 1.6


5

You can install and use my dirhistory utility for bash. Basically, it's a daemon that collects directory changes from all your shells, and a Cdk program that displays the history and lets you pick any directory to switch to (so you're not limited to a stack).


15

You didn't specify which shell you are using, so let this be excuse to advertise zsh. Yes, we do have more history for cd, namely cd -2, cd -4 etc. Very convenient is cd -TAB, especially with completion system and colors enabled: This is what I have in .zshrc: setopt AUTO_PUSHD setopt PUSHD_MINUS setopt CDABLE_VARS zstyle ':completion:*:directory-stack' ...


8

To answer your question regarding "more history". No the cd - feature in Bash only supports a single directory that you can "flip" back to. As @Ramesh states in his answer. If you want a longer history of directories you can use pushd and popd to save a directory or return to a previous one. You can also see the list of what's currently in the stack with ...


19

The command you are looking for is pushd and popd. You could view a practical working example of pushd and popd from here. mkdir /tmp/dir1 mkdir /tmp/dir2 mkdir /tmp/dir3 mkdir /tmp/dir4 cd /tmp/dir1 pushd . cd /tmp/dir2 pushd . cd /tmp/dir3 pushd . cd /tmp/dir4 pushd . dirs /tmp/dir4 /tmp/dir4 /tmp/dir3 /tmp/dir2 /tmp/dir1


2

You saved the files being sourced with DOS line endings (CRLF). Your editor automatically recognizes this and doesn't show the ^M characters, but they're still there. (It probably has some other indicator that the file uses DOS line endings.) You need to remove the CR characters. One way is this: perl -pi -e 's/\r//' /home/rob1nn/.r_inc/*


4

There are two principal ways: Parameter expansion by enabling PROMPT_SUBST The psvar array 1. Parameter expansion in prompt If PROMPT_SUBST is enabled setopt PROMPT_SUBST the prompt is subjected to parameter expansion, command substitution and arithmetic expansion before it is evaluated. That way, the output of a script can be included via command ...


1

On my Centos system MAKE failed with error no ncurses (even though I already had ncurses) the following solution allowed me to upgrade/make zsh from 4.2.6 to 5.0.2 yum install ncurses-devel


2

You can do this by setting up a precmd hook which will take the output of the command and format it as you want, and then make it available to your PROMPT. Minimally, you need: autoload -U add-zsh-hook add-zsh-hook precmd my_precmd_hook_function Define my_precmd_hook_function to call your python script and capture its output in a variable. You can then ...


0

I wouldn't recommend it, but you could use this one-liner: echo 'project' | xargs -I % sh -c 'git clone https://github.com/username/%.git && cd %'


0

The problem was that the version of zsh was 4.3.6. According to the release notes, the %F color expansion feature of the prompt was not added until 5.0 (though the release notes aren't 100% clear here-- in any case, %F doesn't show up in the 4.3.6 zshmisc manpage, which contains the prompt expansion documentation). Confusingly, the %F is still removed from ...


1

You've made grep an alias for grep $GREP_OPTIONS. Don't do that: the GNU grep command itself parses the GREP_OPTIONS environment variable. If you want to put options to a command in a variable, make that variable an array, and don't export it (you can't export arrays anyway, environment variables have string values only). LS_OPTIONS=(--color=auto -q) alias ...


0

The issue is my $LESS contains -X. Plus -+X will set less to it's default behavior, which is whatever is specified in $LESS, NOT no -X. Thus I was running less with -X all the time. That's why neither cleaned the screen.


1

chsh is the program for configuring your login shell. chsh -l will list the available login shells. It's best to keep an existing shell session open when modifying your login configuration so as to prevent inadvertently locking yourself out! I'm not familiar enough with zsh to tell you what elements of your .bashrc might be problematic to copy over.



Top 50 recent answers are included