New answers tagged

0

You need to also add setopt nocaseglob to your ~/.zshrc. The files for any git completion are generated by calling git ls-files with a glob pattern, which is case-sensitive by default. Unsetting caseglob will cause them to be insensitive to case instead.


1

Use a loop, starting at $PWD and stripping off one directory level at a time. You just need to be careful about ending at /. Also count the lines (or pipe through nl). Here's a function that works both in bash and in zsh. function pwd_and_parents { local d n d=$PWD n=0 while [[ $d = *[!/]* ]]; do printf '%d %s\n' "$n" "$d" ...


1

width_part='$((${COLUMNS:-80} * PROMPT_PERCENT_OF_LINE / 100))' PS1="%F{013}%$width_part<<\${(l[$width_part][.])}%~%F{012}\${__git_ps1_foo}%F{011}%(1j.jobs%j.)%(?.%F{004}.%F{001}✕%?)%<<%# %f" That as is, we still do truncation with %<width><<truncated-part%<<, though with an empty substitution string (the ... is gone) ...


1

Something like this would fill the prompt to an appropriate number of dots, using your myPromptWidth function: width="$(myPromptWidth)" print -v dots -f '%*s' $width . dots=${dots// /.} PS1="%$width<...<$dots %/%% " The resulting prompt is like: ......................./tmp% dots needs to contain a sufficient number of dots, the ...


0

Create a file named _ipadd and put the following in it: #compdef ipadd # The line above declares this function as providing completions to # `ipadd`. In addition, it's important that the file name starts with # an `_`, otherwise `compinit` won't autoload it. local output=$(networksetup -listallnetworkservices) # Split the output on newlines. local -a ...


0

Instead of creating scripts, consider creating functions (and converting existing scripts into functions). That way, you'll never have to worry about permissions again. Scripts are easily converted to functions: Remove the .sh extension from the file name. (Technically optional, but that's the convention.) Make sure the file's parent dir is in your $fpath. ...


1

It depends, sometimes they do like Devon explained above, but if they don't have anything to do with each other then no they don't matter. For example if you define a bunch of aliases that aren't being used in your .zshrc or don't depend on anything in your .zshrc then you can put them anywhere you want. If they provide some kind of output to terminal then ...


1

zsh runs the commands in you .zshrc as if you typed them in your terminal. The order does matter, e.g. you cannot use variables before you defined them.


0

I was able to fix it linking the file from node_modules/tldr/bin/completion/zsh/_tldr to the plugins folder. ln -s your_path_node_modules/node_modules/tldr/bin/completion/zsh/_tldr $ZSH_CUSTOM/plugins/tldr/_tldr if you have already defined the path you could use -sf or delete the previous link and copy this file.


0

As per the documentation: HIST_IGNORE_DUPS (-h) Do not enter command lines into the history list if they are duplicates of the previous event. Note that it's "the" previous event and not "any" previous event. If you want to ignore all dups, you will need to set… drum roll You guessed it: HIST_IGNORE_ALL_DUPS From the documentation ...


0

This answer was initially an edit of @cdmo's answer (thanks to @Milkncookiez's comment also!), that got rejected as expected, so here it goes: #!/usr/bin/env bash while [ $# -gt 0 ]; do case "$1" in -p|-p_out|--p_out) p_out="$2" ;; -a|-arg_1|--arg_1) arg_1="$2" ;; *) printf "*****...


0

GNU awk aka gawk+paste: $ < myfile check_this \ | paste myfile - \ | gawk '/YES$/ && NF--'; $ < myfile check_this \ | perl -lpe ' @ARGV && do{ /YES/ && $h{$.}++; eof && close(ARGV); next; }; print if $h{$.}; ' - myfile GNU sed with extended regex mode ON: $ ...


0

We can make use of the GNU version of the dc utility to basically implement a grep -f functionality. dc -e " $(< myfile check_this | sed -e 's/NO/0/;s/YES/1/' | tac) [q]sq [p]sp [?z0=qr1=psxz0<?]s? l?x " < <(< myfile sed -e 's/.*/[&]/') As a first step we load the check_this utility's output, booleanized appropriately (YES=>1,...


0

A variant of @StéphaneChazelas' perfectly good awk-based solution, that is less compact but perhaps easier to read because it does not resort to an external variable (check_processed in his notation), would be: $ awk 'FNR == NR {if ($1 == "YES") yes[FNR];next} FNR != NR && FNR in yes' <(check_this <myfile) myfile Note: @...


0

I made a combination of some approaches recommended here. In my case, I need a script that could handle arguments in this format: --arg1=test So I used the following: args=() for argument in "$@" do key=$(echo $argument | cut -f1 -d=) value=$(echo $argument | cut -f2 -d=) if [[ $key == *"--"* ]]; then v="${...


3

You don't need to have a variable. you can do: echo ${(L)$(uuidgen)} # nested parameter expansion Or: print ${$(uuidgen):l} # history modifiers From the web page reference: 14.3.2 Rules Nested substitution If multiple nested ${...} forms are present, substitution is performed from the inside outwards. From man zshexpn (which is quite ...


