zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: vogt@linux.vnet.ibm.com, Zsh Users <zsh-users@zsh.org>
Subject: Re: Help with directory switching functions
Date: Sat, 28 Nov 2015 10:54:28 -0800	[thread overview]
Message-ID: <151128105428.ZM27762@torch.brasslantern.com> (raw)
In-Reply-To: <20151124103239.GA31057@linux.vnet.ibm.com>

On Nov 24, 11:32am, Dominik Vogt wrote:
}
} I'm trying to write a function that alternately switches between
} two directories.  With "+-" I can repeatedly switch between the
} current directory and the last one where I did anything (type any
} command except switching directories).

[...]

} The function makes use of the chpwd and precmd functions.
} 
} Problems:
} 
} 1. Command lines with multiple command cannot be handled properly
}    because precmd is just called once for the line, not for each
}    command.

If you really need to sneak in before (or after) each command rather
than just each command line, read up on TRAPDEBUG, but see below.

} 2. Depending on $HISTCMD is a bit hacky.  What I'd really want to
}    do is to look at the command being executed and decide
}    individually which commands are "interesting" enough to warrant
}    recording the current directory.

If you use preexec instead of precmd you can examine the command line
instead of just examining the history event number.  I think that
would allow you to start with _IS_CWD_INTERESTING="0" and only set it
to 1 when something interesting happens (if I read correctly right
now, you assume interesting and then zero it in chpwd if nothing else
has happened yet).

Also note that preexec would happen before chpwd, so you'd need some
other corresponding logic changes.

} 3. I'd prefer a shell builtin instead of "readlink".

    _PWD_A="$PWD:A"

Or if not that, why not?

Also, possibly use "cd -q" in _swapdir to avoid running chpwd (the work
will already have been done in preexec, I think).

Finally, you might consider using the directory stack; push each of the
directories that seems interesting, and then you can pop back through
them, rather than only having the two most recent to swap between.


  reply	other threads:[~2015-11-28 18:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 10:32 Dominik Vogt
2015-11-28 18:54 ` Bart Schaefer [this message]
2015-11-30 10:48   ` Dominik Vogt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151128105428.ZM27762@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=vogt@linux.vnet.ibm.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).