5 ms·
I really like this one: jj. New prompt string: PS0. Expanded and displayed by interactive shells after reading a complete command but before execu
by p4bl0 10y ago
I really like this one:
jj. New prompt string: PS0. Expanded and displayed by interactive
shells after reading a complete command but before executing it.
I currently use my PS1 for a lot of dirty things that would have their place in such a PS0 :).
Now, I just have to wait until Bash 4.4 lands in Debian…
- pawadu 10y agoWait, how does this work again?
- HeadlessChild 10y agoSee you in Debian stable 10.
- voltagex_ 10y ago4.4rc2 is in experimental and 4.4 is likely to end up in -backports, so it's not all bad.
- raziel2p 10y agoLike what? Out of curiosity.
- p4bl0 10y agoI detailed some of these dirty things in an old (2011) blog post: https://shebang.ws/fast-window-switch-2-bash-tricks.html https://shebang.ws/fast-window-switch-2-bash-tricks.html
- CJefferson 10y agoYou could use PS0 to make your terminal title be "running <name of program>" when a program is running, then "directory <dir name>" when just on a prompt (that might be too busy for some people, but I'd like to know if a program is actively running in the terminal title).
- p4bl0 10y agoSee my other comment with a link to a blogpost that explains how to do just this before having PS0 :).
- CJefferson 10y agoAh, cool. Didn't realise there was a hack around it (that might still be useful on non-4.4 systems).
- deleted 10y ago[deleted]
- ball_of_lint 10y agoThis is really nice if you keep your own history because then the directory stored for commands like cd will be the one it was called from rather than the one it moved you into.
- abainbridge 10y agoPresumably I can use this to display when the command started (PS0='\t'). I've wanted that forever.
- bluejekyll 10y agoYes! This is huge for visually knowing when something happened.
- amitutk 10y agoTo find the time taken by jobs, it's simplest to just display current time in the prompt. You can quickly look at the time when the job start and the time after job ended. PS1="\@ \h \w> " This displays current time, host and working dir.
- okket 10y agoExcept you have to not forget the to refresh the prompt before typing the command after a coffee break or switching terminal tabs, etc. The PS0 solution is much, much better for this use case.
- kazinator 10y agoYou could implement PS0 in an older Bash which doesn't have it. See here: http://superuser.com/questions/175799/does-bash-have-a-hook-that-is-run-before-executing-a-command http://superuser.com/questions/175799/does-bash-have-a-hook-... There is way to hook into command execution. And that piece of code you hook in could look at a variable called PS0 and process it the way Bash 4.4 does it now. This new PS0 might provide a pre-execution hook of its own. If it performs $(....) command substitution (like PS1 does!), it provides a way of executing arbitrary code. If the entire prompt is "$(some-command ...)" and that command produces no output, then you have a de facto pure hook.
- p4bl0 10y agoYes that's what I did, see my other comment where I link to one of my old blogpost detailing it. My point is that PS0 will make that cleaner :).