2

I'd use awk: <myfile check_this | awk ' !check_processed {if ($1 == "YES") yes[FNR]; next} FNR in yes' - check_processed=1 myfile awk records which line numbers of check_this's output start with a YES word in the yes hash table, and then prints the lines of myfile whose number are in that yes hash table.


1

Let's suppose the function for which you want to define completions is called myfunc. First, let's set up the actual function: Put your function in a file called myfunc. Note that this does not end in .zsh or .sh. Make sure that the dir containing the file myfunc is in your $fpath. For example, if the file myfunc is located in ~/func, add this to your ~/....


2

Second answer tries to explain that you need to do two things: 1_ make sure your general matching rules are not case-insensitive (matcher-list) - from the updated question it's not, 2_ change Unix/(Type/)_hosts (the actual location might vary, but not the Unix/_ssh) last 2 lines to: _wanted hosts expl host \ compadd -M 'm:{a-z}={A-Z} r:|.=* r:|=*' -a &...


0

I found out on zsh terminal it is done using something like: sed -i '.bak' '10d' .zsh_history You can improve this command to automatically remove the last command in the history file. It's a good idea to delete empty lines in the zsh history first: sed -i '.bak' '/^$/d' .zsh_history The backup file ".bak" is only required for sed on macOS.


1

The Shift key is not included as a default prefix key in tmux (see here). However, there is a function called user-keys. With this setting, you can define a custom escape sequence and bind that in tmux. To test an escape sequence in Bash (as default), press Ctrl + V followed by the key sequence you want to test - it will then print the escape sequence. ...


1

