Skip to main content

New answers tagged

1 vote

Be notified of new mail in any Maildir inbox under ~/Mail, in the Zsh shell

Since Maildir mailboxes are used, new mail may be found by looking for any regular file in any directory called new under ~/Mail. We ignore the fact that for a directory to be a legal Maildir mailbox, ...
Kusalananda's user avatar
  • 339k
2 votes

zsh alias does not complete fully if not sourced once a day

If you have some sort of personal configuration file that isn't standard, such as this ~/.zsh you mention, of course you need to source it manually each time you log in. To make this happen ...
terdon's user avatar
  • 244k
0 votes

recursively remove newline from directory names

rename.pl For those of you who always prefer find + xargs, here's what you need: find -iname $'*\n*' -print0 | xargs -0 rename.pl -p -v 's{\n}{_}g' I had this issue on some Windows dirs that I'd ...
Sridhar Sarnobat's user avatar
0 votes

recursively remove newline from directory names

Here it turned out to be about removing the U+2029 paragraph separator character (which your file manager happens to render as ↲) rather than newline. But to answer the question in the subject, to ...
2 votes

To check whether first or last character of a string is x

Since you're asking for zsh, you can of course use standard: case $string in (x* | *x) echo "starts or ends in x (or both)";; (*) echo "Neither starts nor ends in x";; esac ...
Stéphane Chazelas's user avatar
1 vote

Zsh script to filter array excluding a substring

prd~uat matches any string that is prd and is not uat. So that's the same as prd alone. *prd~uat*east* matches any string that ends in prd and that does not start with uat followed by something that ...
Stéphane Chazelas's user avatar
1 vote
Accepted

Zsh script to filter array excluding a substring

Putting the match and exclude filters into a parenthesized group appears to work: #!/usr/bin/env zsh # arg1, environment: dev qa uat-prd prd # arg2, region: east west * filterServerArray() { # ...
Gairfowl's user avatar
  • 650
2 votes

To check whether first or last character of a string is x

To address your "What is the problem here?" question: string="2x3" if [[ "${-n $string | head -c 1}" == "x" ]]; then echo "first character is x" ...
7 votes

To check whether first or last character of a string is x

In any POSIXy shell, the case statement provides pattern matches (without running any external tools): isx() { case $1 in x ) printf '%s\n' "'$1' is just a single x";; x*...
ilkkachu's user avatar
  • 141k
-2 votes

To check whether first or last character of a string is x

Alternative solution, perhaps more readable but which uses more commands: string="xqwertyx" [[ $(echo "$string" | cut -c1) == "x" ]] && echo "First ...
dr_'s user avatar
  • 30.1k
4 votes
Accepted

To check whether first or last character of a string is x

Your expansion with ${ .. } does not run any code: it just produces a text string which is itself not even a valid command (it would need an echo, and also round brackets). There is a Bash expansion ...
Paul_Pedant's user avatar
  • 9,074
0 votes

How to edit command line in full screen editor in ZSH?

In vi mode, a no-config way of achieving that is to use : in normal mode and enter the edit-command-line widget. (You can just type ed and tab-complete it) More info there : https://thevaluable.dev/...
cassepipe's user avatar
  • 179
8 votes
Accepted

How to make '.zshrc' to search for sourced files in the specific folder and not in the folder from which the terminal has been opened

Give an absolute path to the file: . ~/system-wide-clipboard.zsh
Stephen Kitt's user avatar
-2 votes

Expansion of tilde in zsh

In any command you can include the output of another command enclosed in back quotes, even for parameters, directly without eval (it executes in a temporary shell). Here's an example where using tilde ...
Anders Brandén's user avatar
3 votes
Accepted

To execute a shell script: Using "zsh script.sh" and using "./script.sh"

That’s as expected! By default, your file script.sh is not going to be executable. You can correct this with: chmod +x ./script.sh Then running ./script.sh should work. (You can change it back with ...
wobtax's user avatar
  • 318
1 vote

In bash/zsh, how to compare the metadata in two directories including . and excluding .. and the contents inside subdirectories?

-a lists all directory entries, that includes . and .. on systems where readdir() / getdents*() include them. Here, you could run ls twice, once for . with -d (ls -ld . will work even on systems where ...
Stéphane Chazelas's user avatar
1 vote

In bash/zsh, how to compare the metadata in two directories including . and excluding .. and the contents inside subdirectories?

Presumably you're using GNU ls, in which you can omit only .. by using the --ignore/-I option: % ls -la --full-time total 12 drwxr-xr-x 3 muru muru 4096 2024-06-25 11:14:18.165432064 +0900 . drwxr-xr-...
muru's user avatar
  • 73.9k
0 votes

Equivalent of PSReadLine for bash

I finally figured out how to do the exact behavior. ZSH is the only one that could give me identical results: #!/bin/bash # This is done in bash; we'll switch to zsh when we're ready # install ...
Nour's user avatar
  • 115
4 votes
Accepted

incrementing file names in zsh

This may be easier with zshs powerful globbing syntax instead of find and wc. Try this: #!/usr/bin/env zsh setopt extendedglob nextFilename() { local fqp=${1:?} local -a fileCopies=( ${fqp:r}(...
Gairfowl's user avatar
  • 650
0 votes
Accepted

Saving ZSH history across SSH sessions

To save history between sessions, you primarily need to set a few variables for history size in your ~/.zshrc. For example. HISTSIZE=10000 HISTFILE=~/.zshistory SAVEHIST=8000 Avoid using export with ...
okapi's user avatar
  • 757
0 votes

How to remove duplicate slashes from path to a file?

Using python P=/opt//bin//executable RP=$(python3 -c "import pathlib; print(pathlib.Path(\"$P\"))") ❯ echo $RP /opt/bin/executable Python seems to keep the leading double ...
balki's user avatar
  • 4,457
-1 votes

Running chsh does not change shell

Circling back on this if anyone wants a simple solution: I was logged in as root and I got the same error message as was listed before using chsh. This is what worked for me. If I wanted to toggle to ...
Charles Owen's user avatar
0 votes

Salesforce dataloader #!/bin/bash script errors mentions .zshrc

The answer courtesy of `@steeldriver. Turns out, one of the scripts in dataloader imports .zshrc explicitly. The problem was solved by removing the following lines from the util/util.sh script: ...
Al Cher's user avatar
  • 101
2 votes
Accepted

what is the nature of compgen under zsh (as opposed to bash)?

Run from my linux bash: $> type compgen compgen is a shell builtin from my linux zsh: compgen is a shell function from /home/marcus/.oh-my-zsh/lib/completion.zsh on a linux zsh on a "clean&...
Marcus Müller's user avatar

Top 50 recent answers are included