Hot answers tagged

35

As you clarified in comments it's still running in foreground on an interactive shell, you should just be able to press Ctrl+Z. That will suspend the ./command job. Unless ./command actually intercepts the SIGTSTP signal and chooses to exit(0) in that case (unlikely), the exit status will be non-0 (128+SIGTSTP, generally 148), so sudo poweroff will not be ...


8

You could just rename /sbin/poweroff temporarily.


4

Cron doesn't accept shell functions, create a script like #!/bin/bash adddate() { while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done } $binPath/zsh/test.zsh | adddate 1>>$logPath/log.csv 2>>$errorLogPath/error.txt and put that in cron. (I'm assuming here that you used $binPath and $logPath ...


4

ga somename.java is short for git add **/ somename.java. The first argument to the alias is not concatenated to the last word inside the alias. You can think of it this way: the space that you type after ga is not removed. To do anything more complex than give a command an alternate name or pass arguments to a command, use a function instead of an alias. ...


3

With zsh: autoload zmv # best in ~/.zshrc zmv -v $'(**/)(*[\n\u2029]*)(#qD)' $'$1${2//[\u2029\n]}' To remove both newlines (U+000A) or the paragraph separator character (U+2029). Or: zmv -v $'(**/)(*[[:cntrl:]]*)(#qD)' $'$1${2//[[:cntrl:]]}' to remove all control characters. Whether U+2029 will be classified as cntrl or not will depend on the system though....


3

You said that printf "%q\n" * shows first$'\342\200\251' second$'\342\200\251' third$'\342\200\251' The $'\342\200\251' there isn't the regular newline, it's the Unicode U+2029 PARAGRAPH SEPARATOR, encoded in UTF-8. The output there has the bytes in octal; in hex, they would be e2 80 a9. That's why find -name $'*\n*' doesn't match it. Without the ...


3

I don't know about your specific terminal emulator, but in xterm (whose API many terminal emulators have copied), you can do: printf '\e]11;%s\a' colorname to set the background colour. Where colorname can be any colour specification as supported by the XParseColor() X library function. Then you could have zsh send escape sequences with a colour ...


2

One of the Zsh User Guides mentions that you could press Escape followed by Enter when you intend to create a line break, to avoid entering into a multiprompt(PS2) where you can no longer edit the previous line. This also works only with the default emacs keybindings. However, I find the answer from the_velour_fog should be marked as the accepted answer as ...


2

That quote> is the $PS2 (aka $PROMPT2 in zsh) prompt, the secondary prompt string. The primary prompt string ($PS1 / $PROMPT), >  it seems in your case, is the one that invites you to enter a command. The secondary command is the one that invites you to continue and finish your command. It's displayed after you've pressed Enter while the command was ...


2

