* get the number of active jobs to show in the prompt? @ 2001-10-01 5:56 Drew Perttula 2001-10-01 6:09 ` Goran Koruga ` (2 more replies) 0 siblings, 3 replies; 29+ messages in thread From: Drew Perttula @ 2001-10-01 5:56 UTC (permalink / raw) To: zsh-users Hello everyone- I'm tired of using my close-window shortcut to zap shells that still owned running programs, so I'd like my zsh prompt to indicate that somehow. I can't figure out how to do anything programmatically with the 'jobs' command (such as "jobs | wc -l"), so I'm lost as to how to do my prompt trick. TIA for any help -Drew ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 5:56 get the number of active jobs to show in the prompt? Drew Perttula @ 2001-10-01 6:09 ` Goran Koruga 2001-10-01 6:12 ` Sweth Chandramouli 2001-10-01 8:28 ` Deborah Ariel Pickett 2 siblings, 0 replies; 29+ messages in thread From: Goran Koruga @ 2001-10-01 6:09 UTC (permalink / raw) To: zsh-users On Sun, Sep 30 2001, Drew Perttula wrote: Hi, export PS1="`jobs | wc -l`" should work if you have PROMPT_SUBST set. However, while testing it, I noticed that jobs | wc -l always prints 0 (other commands can't get its output either), so someone else will have to explain you why this happens. Goran > > Hello everyone- > > I'm tired of using my close-window shortcut to zap shells > that still owned running programs, so I'd like my zsh prompt > to indicate that somehow. I can't figure out how to do anything > programmatically with the 'jobs' command (such as "jobs | wc -l"), > so I'm lost as to how to do my prompt trick. > > TIA for any help > > -Drew > -- Writing about music is like dancing about architecture. -- Frank Zappa ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 5:56 get the number of active jobs to show in the prompt? Drew Perttula 2001-10-01 6:09 ` Goran Koruga @ 2001-10-01 6:12 ` Sweth Chandramouli 2001-10-01 6:37 ` Phil Pennock 2001-10-01 8:28 ` Deborah Ariel Pickett 2 siblings, 1 reply; 29+ messages in thread From: Sweth Chandramouli @ 2001-10-01 6:12 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 1041 bytes --] On Sun, Sep 30, 2001 at 10:56:50PM -0700, Drew Perttula wrote: > > Hello everyone- > > I'm tired of using my close-window shortcut to zap shells > that still owned running programs, so I'd like my zsh prompt > to indicate that somehow. I can't figure out how to do anything > programmatically with the 'jobs' command (such as "jobs | wc -l"), > so I'm lost as to how to do my prompt trick. zsh spawns a subshell for the LHS of a pipe, rather than the RHS, which lets you do things like $ do_something | read VAR and have VAR still be set. That means that jobs in your example is being run in a subshell where there _aren't_ any background jobs. The only way I can think of offhand to get the info from jobs would be to redirect the output of jobs to a temp file and then use that to build your prompt; that's not very efficient, however. I don't know if there's some other way to get that info from the shell. -- Sweth. -- Sweth Chandramouli ; <svc@sweth.net> President, Idiopathic Systems Consulting [-- Attachment #2: Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 6:12 ` Sweth Chandramouli @ 2001-10-01 6:37 ` Phil Pennock 2001-10-01 6:59 ` Drew Perttula 2001-10-01 7:08 ` Sweth Chandramouli 0 siblings, 2 replies; 29+ messages in thread From: Phil Pennock @ 2001-10-01 6:37 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 1427 bytes --] On 2001-10-01 at 02:12 -0400, Sweth Chandramouli wrote: > zsh spawns a subshell for the LHS of a pipe, rather than > the RHS, which lets you do things like > > $ do_something | read VAR > > and have VAR still be set. That means that jobs in your > example is being run in a subshell where there _aren't_ any background > jobs. The only way I can think of offhand to get the info from jobs > would be to redirect the output of jobs to a temp file and then use that > to build your prompt; that's not very efficient, however. I don't know > if there's some other way to get that info from the shell. I picked this up from zefram, I think: jobs % >& /dev/null && psvar[1]="" || psvar[1]=() Actually, what I have is this: precmd () { local exitstatus=$? psvar[1]=SIG [[ $exitstatus -ge 128 ]] && psvar[1]=SIG$signals[$exitstatus-127] [[ $psvar[1] = SIG ]] && psvar[1]=$exitstatus jobs % >& /dev/null && psvar[2]="" || psvar[2]=() } [ switch PS1 depending upon $TERM, but for xterm: ] PS1=': %2(L.%U[%L]%u.)%(?..%B{%v}%b)%(2v:+:-)%n@%m:%l(%!)%30<..<%~%#; ' The key thing is the %(2v:+:-) -- psvar[2] was set depending upon whether or not there are background jobs, %(2v:+:-) therefore gives a '+' if there are background jobs, or a '-' if not. I _really_ miss having +/- indication of background jobs when forced to use bash. -- <-------- The information went data way [-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --] ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 6:37 ` Phil Pennock @ 2001-10-01 6:59 ` Drew Perttula 2001-10-01 7:08 ` Sweth Chandramouli 1 sibling, 0 replies; 29+ messages in thread From: Drew Perttula @ 2001-10-01 6:59 UTC (permalink / raw) To: zsh-users > Actually, what I have is this: > precmd () { > local exitstatus=$? > psvar[1]=SIG > [[ $exitstatus -ge 128 ]] && psvar[1]=SIG$signals[$exitstatus-127] > [[ $psvar[1] = SIG ]] && psvar[1]=$exitstatus > jobs % >& /dev/null && psvar[2]="" || psvar[2]=() > } > [ switch PS1 depending upon $TERM, but for xterm: ] > PS1=': %2(L.%U[%L]%u.)%(?..%B{%v}%b)%(2v:+:-)%n@%m:%l(%!)%30<..<%~%#; ' > > The key thing is the %(2v:+:-) -- psvar[2] was set depending upon > whether or not there are background jobs, %(2v:+:-) therefore gives a > '+' if there are background jobs, or a '-' if not. It seems like the + and - come at the reverse times than you say, but, just the same, this looks like what I want. Thanks everyone for the quick responses! -Drew ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 6:37 ` Phil Pennock 2001-10-01 6:59 ` Drew Perttula @ 2001-10-01 7:08 ` Sweth Chandramouli 1 sibling, 0 replies; 29+ messages in thread From: Sweth Chandramouli @ 2001-10-01 7:08 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 984 bytes --] On Mon, Oct 01, 2001 at 08:37:58AM +0200, Phil Pennock wrote: > The key thing is the %(2v:+:-) -- psvar[2] was set depending upon > whether or not there are background jobs, %(2v:+:-) therefore gives a > '+' if there are background jobs, or a '-' if not. The difference between this and the OP's request being that you only know if there are backgrounded jobs, and not how many there are. Maybe it would be nice to be able to invoke jobs with a process group leader argument, in which case it would (if perms were correct, of course) show the job list for the shell with that PID, rather than the current shell, so that people could do something like PS1="[$(jobs -P $$ | wc -l)]rest_of_prompt" ? (Actually, it would probably be better to just add a % macro for "number of current jobs", though I don't think it's really important enough to warrant either.) -- Sweth. -- Sweth Chandramouli ; <svc@sweth.net> President, Idiopathic Systems Consulting [-- Attachment #2: Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 5:56 get the number of active jobs to show in the prompt? Drew Perttula 2001-10-01 6:09 ` Goran Koruga 2001-10-01 6:12 ` Sweth Chandramouli @ 2001-10-01 8:28 ` Deborah Ariel Pickett 2001-10-01 9:04 ` Phil Pennock 2 siblings, 1 reply; 29+ messages in thread From: Deborah Ariel Pickett @ 2001-10-01 8:28 UTC (permalink / raw) To: Drew Perttula; +Cc: zsh-users Drew wrote: > I'm tired of using my close-window shortcut to zap shells > that still owned running programs, so I'd like my zsh prompt > to indicate that somehow. I can't figure out how to do anything > programmatically with the 'jobs' command (such as "jobs | wc -l"), > so I'm lost as to how to do my prompt trick. Looks like you've already got an answer, but there are better ways to do this from zsh 3.1.9 onwards. The "zsh/parameter" module defines three variables, among others: jobdirs, jobtexts, and jobstates. They're normal associative arrays, which means you can do things like this: numberofjobs=$#jobstates without having to invoke subshells or other yucky things you really want to keep out of the shell prompt generation code. If you want to count just running jobs, or suspended jobs, this appears to work (but it probably isn't the natural way to do it; I just made up this solution by simulated annealing): numberofsuspendedjobs=${(Mw)#jobstates#suspended:} s/suspended/running/g for running jobs. Insert "zmodload zsh/parameter" in a suitable zsh startup file (such as .zshrc) before trying this. -- Debbie Pickett http://www.csse.monash.edu.au/~debbiep debbiep@csse.monash.edu.au "As far as my eyes can see there are shadows surrounding me. And to those I leave behind, I want you all to know you've always shared my darkest hours, I'll miss you when I go." - _Old and Wise_, The Alan Parsons Project ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 8:28 ` Deborah Ariel Pickett @ 2001-10-01 9:04 ` Phil Pennock 2001-10-01 17:44 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Phil Pennock @ 2001-10-01 9:04 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 788 bytes --] On 2001-10-01 at 18:28 +1000, Deborah Ariel Pickett wrote: > Looks like you've already got an answer, but there are better ways to do > this from zsh 3.1.9 onwards. Ooh, thanks! Wonder how I missed this when reading zshmodules(1)? *sighs* > Insert "zmodload zsh/parameter" in a suitable zsh startup file (such as > .zshrc) before trying this. Yep, works beautifully; I now use: zmodload zsh/parameter function precmd { [... all the other bits ...] psvar[2]=$#jobstates; [[ $psvar[2] -eq 0 ]] && psvar[2]=() } and then in PS1: %(2v:<+%2v>:-) Let more linenoise^Wzsh beauty. -- Whoever despises the high wisdom of mathematics nourishes himself on delusion and will never still the sophistic sciences whose only product is an eternal uproar -- Leonardo da Vinci [-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --] ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 9:04 ` Phil Pennock @ 2001-10-01 17:44 ` Vincent Lefevre 2001-10-02 15:43 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-01 17:44 UTC (permalink / raw) To: zsh-users On Mon, Oct 01, 2001 at 11:04:54 +0200, Phil Pennock wrote: > zmodload zsh/parameter > function precmd { [... all the other bits ...] > psvar[2]=$#jobstates; [[ $psvar[2] -eq 0 ]] && psvar[2]=() > } > and then in PS1: %(2v:<+%2v>:-) There is a small problem, though: When a job terminates and the prompt is reprinted, precmd isn't called and the prompt isn't rebuilt, so that I still get the old prompt. I'd prefer to get a new prompt (a bit like when I type [Return]). Is there an option to have this behaviour? -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-01 17:44 ` Vincent Lefevre @ 2001-10-02 15:43 ` Bart Schaefer 2001-10-02 16:13 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-02 15:43 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 1, 7:44pm, Vincent Lefevre wrote: } } There is a small problem, though: When a job terminates and the prompt } is reprinted, precmd isn't called and the prompt isn't rebuilt, so that } I still get the old prompt. I'd prefer to get a new prompt (a bit like } when I type [Return]). Is there an option to have this behaviour? There's no option to get that behavior because, in general, regenerating the prompt might change too much of the editor state. For example, what if you're editing at the secondary prompt (e.g., on the second or later line of a shell function or quoted string)? So the closest you could do is "setopt no_notify" so that job termination is only recognized/reported immediately before printing the prompt. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-02 15:43 ` Bart Schaefer @ 2001-10-02 16:13 ` Vincent Lefevre 2001-10-02 23:25 ` Deborah Ariel Pickett 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-02 16:13 UTC (permalink / raw) To: zsh-users On Tue, Oct 02, 2001 at 15:43:13 +0000, Bart Schaefer wrote: > There's no option to get that behavior because, in general, regenerating > the prompt might change too much of the editor state. For example, what > if you're editing at the secondary prompt (e.g., on the second or later > line of a shell function or quoted string)? I don't see the problem. Could you give an example? > So the closest you could do is "setopt no_notify" so that job termination > is only recognized/reported immediately before printing the prompt. No, I want job termination to be reported immediately. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-02 16:13 ` Vincent Lefevre @ 2001-10-02 23:25 ` Deborah Ariel Pickett 2001-10-02 23:29 ` unsubscribe me Matthew Lyon 2001-10-03 0:06 ` get the number of active jobs to show in the prompt? Vincent Lefevre 0 siblings, 2 replies; 29+ messages in thread From: Deborah Ariel Pickett @ 2001-10-02 23:25 UTC (permalink / raw) To: Vincent Lefevre; +Cc: zsh-users Vincent wrote: > On Tue, Oct 02, 2001 at 15:43:13 +0000, Bart Schaefer wrote: > > There's no option to get that behavior because, in general, regenerating > > the prompt might change too much of the editor state. For example, what > > if you're editing at the secondary prompt (e.g., on the second or later > > line of a shell function or quoted string)? > I don't see the problem. Could you give an example? I thought the above paragraph *was* the example . . . OK, this example's not quite the same as Bart's, but it's close. Say you're in the middle of typing the following code: primary-prompt-with-job-info-in-it> for x in foo bar baz secondary-prompt> do secondary-prompt> echo ^ and the cursor is right there when a job finishes. What you seem to want is for zsh to instantly be interrupted and have it re-process the prompt. How? Should it run precmd() again to do so? What if there's stuff in precmd() that isn't to do with generating the prompt, but is instead involved in dealing with command history? You wouldn't want that to run again, because you haven't finished typing your command. I also believe that when you're typing a multi-line command like the one above, the individual lines that make it up aren't joined together into the command history as one command until the whole command is complete. (zsh developers, please correct me if I'm wrong.) Re-displaying the multi-line command thus isn't going to be easy. It certainly can't be done with user-level zsh programming. Yes, of course zsh could be modified to do what you want. Personally, I'd love it, because I was trying to do a similar thing a few months back, but I don't think it's very high on the zsh developers' list of priorities. (I'm not one of them, so correct me if I'm wrong.) (What I was trying a few months back was something that would set an alarm trap to go off in a few minutes, and catch it with a trap handler that would re-generate the prompt. It would then repeat the process, ensuring that the prompt was always up-to-date. Thus if I was away from my terminal I could see immediately how many messages were waiting for me by looking at the relevant part of the prompt. It didn't work, for the reasons Bart relates, so I just got in the habit of pressing ENTER to re-print the prompt when I came back to my machine. One extra keypress hasn't killed me.) -- Debbie Pickett http://www.csse.monash.edu.au/~debbiep debbiep@csse.monash.edu.au "Am I - d-dead?" "No." "We could fix that for you . . ." - _FernGully_ ^ permalink raw reply [flat|nested] 29+ messages in thread
* unsubscribe me 2001-10-02 23:25 ` Deborah Ariel Pickett @ 2001-10-02 23:29 ` Matthew Lyon 2001-10-03 0:06 ` get the number of active jobs to show in the prompt? Vincent Lefevre 1 sibling, 0 replies; 29+ messages in thread From: Matthew Lyon @ 2001-10-02 23:29 UTC (permalink / raw) Cc: zsh-users please unsubscribe me. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-02 23:25 ` Deborah Ariel Pickett 2001-10-02 23:29 ` unsubscribe me Matthew Lyon @ 2001-10-03 0:06 ` Vincent Lefevre 2001-10-03 5:43 ` Bart Schaefer 1 sibling, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 0:06 UTC (permalink / raw) To: zsh-users In article <200110022325.JAA07306@bruce.csse.monash.edu.au>, Deborah Ariel Pickett <debbiep@mail.csse.monash.edu.au> wrote: > What you seem to want is for zsh to instantly be interrupted and have it > re-process the prompt. > How? The current command should be saved in a safe place. Then, the necessary functions (e.g., precmd()) should be called. Finally, the current command should be restored and displayed with the new prompt(s). > Should it run precmd() again to do so? What if there's stuff in > precmd() that isn't to do with generating the prompt, but is instead > involved in dealing with command history? This is not a problem. When the user is typing a command (even if multiline), the command isn't in the history yet. > You wouldn't want that to run again, because you haven't finished typing > your command. Why not? Or perhaps there should be two different functions: precmd(), which should behave like now, and preprompt(), which should be run just before the prompt is (re)displayed. Then, the code that modifies the prompt should be in preprompt(). -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 0:06 ` get the number of active jobs to show in the prompt? Vincent Lefevre @ 2001-10-03 5:43 ` Bart Schaefer 2001-10-03 14:22 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 5:43 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 2:06am, Vincent Lefevre wrote: } } The current command should be saved in a safe place. Then, the necessary } functions (e.g., precmd()) should be called. Finally, the current command } should be restored and displayed with the new prompt(s). This is the sort of thing that sounds good in theory, but will drive you insane in practice. For some sort of inkling of how it would feel, try using this: function push-line-at-random { local nested=${(%):-%_} zle self-insert print '\n[0] + done pretend a job finished' bindkey $KEYS self-insert bindkey -M $KEYMAP \\$(([##8](RANDOM % 26 + ##a))) push-line-at-random if [[ -n $nested ]] then zle push-line-or-edit zle beep else zle push-input zle send-break fi } zle -N push-line-at-random bindkey \\$(([##8](RANDOM % 26 + ##a))) push-line-at-random Aside from the stuff that Deborah mentioned, most of which is correct, there's the question of what to do when you're at the "bck-i-search:" prompt (or other "minibuffer" prompts), or when you're in menu-select, or when you're in the middle of some long-running user-defined widget such as incremental-complete-word. While someone (not me, this time) is deciding whether they want to attempt to come up with a clean way to deal with all of this, you might look at what you can do with "zle -I" and "zle -M". For example: TRAPCLD() { zle -I && zle -M "jobs: $#jobstates running" } It's too bad that this does two redraws (one for the notify output and again because of `zle -I') but at least it shows the info you want. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 5:43 ` Bart Schaefer @ 2001-10-03 14:22 ` Vincent Lefevre 2001-10-03 14:59 ` Vincent Lefevre 2001-10-03 15:11 ` Bart Schaefer 0 siblings, 2 replies; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 14:22 UTC (permalink / raw) To: zsh-users On Wed, Oct 03, 2001 at 05:43:50 +0000, Bart Schaefer wrote: > This is the sort of thing that sounds good in theory, but will drive you > insane in practice. For some sort of inkling of how it would feel, try > using this: > > function push-line-at-random { > local nested=${(%):-%_} > zle self-insert > print '\n[0] + done pretend a job finished' > bindkey $KEYS self-insert > bindkey -M $KEYMAP \\$(([##8](RANDOM % 26 + ##a))) push-line-at-random > if [[ -n $nested ]] > then > zle push-line-or-edit > zle beep > else > zle push-input > zle send-break > fi > } > zle -N push-line-at-random > bindkey \\$(([##8](RANDOM % 26 + ##a))) push-line-at-random I get errors like push-line-at-random:bindkey:5: no such keymap `\163' But I don't understand what you mean. > Aside from the stuff that Deborah mentioned, most of which is correct, > there's the question of what to do when you're at the "bck-i-search:" > prompt (or other "minibuffer" prompts), or when you're in menu-select, > or when you're in the middle of some long-running user-defined widget > such as incremental-complete-word. I still don't understand the problem. > While someone (not me, this time) is deciding whether they want to > attempt to come up with a clean way to deal with all of this, you might > look at what you can do with "zle -I" and "zle -M". For example: > > TRAPCLD() { zle -I && zle -M "jobs: $#jobstates running" } This doesn't solve my problem: for instance, after a Ctrl-L, the message disappears. I think that the best thing I can do is to put the jobs status directly to the terminal title, and this can be done with TRAPCLD. > It's too bad that this does two redraws (one for the notify output and > again because of `zle -I') but at least it shows the info you want. This is not what I want. I just want the prompt to reflect the jobs status. Currently, my prompt is yellow when there are no jobs, and green when there is at least one job. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 14:22 ` Vincent Lefevre @ 2001-10-03 14:59 ` Vincent Lefevre 2001-10-03 15:11 ` Bart Schaefer 1 sibling, 0 replies; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 14:59 UTC (permalink / raw) To: zsh-users On Wed, Oct 03, 2001 at 16:22:46 +0200, Vincent Lefevre wrote: > This doesn't solve my problem: for instance, after a Ctrl-L, the > message disappears. I think that the best thing I can do is to put > the jobs status directly to the terminal title, and this can be > done with TRAPCLD. I now have the following: precmd() { psvar[1]=$#jobstates; if [[ $psvar[1] -eq 0 ]] then psvar[1]=() elif [[ $psvar[1] -eq 1 ]] then psvar[1]="$psvar[1] job" else psvar[1]="$psvar[1] jobs" fi # Note: STY is set by screen if [[ $TERM == (xterm*|dtterm|rxvt) && -z $STY ]] then print -nP "\e]1;%m:%.\x07" print -nP "\e]2;%(1v. [%1v] .)${WINTITLE:+ [$WINTITLE]} %n@%m - %~ \x07" fi } TRAPCLD() { precmd } -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 14:22 ` Vincent Lefevre 2001-10-03 14:59 ` Vincent Lefevre @ 2001-10-03 15:11 ` Bart Schaefer 2001-10-03 15:35 ` Vincent Lefevre 1 sibling, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 15:11 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 4:22pm, Vincent Lefevre wrote: } } On Wed, Oct 03, 2001 at 05:43:50 +0000, Bart Schaefer wrote: } > } > bindkey -M $KEYMAP \\$(([##8](RANDOM % 26 + ##a))) push-line-at-random } } I get errors like } } push-line-at-random:bindkey:5: no such keymap `\163' Oh, fiddle. $KEYMAP is only in 4.1.0-dev. Just drop that `-M $KEYMAP'. } But I don't understand what you mean. You might if that sample were working. :-/ } > Aside from the stuff that Deborah mentioned, most of which is correct, } > there's the question of what to do when [...] } } I still don't understand the problem. There are two issues: One, I think it's a bad idea in the first place because its potentially very disruptive to the interactive experience. Imagine how you'd feel using, say, "vi" if it were to exit in the middle of you typing a sentence and then start up again with the text you were editing possibly shifted to another part of the screen. It's another matter if this happens on an explicit user action -- you could create your own widget that would redraw the prompt, and bind it to ctrl-L or something. Two, even if I didn't think the resulting interactive experience would be nasty, I don't think the expected benefit is worth the implementation effort. There's much more state to save/restore than just the contents of the editor buffers, and in the case of a user-defined widget it may not even be possible to know what state needs to be saved and restored. } > It's too bad that this does two redraws (one for the notify output and } > again because of `zle -I') but at least it shows the info you want. } } This is not what I want. I just want the prompt to reflect the jobs } status. What I meant was, it puts the equivalent information somewhere that you can see it, even though it's not exactly the implementation that you most desire. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 15:11 ` Bart Schaefer @ 2001-10-03 15:35 ` Vincent Lefevre 2001-10-03 15:58 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 15:35 UTC (permalink / raw) To: zsh-users On Wed, Oct 03, 2001 at 15:11:04 +0000, Bart Schaefer wrote: > There are two issues: One, I think it's a bad idea in the first place > because its potentially very disruptive to the interactive experience. > Imagine how you'd feel using, say, "vi" if it were to exit in the middle > of you typing a sentence and then start up again with the text you were > editing possibly shifted to another part of the screen. But this is not caused by calling a function when the prompt is redisplayed. This is caused by the NOTIFY option. And any user can disable it. In my case, a job shouldn't terminate when I'm typing something in zle, or something bad happened. Perhaps I could disable NOTIFY when zle is active and use TRAPCLD with zle -M in this case. Is it possible? For instance with a setopt nonotify in precmd and a setopt notify in preexec? > It's another matter if this happens on an explicit user action -- you > could create your own widget that would redraw the prompt, and bind it > to ctrl-L or something. How can I do that (to rebuild the prompt when clear-screen is called)? > Two, even if I didn't think the resulting interactive experience would > be nasty, I don't think the expected benefit is worth the implementation > effort. There's much more state to save/restore than just the contents > of the editor buffers, and in the case of a user-defined widget it may > not even be possible to know what state needs to be saved and restored. OK. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 15:35 ` Vincent Lefevre @ 2001-10-03 15:58 ` Bart Schaefer 2001-10-03 16:47 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 15:58 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 5:35pm, Vincent Lefevre wrote: } Subject: Re: get the number of active jobs to show in the prompt? } } On Wed, Oct 03, 2001 at 15:11:04 +0000, Bart Schaefer wrote: } > There are two issues: One, I think it's a bad idea in the first place } > because its potentially very disruptive to the interactive experience. } > Imagine how you'd feel using, say, "vi" if it were to exit in the middle } > of you typing a sentence and then start up again with the text you were } > editing possibly shifted to another part of the screen. } } But this is not caused by calling a function when the prompt is } redisplayed. This is caused by the NOTIFY option. And any user } can disable it. I'm addressing your original question, which, paraphrased, was, "Is there a way to force the prompt to be recomputed rather than just redisplayed when I'm notified that a job has exited? And I want `setopt notify'." If notify isn't involved, precmd is already sufficient. If notify is involved, then the fact that the prompt could change length and that the current "prompt level" could need to change from PS2 or deeper back to PS1, leads to all the objections that have been raised. } Perhaps I could disable NOTIFY when zle is active and use TRAPCLD with } zle -M in this case. Is it possible? For instance with a setopt nonotify } in precmd and a setopt notify in preexec? Unfortunately, installing a TRAPCLD handler forces `notify' to behave as if it were on, even if it's actually off. I reported this to zsh-workers yesterday. } > It's another matter if this happens on an explicit user action -- you } > could create your own widget that would redraw the prompt, and bind it } > to ctrl-L or something. } } How can I do that (to rebuild the prompt when clear-screen is called)? Basically the same way I did it in push-line-at-random: function redraw-prompt { local nested=${(%):-%_} # zle .clear-screen # You may or may not want this if [[ -n $nested ]] then zle .push-line-or-edit else zle .push-input zle .send-break # Force new prompt; sorry about beeping fi } # Pick one: # zle -N clear-screen redraw-prompt # zle -N redraw-prompt; bindkey '^L' redraw-prompt -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 15:58 ` Bart Schaefer @ 2001-10-03 16:47 ` Vincent Lefevre 2001-10-03 17:09 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 16:47 UTC (permalink / raw) To: zsh-users On Wed, Oct 03, 2001 at 15:58:06 +0000, Bart Schaefer wrote: > If notify isn't involved, precmd is already sufficient. Well, I've always had notify and I do want it. > If notify is involved, then the fact that the prompt could change > length and that the current "prompt level" could need to change from > PS2 or deeper back to PS1, leads to all the objections that have > been raised. In my case, the length isn't changed. So, this is not my problem. > } How can I do that (to rebuild the prompt when clear-screen is called)? > > Basically the same way I did it in push-line-at-random: > > function redraw-prompt { > local nested=${(%):-%_} > # zle .clear-screen # You may or may not want this I want this, so I uncommented it. > if [[ -n $nested ]] > then > zle .push-line-or-edit > else > zle .push-input > zle .send-break # Force new prompt; sorry about beeping > fi > } > # Pick one: > # zle -N clear-screen redraw-prompt > # zle -N redraw-prompt; bindkey '^L' redraw-prompt This doesn't work: the screen is cleared, but then, the prompt is printed twice. Replacing "zle .clear-screen" by "clear" almost works. The problem is that push-line seems to send a \n. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 16:47 ` Vincent Lefevre @ 2001-10-03 17:09 ` Bart Schaefer 2001-10-03 19:34 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 17:09 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 6:47pm, Vincent Lefevre wrote: } Subject: Re: get the number of active jobs to show in the prompt? } } > If notify is involved, then the fact that the prompt could change } > length and that the current "prompt level" could need to change from } > PS2 or deeper back to PS1, leads to all the objections that have } > been raised. } } In my case, the length isn't changed. So, this is not my problem. Yes, but to implement a general solution in the ZLE C code, the possibility that the prompt might change length would have to be dealt with. And even if the PS1 prompt doesn't change length, the insertion (or not) of the various PS2 and other prompts could change the screen. } > # zle .clear-screen # You may or may not want this } } I want this, so I uncommented it. } } This doesn't work: the screen is cleared, but then, the prompt is } printed twice. Right, the old prompt and editor input is redisplayed by clear-screen, and then the new prompt is generated and displayed below that. } Replacing "zle .clear-screen" by "clear" almost works. } The problem is that push-line seems to send a \n. Again, that's right. ZLE doesn't know that you've erased the screen with "clear", so it thinks it has to move down past the current editing area before redrawing the new prompt. There's no way to force it to draw the new prompt directly on top of the old one, because of the the length-may-have-changed etc. reasons above. There's also unfortunately no way to get it to regenerate the prompt first and then do clear-screen afterwards, because `send-break' aborts even a user-defined widget in progress. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 17:09 ` Bart Schaefer @ 2001-10-03 19:34 ` Vincent Lefevre 2001-10-03 20:01 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 19:34 UTC (permalink / raw) To: zsh-users On Wed, Oct 03, 2001 at 17:09:26 +0000, Bart Schaefer wrote: > } The problem is that push-line seems to send a \n. > > Again, that's right. ZLE doesn't know that you've erased the screen with > "clear", so it thinks it has to move down past the current editing area > before redrawing the new prompt. Why not having another widget that prints a "\r" instead of a "\n"? -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 19:34 ` Vincent Lefevre @ 2001-10-03 20:01 ` Bart Schaefer 2001-10-03 20:08 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 20:01 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 9:34pm, Vincent Lefevre wrote: > Subject: Re: get the number of active jobs to show in the prompt? > On Wed, Oct 03, 2001 at 17:09:26 +0000, Bart Schaefer wrote: > > } The problem is that push-line seems to send a \n. > > > > Again, that's right. ZLE doesn't know that you've erased the screen with > > "clear", so it thinks it has to move down past the current editing area > > before redrawing the new prompt. > > Why not having another widget that prints a "\r" instead of a "\n"? It's not the widget that's doing it. It's the ZLE internal screen refresh routines. All the widget does is set a flag telling the internals that the current line-editing "session" has terminated; the redraw is invoked upon return to the top of main command input loop. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 20:01 ` Bart Schaefer @ 2001-10-03 20:08 ` Vincent Lefevre 2001-10-03 21:46 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 20:08 UTC (permalink / raw) To: zsh-users In article <011003130131.ZM29770@candle.brasslantern.com>, Bart Schaefer <schaefer@brasslantern.com> wrote: > > Why not having another widget that prints a "\r" instead of a "\n"? > It's not the widget that's doing it. It's the ZLE internal screen refresh > routines. All the widget does is set a flag telling the internals that the > current line-editing "session" has terminated; the redraw is invoked upon > return to the top of main command input loop. OK, so there could be another flag to tell whether to print "\n" or "\r". -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 20:08 ` Vincent Lefevre @ 2001-10-03 21:46 ` Bart Schaefer 2001-10-03 21:51 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 21:46 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 10:08pm, Vincent Lefevre wrote: > > It's not the widget that's doing it. It's the ZLE internal screen refresh > > OK, so there could be another flag to tell whether to print "\n" or "\r". Once again, it's not that simple. It's not just printing a "\n" -- it's moving the cursor to below the current editing area, which could be many lines high. And printing an '\r' instead might still put the new prompt in the middle of said multi-line area. At this point Geoff Wing is the right person to continue this discussion if it's going to be continued, as he's the most recent primary author of the ZLE screen refresh routines. Meanwhile, since you know your own prompt doesn't change size, you could try fooling with something like this: zmodload -i zsh/termcap function redraw-prompt { zle .clear-screen if (( BUFFERLINES < LINES - 1 )) then precmd echotc sc echotc ho print -nP "$PS1" echotc rc fi return 0 } zle -N clear-screen redraw-prompt That'll only work for terminals that have sc/rc (save/restore cursor), and your PS1 better not have %E in it. ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 21:46 ` Bart Schaefer @ 2001-10-03 21:51 ` Bart Schaefer 2001-10-03 23:15 ` Vincent Lefevre 0 siblings, 1 reply; 29+ messages in thread From: Bart Schaefer @ 2001-10-03 21:51 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 3, 2:46pm, Bart Schaefer wrote: > Subject: Re: get the number of active jobs to show in the prompt? > function redraw-prompt { > zle .clear-screen > if (( BUFFERLINES < LINES - 1 )) > then > precmd > echotc sc > echotc ho > print -nP "$PS1" > echotc rc > fi > return 0 > } I just realized you need to add "zle -R" right before the call to "precmd". ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 21:51 ` Bart Schaefer @ 2001-10-03 23:15 ` Vincent Lefevre 2001-10-04 0:05 ` Bart Schaefer 0 siblings, 1 reply; 29+ messages in thread From: Vincent Lefevre @ 2001-10-03 23:15 UTC (permalink / raw) To: zsh-users In article <011003145139.ZM29856@candle.brasslantern.com>, Bart Schaefer <schaefer@brasslantern.com> wrote: > I just realized you need to add "zle -R" right before the call to "precmd". Even with that, there are several problems: _ the %? has a bad value; _ I need to display RPS1 too (if it was displayed before the clear-screen); _ it doesn't work with non-PS1 prompts (with such prompts the current behaviour would be OK for me). -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> - 100% validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des Jeux Mathématiques et Logiques, TETRHEX, etc. Work: CR INRIA - computer arithmetic / SPACES project at LORIA ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: get the number of active jobs to show in the prompt? 2001-10-03 23:15 ` Vincent Lefevre @ 2001-10-04 0:05 ` Bart Schaefer 0 siblings, 0 replies; 29+ messages in thread From: Bart Schaefer @ 2001-10-04 0:05 UTC (permalink / raw) To: Vincent Lefevre, zsh-users On Oct 4, 1:15am, Vincent Lefevre wrote: > > Even with that, there are several problems: At this point: Left as exercises for the interested party. ^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2001-10-04 0:05 UTC | newest] Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-10-01 5:56 get the number of active jobs to show in the prompt? Drew Perttula 2001-10-01 6:09 ` Goran Koruga 2001-10-01 6:12 ` Sweth Chandramouli 2001-10-01 6:37 ` Phil Pennock 2001-10-01 6:59 ` Drew Perttula 2001-10-01 7:08 ` Sweth Chandramouli 2001-10-01 8:28 ` Deborah Ariel Pickett 2001-10-01 9:04 ` Phil Pennock 2001-10-01 17:44 ` Vincent Lefevre 2001-10-02 15:43 ` Bart Schaefer 2001-10-02 16:13 ` Vincent Lefevre 2001-10-02 23:25 ` Deborah Ariel Pickett 2001-10-02 23:29 ` unsubscribe me Matthew Lyon 2001-10-03 0:06 ` get the number of active jobs to show in the prompt? Vincent Lefevre 2001-10-03 5:43 ` Bart Schaefer 2001-10-03 14:22 ` Vincent Lefevre 2001-10-03 14:59 ` Vincent Lefevre 2001-10-03 15:11 ` Bart Schaefer 2001-10-03 15:35 ` Vincent Lefevre 2001-10-03 15:58 ` Bart Schaefer 2001-10-03 16:47 ` Vincent Lefevre 2001-10-03 17:09 ` Bart Schaefer 2001-10-03 19:34 ` Vincent Lefevre 2001-10-03 20:01 ` Bart Schaefer 2001-10-03 20:08 ` Vincent Lefevre 2001-10-03 21:46 ` Bart Schaefer 2001-10-03 21:51 ` Bart Schaefer 2001-10-03 23:15 ` Vincent Lefevre 2001-10-04 0:05 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).