Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

2

Combine three parameter expansion features: ${…:#PATTERN} to filter elements that match PATTERN; (M) to keep matching elements (without this flag, the filter removes matching elements); ${#…} to count the resulting elements. if [[ -n ${(M)myarray:#-test.*} ]]; then echo "there are ${(M)#myarray:#-test.*} test flags" … And you can even combine this ...


1

I'm using a very simple workaround which may be useful if you want to debug only a specific function although the same idea can be applied to complete tracing with set -x: When I need to debug a specific function, say myfunc, I open a child shell with TRACE_FUNC=myfunc zsh -l 2> debug.err.txt while I have set in my ~/.zshrc something along the lines of: ...


1

you can define a "widget" with zle -N <name-of-new-widget> that triggers a function with the same new widget name that you define, which can run multiple zle commands that emulate vim's dd vim-dd() { zle kill-whole-line zle up-line } zle -N vim-dd bindkey -a dl vim-dd


2

This is left unspecified, so each shell is allowed to do what it wants, and doesn't have to document the details. (From a historical perspective, it was unspecified because different shells did different things.) Technically a shell would be allowed to flip a coin. In practice, the details of what runs in a separate environment and what doesn't can depend on ...


0

You could add the "compinit" references on the .zlogin instead of .zshrc, in my case the loading time improved a lot. I also have a test to recompile the compinit only once a day. autoload -Uz zrecompile autoload -Uz compinit dump=$ZSH_COMPDUMP # http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html if [[ -s $dump(#qN.mh+24) && (! -s ...


-1

This is to check all established connection from other user using SSH netstat | grep ssh


1

You could do: #! /bin/sh - src_file=/path/to/file { while read <&3 -r line; do case $line in ('#'*) ;; (*) if eval " $line" 3<&- 4>&-; then echo OK line="# $line" else echo FAIL fi esac printf '%s\n' "$line" >&4 done mv -- "$src_file.new" "$...


0

Using sed [command] file > file will, as you have discovered, not do what you want. The redirection wipes out the contents of file and replaces it with the output of sed. What you need to do is use sed's built-in ability to modify files in-place: sed --in-place "$COUNTs/^/#/" file


1

This could be a clash between git's own completion and oh-my-zsh's one. I found a working solution here: https://www.raphael-brugier.com/blog/fix-git-completion-zsh-mac-homebrew/ Depending on your environment, you might therefore want to disable git completion in your .zshrc: compdef -d git Also, upgrading your Zsh version seems to help, as this kind of ...


0

The answer about ${+name} variable expansion basically solves the problem. I just wanna add some info about the speed comparison to complete the topic. The reason why (($commands[tree])) style command is used is that, searching commands in an array is faster than command -v tree, which -a tree. ❯ export TIMEFMT=$'%U user %S system %P cpu %*E total' ❯ ...


1

It appears I was using the wrong commands. Either of these fix the issue: setopt nocorrect unsetopt correct


4

As of zsh 5.7, the answer is no. The trace output always goes to stderr. Source: reading the source. The trace output is written to the file xtrerr, which looks promising, but the only assignments to xtrerr are to stderr, to a copy of it, or to NULL. It should be possible to write a dynamically loadable module that sets xtrerr, but writing a module outside ...


3

The EXTENDED_GLOB options needs to be set for zsh. To see if it's been set, run setopt to display the options that have been set: $ setopt | grep glob extendedglob If it isn't set, run setopt extended_glob. NOTE: this will cause the ~, ^, and # to not be expanded on. The issue in my case was that, although I set this option in the shell, I was running ...


1

Found a solution here: https://blog.callstack.io/supercharge-your-terminal-with-zsh-8b369d689770 # Open new tabs in same directory if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then function chpwd { printf '\e]7;%s\a' "file://$HOSTNAME${PWD// /%20}" } chpwd fi Note that the only percent-encoding it does on the path is to replace spaces with "%20"....


Top 50 recent answers are included