Hot answers tagged

10

Try doing unsetopt equals and try again. Or put quotes on the first equals character. If you use [ for conditions, all arguments are evaluated normally and = at the start of a word is a useful zsh shorthand to get the location of a command. e.g. =ls expands to /bin/ls. Given == zsh looks for an = command and doesn't find one. Zsh in posix mode (sh ...


9

In zsh, by default all the widgets that operate on words including the transpose-words one bound by default to Alt+T in emacs mode work on words that are defined as sequences of alnum+$WORDCHARS characters. The default value of $WORDCHARS has *?_-.[]~=/&;!#$%^(){}<>, so includes /, so should be fine for you to transpose paths as long as those ...


7

Sourcing an rc file rarely if ever works in practice, because people rarely write them to be idempotent. A case in point is your own, where you are prepending the same directory to the fpath path every time, which of course means that searching that path takes a little longer each time. No doubt this isn't the only place where you are doing that sort of ...


5

While autoload marks a name for autoloading on first reference in zsh, it doesn't redefine any existing function with the same name should it already be defined, since the name has already been referenced once it was defined. in order to achieve what you desire, you would have to undefine the function first before sourcing .zshrc again or for something more ...


4

The time keyword in zsh produces output in the format specified by the variable TIMEFMT. The default value of this variable is %J %U user %S system %P cpu %*E total You can change this like this, for example: TIMEFMT=$'%J\n%U user\n%S system\n%P cpu\n%*E total' (this really just inserts a few newline characters into the default format string) Which ...


4

It sounds like you're asking zsh to interpret that script. You don't say what updateExpediaGitRepos is, but I suppose that alias sources that script, using the . or source builtin command. Those are the commands to tell the current shell interpreter to interpret code in a file, so the shebang (#! /bin/bash) is not relevant. The shebang is only used by the ...


3

The behavior is because of how arrays work in zsh shell, their indices start at 1 and not at 0. So any access to elements at index 0 will throw the error you are seeing. From the zsh manual - 15.2.1 Array Subscripts 15.2.1 Array Subscripts Individual elements of an array may be selected using a subscript. A subscript of the form [exp] selects the ...


3

Why your code doesn't work The wildcard pattern *.avi is expanded by the shell that runs find before running find, so its effect depends on whether there are *.avi files in the current directory or not. See find not recursive when file at top for more explanations. To expand *.avi in subdirectories, you'd need to do three things differently: quote the ...


3

I did realize that zsh's vim mode is a bit more advanced than I realized before. There is an a text object which corresponds to argument. So I would be able to take advantage of some muscle memory by typing a sequence such as EscdaaBPiSpace. But you can see also that 8 keystrokes is far from ideal. Given that this operation requires plugins to achieve ...


3

If you don't have the EXTENDED_HISTORY shell option set in zsh, then the history events that are saved to $HISTFILE will be saved without timestamps. When you use history -E 1, the history events are printed from the start of the in-memory history to the end, with timestamps (formatted in a particular way). History entries that were read from $HISTFILE don'...


2

So far no answer nor comment explicitly stated what chsh really does. You seem to think chsh changes the current shell. No. It only changes some record that tells the OS what shell is your login shell. The record counts when your login shell is about to be started. The current shell (or any other already started shell) stays unaffected: it does not morph ...


2

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work. The better ...


2

Session names cannot contain either . or :. You can create window names with them but you won't be able to use them in targets so I don't recommend it. You can still target the window using the window index (eg :3) or window ID (eg @2).


2

zcompile is a zsh shell builtin only available from within the shell, find is a separate command from the shell so that can't work. zsh globs can easily replace find here: set -o extendedglob # for ^, best in ~/.zshrc for file (./**/^*.zwc(N.)) zcompile $file (here omitting hidden files and files in hidden dirs which is probably preferable; if not add the ...


2

To cancel what you're calling "selection mode" from a zsh zle widget, it is: zle set-mark-command -n -1 or if you prefer: REGION_ACTIVE=0 What zsh supports comes in mostly emacs and vim compatible forms. Text between the mark ($MARK) and cursor ($CURSOR) is highlighted. Documentation also talks about the region (emacs) or visual mode (vim). The typical ...


2

Assuming that rename 's/[^A-Za-z0-9.-]/_/g' -- *.avi would properly rename all the files with a .avi filename suffix in the current directory, you would be able to apply this to all directories beneath the current one (including the current one) with find . -type d -exec sh -c ' for dirpath do ( cd "$dirpath" && rename "s/[^A-Za-z0-9.-]...


2

time does not time commands. From the Single Unix Specification's rationale: The term utility is used, rather than command, to highlight the fact that shell compound commands, pipelines, special built-ins, and so on, cannot be used directly. The SUS also states that the result of time on special built-in commands is undefined, and its results when used on ...


1

There is a pretty simple way to achieve this. I don't know oh-my-zsh, but I know this issue. It's as simple as including zstyle '*' single-ignored complete somewhere in your shell config, preferably after your oh-my-zsh config gets loded. Hope this helps!


1

The solution was to actually add the following line to .tmux.conf set-option -g default-shell /bin/zsh What's dumb is I definitely knew that and actually did add the line, but I seem to have either not saved the file or not restarted the server after doing so. Everything started working just fine when I connected the next day.


1

If you want to count the number of non-hidden files that have a .json extensions in the current directory, you'd do: (){echo $#} *.json(NoN) (N for nullglob, oN to disable sorting which we don't need here). ls -l | grep .json | wc -l is wrong for a number of reasons: . is a regexp operator that match any single character. If you wanted to search for the ....


1

Your original command might fail if the expanded list of files is too long, since it relies on the shell to expand the list of files. ls -l | grep .json | wc -l Is OK because the command line is short (no expansion) and the grep does the filtering line by line instead. Note that the dot matches any character, not just a dot. Use -F to indicate fixed ...


1

In Bash, press Ctrl-X Ctrl-E to open the currently entered command line in your $EDITOR. Edit it as you like, then save and quit to execute it. For instance, if your default editor is Vim, <C-x><C-e>f dE$p:wq will transform your initial command line into your desired command line and execute it. Of course, if you have a plugin like sideways.vim, ...


1

Terminals do not work this way. Terminals do not send modifier keys. Modifiers are swallowed by the terminal and do not get sent down the wire to the host. Terminal input is in terms of character sequences not keyboard events. (Yes, a few real terminals such as the DEC VT520 supported "scancode" modes, but that would break beyond repair what you are ...


1

As kaylum pointed out, you are still in the same user environment. To refresh it you should log out & log in again or, if you prefer, use su command to re-login without losing your current session: su - $USER Your echo $0 will work properly then. after you exit this session with exit you'll be again in the former one.


1

Something like: autoload -U zmv mkdir-and-mv() { mkdir -p -- "$2:h" && mv -- "$@" } typeset -A c c=( blue colors red colors apple fruits banana fruits ) zmv -n -P mkdir-and-mv "(**/)((${(j:|:)${(@bk)c}}).txt)" '$1$c[$3]/$2' (remove the -n for dry-run if happy)


1

Thanks to /u/OneTurnMore, one possible way of roughly doing this is: [~] % hash -d _=$HOME/.config [~] % ~_ [~_] % pwd /home/me/.config hash -d _=$XDG_CONFIG_HOME works but does not change the prompt.


1

The following works zstyle ':vcs_info:*:*:martin' formats "%0.0r" In this case the %0.0r specifier says to use the repository name but display it as 0 width string. See the zsh zformat utility as this is what formats uses.


1

$ ls -li /bin/zsh /usr/bin/zsh 19401918 -rwxr-xr-x 1 root root 861568 Feb 4 2019 /bin/zsh 19401918 -rwxr-xr-x 1 root root 861568 Feb 4 2019 /usr/bin/zsh Matching i-nodes means they are hard-linked.


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