That's the whole point of pipe lines to run commands concurrently with pipes in between them. For commands to run sequentially, you'd need pipes of infinite size, or resort to storing output into temporary files. With zsh, that can be done with: zathura =( man -k . | fzf -e --tiebreak=begin | awk '{print $1}' | xargs -rd '\n' man -Tpdf ) (here ...


2

There's definitely a simpler way to do it robustly in zsh. There's a simpler way to do it robustly in plain sh, too: this script is overly complicated and fragile (assumes all file names have an extension, overwrites files without prompting, …). Since this thread is about zsh, I'll take advantage of zsh's capabilities. The history and parameter expansion ...


2

That would rather be: eval -- "$(pbpaste)" or: pbpaste | source /dev/stdin eval evaluates the shell code resulting of the concatenation with spaces of its arguments. So here we take the output of pbpaste with $(...) command substitution, quoted so that it is not split and pass it as one argument to eval (preceded with -- that marks the end of ...


1

The primary role of a shell is to let you run the programs that are installed on your system. As a consequence, all command line shells let you run pretty much the same commands. The differences are a very small number of commands that are built into the shells themselves, which vary a little between shells. Shells differ mainly in terms of their programming ...


1

Perhaps I'm missing something here — I'd never heard of fzf (or zathura, for that matter) before I saw this question, and I don't have them on my system to test with.  But … isn't the point of fzf to pick an item from a list?  Let me rephrase that: isn't the point of fzf to pick one item from a list?  Isn't xargs overkill here?  Isn't the logic basically ...


1

In my usecase I have many font files to patch (i.e. many .ttf files), and I want to directly type and run the script command in Terminal (not storing it in a script file): for x in JetBrainsMonoNL* ; do \ fontforge -script fontpatcher $x --mono -l -q --fontawesome \ --octicons --fontlogos --mdi --powerline --powerlineextra; \ done; The point is: ...


1

The problem isn't kitty. If you run /bin/sh and paste you can test that. The problem, in my case, was actually zsh. And specifically oh-my-zsh which has this in the ~/.zshrc conf, # Uncomment the following line if pasting URLs and other text is messed up. # DISABLE_MAGIC_FUNCTIONS=true Uncommenting that fixed my problem. https://github.com/ohmyzsh/ohmyzsh/...


1

You will need to train yourself to enter your commands a bit differently to be able to get what you want. This works: % setopt histignoredups % print a; print b a b % print a; print b a b % print a; print c a c % print a; print b a b % print a; print b a b % history 1 setopt histignoredups 2 print a; print b 3 print a; print c 4 print a;...


1

Assuming you are referring to your own user's crontab, to avoid duplicating the definition of JAVA_HOME you can export the variable in ~/.zshenv (instead of ~/.zshrc), which is read even in non-interactive, non-login shells, and run zsh -c 'sh /path/to/script' in your cron job (replacing sh, based on what the program called "Bourne shell" in your ...


1

Is there a way to prevent zsh from executing the poweroff command while making sure that the first one runs until it is done? I don't think it's possible unless you use something like gdb to edit the memory of a running process. Would editing the /etc/sudoers file so that the system asks for my password still help in this case? It should help.


1

My problem was I that I had put them in a pair of single qoutes. Here is a solution: "{\":updated\": {\"N\":`date +%s`}}"


1

One good feature I like is that zsh automatically show the running command on window title That's actually Oh-My-Zsh that does that, not Zsh itself. To get the behavior you want: From the Oh-My-Zsh file lib/termsupport.zsh, copy the function omz_termsupport_preexec to your .zshrc file Change the last line (title '$CMD' '%100>...>$LINE%<<') to ...


1

Use the steef theme as the basis for a new theme, say, taciano: % cd $ZPREZTODIR/modules/prompt/functions % cp prompt_steeef_setup prompt_taciano_setup In your .zpreztorc file, find zstyle ':prezto:module:prompt' theme <value> and change <value> to taciano. In the file $ZPREZTODIR/modules/prompt/functions/prompt_taciano_setup, change the line ...


1

You can ignore some patterns in completions by tuning completion styles with the zstyle built-in. There are examples in the zsh guide. zstyle ':completion:*:*:cd:*:*' ignored-patterns '__pycache__' Under default settings, zsh tries a second round of completion if there are no matches the first time, and the second round does not honor ignored-patterns, so ...


1

As suggested in one of the comments, you could put them in the file /etc/zshenv. However, on many distributions, this file is supplied by the OS. Besides that, /etc/zshenv is sourced every time your system runs a Zsh script, even when it's not from an interactive shell. Putting too many customizations in /etc/zshenv has the potential to significantly slow ...


1

If you first paste cat >> test.txt and press Enter, and then paste This is a test. and then press Enter followed by ControlD, or press ControlD twice, you will get the result you're looking for (in the first case, with a line break after your input, and in the second case, without). If you directly paste cat >> test.txt This is a test. then ...


1

Good Ol' Locale One issue I have had come up is not having my locale set, which causes all sorts of headache and misery to befall the unaware. To set it, go to /etc/locale.gen and uncomment the US English locale: en_US.UTF-8 UTF-8 then as root run locale-gen and as root again localectl set-locale LANG=en_US.UTF-8 just to be extra sure. Then reboot and if ...


1

The behaviour that you're observing, i.e. that pressing Ctrl+P brings back the previous command even if it starts with a space and HIST_IGNORE_SPACE is set, is documented (my emphasis): HIST_IGNORE_SPACE (-g) Remove command lines from the history list when the first character on the line is a space, or when one of the expanded aliases contains a leading ...


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