Split str, then prepend -e to each array element, and split again. % str="c java" % print -lr -- ${=${${=str}/#/-e }} -e c -e java It's uglier and more fragile than it needs to be because the first step is to split a string into a list. If you had the list in an array, you could just prepend and then split: % a=(c java) % print -lr -- ${=${a/#/-e }...


1

Getting No such widget when your press Tab means you have a bindkey statement that has bound Tab to a widget that does not actually exist or the widget you've bound to Tab is trying to invoke another widget that does not exist. To find out what's bound to your Tab key, do bindkey '^I' This will output something like "^I" fzf-completion To find ...


2

bindkey -A … main defines what the main keymap is. The main keymap is the one that the editor uses each time you start editing a line. So what's changed is that the main keymap is now viins rather than emacs. Basically, zsh now uses Vi editing mode by default rather than Emacs editing mode. Unless overridden in your .zshrc, zsh defaults to Vi editing mode if ...


0

It appears that the tool you installed changed your main keymap from emacs to viins (by doing bindkey -v). To change main back to the default value of emacs, do bindkey -e See http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Keymaps for more info on keymaps and http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins for more ...


1

You do not need to change any completion functions to get what you want. Just add this to your ~/.zshrc file: # $PREFIX is the part of the current word that's to the left of the cursor. # $SUFFIX is the part of the current word that's to the right of the cursor. # Let's ignore all host completions that don't explicitly match what we've typed, # but allow ...


1

There's a ZSH plugin I'd recommend: https://github.com/kutsan/zsh-system-clipboard . To install it, run: git clone https://github.com/kutsan/zsh-system-clipboard ~/.zsh/plugins/zsh-system-clipboard And then source the file in your .zshrc: source "$HOME/.zsh/plugins/zsh-system-clipboard/zsh-system-clipboard.zsh" The plugin supports using Tmux' ...


1

% parameter expansion flag can be used: echo "${(%):-%B}$1${(%):-%b}" zsh has a print builtin which has -P to perform prompt expansions (Note: if $1 contains prompt sequences, they will be interpreted as such): print -P -- "%B$1%b" You may want to print all arguments instead of just the first positional parameter (use $@/$*). You may ...


1

%B and %b are examples of prompt sequences, and usually can only be used for formatting prompts. For normal scripting, you can use the tput command to achieve what you want: echo "$(tput bold)$1$(tput sgr0)" Alternatively, you could output the ECMA-48 ("ANSI") escape codes directly. I wouldn't recommend this though, because it's less ...


-1

I found the reason should be that sudo command invokes the sh as a default shell to root user, and there is no command called 'print' in sh.


1

Is it's the same -n/-o noexec as in POSIX shells, that causes the code to be read and parsed but not executed. See info zsh noexec for details. Beware it flags shell syntax errors, but not necessarily things like wildcard/qualifier/expansion flag syntax errors. Also note that some options affect the syntax of the shell. So if you have some set -o those-...


1

This is mostly covered in Why does parameter expansion with spaces without quotes work inside double brackets "[[" but not inside single brackets "["?. In a nutshell, [[ … ]] is special syntax with different parsing rules, whereas test and [ are ordinary commands. In plain sh (including ksh, bash, etc.), test -n $var applies splitting and ...


1

Let's split it up in parts cp -a: copy everything in ~/.[^.]* and the dirs below it to . With -a you are telling 'Also copy the subdirectories and try to keep all properties of the files and dirs the same' . See man cp for more info ~/.[^.]*: All hidden files and dirs in your home dir because: ~ is your homedir * means 'this can be anything' so ~/* becomes:...


2

That syntax is for some shells other than zsh and even there, it would be wrong. .[^.]* matches on file names that start with . followed by a character other than ., followed by 0 or more characters. That's the kind of syntax you'd need in shells that include . and .. in the expansion of .*. . and .. are navigating tools used to refer to the current and ...


2

To complement @Gilles' answer, you can also assign values to positional parameters outside of arithmetic expressions with 1=value for instance, so here to increment the first positional parameter, you could also do: 1=$(($1 + 1)) But strictly speaking, if $1 may contain an arbitrary arithmetic expression as opposed to just a literal numerical constant (such ...


5

In zsh, the array variable argv is an alternative way to access the positional parameters. So: ((argv[1]++))


2

As long as your terminal generates input control sequences in ECMA-48 form, or the DECFNK, Interix, SCO Console, or Unicode RXVT forms, you can feed it to my console-decode-ecma48 tool, with the --input command-line option to tell it that the character stream is input rather than output. This is true for most terminals and terminal emulators that you will ...


2

What character or sequence of characters a terminal sends when you press one of its keys (or key combinations) depends on the terminal itself. While a is quasi-universally what all terminals send when you press their A key (for those that have such a key at least), for keys like Home, Left, F1 or Ctrl+6, etc, it varies a lot between terminals. There is some ...


3

The first couple of lines ^[^? ^X^U are codes that you can find tabulated as ASCII controls ^[ (escape) ^U (control-U) ^X (control-X) That ^? is the conventional representation of ASCII DEL (the delete key). If your terminal description (TERM) is set appropriately, infocmp -1 -x will print the ncurses names for the keys in terminfo format. There's ...


0

bash $ bind -p | grep -F '[3;5~' "\e[3;5~": delete-char


0

Ok, I found it. It is. .zshrc I added this line to be sure next time: echo "Hello zsh";


0

It sounds to me you would have to redefine the widgets that take a motion, like the ones bound to d, c, y, gu, gU, g~... Something like: test-widget () { MARK=3 CURSOR=6 MOVE_AFTER_MOTION=2 } zle -N test-widget bindkey -M vicmd ' ' test-widget for widget in vi-{delete,change,yank,{down,oper-swap,up}-case}; do $widget () { local ret zle "...


2

IMNSHO robustness and shell scripts are incompatible concepts (IFS is just a hack, sorry). I think there are only two ways to do what you want in a robust manner: either write a program in some sane language (Python, C, whatever) or use tools built specifically for robustness. With csv-nix-tools (*) you can achieve this with: csv-ls -c name,mtime_sec,...


2

A process can be sent that SIGTTOU signal (which causes that message), when it makes a TCSETSW or TCSETS ioctl() for instance (like when using the tcsetattr() libc function) to set the tty line discipline settings while not in the foreground process group of a terminal (like when invoked in background from an interactive shell), regardless of whether tostop ...


3

The problem will be that each instance of 2>&1 will cause stderr to redirected all over again to each redirection of stdout that was already done. See this example in the multios section: However, consider: date >output >&1 As redirections are evaluated in order, when the >&1 is encountered the standard output is set to the file ...


1

An alternate approach I was surprised not to see already covered, which will work on any shell adopting quite widespread ksh extensions (including both bash and zsh), on a system with GNU tools: while IFS= read -r -d ' ' time && IFS= read -r -d '' filename; do printf 'Filename %q, with epoch time %s\n' "$filename" "$time" done &...


11

In zsh, list=(*(Nom:r)) Is definitely the most robust. print -rC1 -- *(Nom:r) to print them one per line, or print -rNC1 -- *(Nom:r) as NUL-delimited records to be able to do anything with that output since NUL is the only character not allowed in a file path. Change to *(N-om:r) if you want the modification time to be considered after symlink resolution (...


0

There's the install command from GNU coreutils with the -D option which can copy a file and create the directories leading to them in one go (and also let you specify the ownership and permissions). By default, it creates executable files and doesn't honour the umask as it's typically used as a dev tool in make install stages. install -m u=rw,go=r -D /dev/...


2

In addition to the basic 10 chars that a working alias can not accept in zsh: "&');<>`|, setting the option posixaliases adds 12 more #$(*-?[\]^{~ That includes the dash -, which is valid without posixaliases. Alias options There are few options in zsh that affect aliases: ALIASES ALIAS_FUNC_DEF POSIX_ALIASES The aliases option enables all ...


2

Those 2 images are showing 2 different folders. The first image (using ls -a) is showing you your personal folder. The second image is showing you the files & folders in the Desktop folder. Try this: cd ~/Desktop ls -a And notice that you will see the contents as per the second image. Notice that both have a folder called Documents, and so perhaps ...


Top 50 recent answers are included