zsh-users
 help / color / mirror / code / Atom feed
* Re: Fix up the history upon "fg"
@ 2001-04-10  4:43 Felix Rosencrantz
  2001-04-10  7:48 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Rosencrantz @ 2001-04-10  4:43 UTC (permalink / raw)
  To: zsh-workers

That's a pretty useful function.  I guess I would sort of also like the inverse
function, you type a command, and if the same command line is already running
(including same CWD) the shell does a fg rather than run the command.

This sort of command would be useful for a wrapper around something like vim or
other commands that don't like you having multiple instances running for the
same file (or other resource.)

Also, it wouldn't be too hard to make getjobs() also print an appropriate "cd"
to the command if the CWD is not the same.

I guess I would like a way to add attributes to history.  I tend to use
pushd/popd and ~1,~2 etc.  But when I look back at history it can be impossible
to tell what directory I was in at the time the command was run. It would be
nice if zsh could store the CWD information along with the history.  Of course,
this could require a lot more memory usage.   It would be useful if this
information was kept like the time data, where it is printed only when wanted.

-FR.

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Fix up the history upon "fg"
  2001-04-10  4:43 Fix up the history upon "fg" Felix Rosencrantz
@ 2001-04-10  7:48 ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-04-10  7:48 UTC (permalink / raw)
  To: zsh-workers

On Apr 9,  9:43pm, Felix Rosencrantz wrote:
} Subject: Re: Fix up the history upon "fg"
}
} That's a pretty useful function. I guess I would sort of also like the
} inverse function, you type a command, and if the same command line is
} already running (including same CWD) the shell does a fg rather than
} run the command.

A slightly extended version of `setopt auto_resume'.

You'd need to have preexec stash the command line for you somewhere, so
that you could compare against $jobtexts inside the wrapper function.  You
need the alias-expanded command line (see Wayne's recent patch in 13933).

} It would be nice if zsh could store the CWD information along with the
} history.

Cutesy trick:

    precmd() {
	local bufstack
	read -z bufstack && print -z "$bufstack" || print -z ": $PWD; "
    }

-- 
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] 3+ messages in thread

* Fix up the history upon "fg"
@ 2001-04-04 22:41 Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-04-04 22:41 UTC (permalink / raw)
  To: zsh-users

Here's a possibly-handy function.  When you use "fg" or "bg" (or one of
the abbreviations, e.g. "%+"), "getjobs" finds the original text of that
command and inserts it into the history, so that e.g., "!!" will execute
that command again rather than executing "fg" again.

If you use several arguments to "fg", e.g. "fg %2 %3 %1", the commands
for all those jobs are collected and concatenated with semicolons.

Arguably this could be implemented in C as an optional behavior of bin_fg,
so the fg command itself could be removed from the history and replaced
with the job text; but I'm not feeling that ambitious today.

This requires at least zsh-3.1.9, I think.  Definitely not 3.0.anything.

    # Call this from the preexec function like so:
    #   preexec() {
    #	  getjobs "${(z)1}"
    #   }
    getjobs () {
	setopt localoptions noshwordsplit noksharrays
	local texts
	case $1 in
	    fg|bg) shift; [[ -n $1 ]] || set -- %% ;;
	    %*) ;;
	    *) return 0 ;;
	esac
	repeat $#
	do
	    # This case statement emulates jobs.c:getjob()
	    case $1 in
		%(|[%+])) 1=${(k)jobstates[(r)*:+:*]} ;;
		%-) 1=${(k)jobstates[(r)*:-:*]} ;;
		%<->) 1=${1#%} ;;
		%[?]*) 1=${${(Ok)jobtexts[(R)*${1#%[?]}*]}[1]} ;;
		*) 1=${${(Ok)jobtexts[(R)$1*]}[1]} ;;
	    esac
	    [[ -n $1 ]] && texts=($texts ${jobtexts[$1]})
	    shift
	done
	# Remove the "-s" below if you'd prefer that this just report
	# what jobs are being affected rather than modify the history
	(( $#texts )) && print -s ${(j:; :)texts}
	return 0
    }

-- 
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] 3+ messages in thread

end of thread, other threads:[~2001-04-10  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-10  4:43 Fix up the history upon "fg" Felix Rosencrantz
2001-04-10  7:48 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2001-04-04 22:41 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).