Tag Info

Hot answers tagged

6

Alias substitution is only performed when reading lines from interactive sources. So the second alias is not affected by the first, hence the literal replacement. Perhaps something similar: PACMAN=pacman if [ -f /usr/bin/pacmatic ]; then PACMAN=pacmatic fi # Colorized Pacman output alias pacman="${PACMAN} --color auto" This'll set 'pacman' to the ...


5

The zsh/parameter module, which is part of the default distribution, provides an associative array options that indicates which options are on. if [[ $options[extended_glob] = on ]]; then … For options that have a single-letter alias (which is not the case of extended_glob), you can also check $-. Note that it's rarely useful to test which options are ...


3

In zsh, you can use setopt to show options enabled and unsetopt to show which are not enabled: $ setopt autocd histignorealldups interactive monitor sharehistory shinstdin zle $ unsetopt noaliases allexport noalwayslastprompt alwaystoend noappendhistory autocd autocontinue noautolist noautomenu autonamedirs ..... In bash, you can use shopt -p.


3

.oh-my-zsh isn't used by anything but oh-my-zsh. If you use bash, you can just remove it. The instructions tell you to run the command uninstall_oh_my_zsh. This is a function that you can invoke from zsh running oh-my-zsh. If you aren't running oh-my-zsh, you can run tools/uninstall.sh, but all it does is: remove ~/.oh-my-zsh, which you were going to do ...


3

There are ksh specific commands/options/shortcuts/features that won't work or work differently with zsh, and there are even more zsh specific things that would fail under ksh. If your goal is to write scripts, my advice would be to stick to POSIX features shared by both shells. zsh might miss some POSIX ones as compliance is not in its design objectives. ...


3

How about using brace expansions? $ ls -ld /{,usr/{,bin/{,tee}}} drwxr-xr-x 23 root root 4096 Mar 7 06:57 / drwxr-xr-x 10 root root 4096 Jan 9 2013 /usr/ drwxr-xr-x 2 root root 40960 Apr 9 23:57 /usr/bin/ -rwxr-xr-x 1 root root 26176 Nov 19 2012 /usr/bin/tee


3

ls -ld `echo 'path/to/file' | sed ':0 p;s!/[^/]*$!!;t0' | sort -u` sed part: :0 label 0; p print; s!p!r! replace pattern p with replacement r; /[^/]*$ search for /, then any sequence of not-/ till the end of line; replacement is empty, so just delete the match; t0 if s!!! performs a replacement, then go to label 0. Edit by OP after comments I did the ...


3

A shell alias behaves pretty similarly to a #define, i.e. redefining a shell alias would override the previous one. I'm not sure what would be the Right WayTM, but one approach would be making use a shell function that accepts parameters and using that to create an alias. Your code snippet could be rewritten as: if [ -f /usr/bin/pacmatic ]; then ...


2

Just use: [[ -o extended_glob ]] That also works in bash, but only for the options set by set -o, not those set by shopt. zsh has only one set of options which can be set with either setopt or set -o. Just like with bash (or any POSIX shell), you can also do set -o or set +o to see the current option settings.


2

I can't think of any expansion trick or utility to do it all in one go. So a loop is the way to go. Here's some code that works under both bash and zsh, and accommodates directories with arbitrary names. ## Usage: set_directory_chain VAR FILENAME ## Set VAR to the chain of directories leading to FILENAME ## e.g. set_directory_chain a /usr/bin/env is ...


1

su executes your login shell as indicated in the login database. This is /root/zsh, which doesn't exist, so the command su fails. chsh only accepts changing the shell of a user who currently has a valid shell (listed in /etc/shells). Since /root/zsh is not accepted, chsh fails. The root user can change anyone's shell, but this test is made after the ...


1

In zsh, you can easily append to an alias by using the aliases associative array: alias pacman="${aliases[pacman]-pacman} --color auto" In other shells, you need to use the output of the alias command to find out about existing aliases. current_pacman_alias=$(alias pacman 2>/dev/null) alias pacman="${current_pacman_alias:-pacman} --color auto" While ...


1

I see at least one thing missing: you're passing CFLAGS=-I/path/to/installation/include, which lets the compilation scripts find the header files, but you also need to let the compilation scripts find the library to link against (libncurses.a). Also the installation instructions say to use CPPFLAGS for the include directories, not CFLAGS. export ...


1

These speeds are a configuration setting for serial lines and are irrelevant for any terminal that isn't connected through a serial line, such as terminal multiplexer software, remote terminals, GUI terminal emulator, or any other kind of software terminal. Because serial lines were once the norm for terminals, the speed is a parameter in the terminal ...


1

In the standard vicmd mode R is already bound to vi-replace-chars. So when you define R+R to redo with bindkey -a rr redo you have two possible actions Zsh could follow when R is pressed interpret it as the command vi-replace-chars or wait for a second character and then interpret the command redo The algorithm for matching keyboard commands in Zsh ...


1

This could be a consequence of running some code that clobbers the variable FPATH or fpath. Check the value of either of these variables; it should be a list of directories where zsh loads functions. The variables FPATH and fpath are tied (like PATH and path): changing one affects the other. The uppercase FPATH is a string which contains a colon-separated ...


1

showkey has no switch for that, but you can always pipe the output to another program to do the conversion. With zsh you can do it like this: stdbuf -oL showkey -s | while read line do if [[ "$line" =~ '^0x' ]] then for code in ${(z)line} do printf "0%o " $code done echo else echo $line fi done stdbuf is part of the GNU ...



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