Output of bash dirs command vs. emacs

Randall R Schulz rrschulz@cris.com
Wed Feb 19 19:27:00 GMT 2003


Nix,

Consider:

% help dirs
dirs: dirs [-clpv] [+N] [-N]
     Display the list of currently remembered directories.  Directories
     find their way onto the list with the `pushd' command; you can get
     back up through the list with the `popd' command.

     The -l flag specifies that `dirs' should not print shorthand versions
     of directories which are relative to your home directory.  This means
     that `~/bin' might be displayed as `/homes/bfox/bin'.  The -v flag
     causes `dirs' to print the directory stack with one entry per line,
     prepending the directory name with its position in the stack.  The -p
     flag does the same thing, but the stack position is not prepended.
     The -c flag clears the directory stack by deleting all of the elements.

     +N  displays the Nth entry counting from the left of the list shown by
         dirs when invoked without options, starting with zero.

     -N  displays the Nth entry counting from the right of the list shown by
         dirs when invoked without options, starting with zero.


An example:

% dirs -v
  0  /d/Program Files
  1  /c/SD/tau/src/tau/io
  2  /c/SD/tau/src/tau/fol
  3  /c/SD/tau/src/tau/tkb
  4  /c/SD/tau/src/tau/web

% dirs -v |sed -e 's/^ *[0-9]* *//'
/d/Program Files
/c/SD/tau/src/tau/io
/c/SD/tau/src/tau/fol
/c/SD/tau/src/tau/tkb
/c/SD/tau/src/tau/web

% dirs -v |sed -e 's/^ *[0-9]* *//' -e $'s/\([ \t&*(){}|"\'<>?]\)/\\\\\\1/g'
/d/Program\ Files
/c/SD/tau/src/tau/io
/c/SD/tau/src/tau/fol
/c/SD/tau/src/tau/tkb
/c/SD/tau/src/tau/web

% dirs -v |sed -e 's/^ *[0-9]* *//' -e $'s/^.*[ \t&*(){}|"\'<>?].*$/\'&\'/g'
'/d/Program Files'
/c/SD/tau/src/tau/io
/c/SD/tau/src/tau/fol
/c/SD/tau/src/tau/tkb
/c/SD/tau/src/tau/web


The character class show here as requiring escaping was haphazardly by 
scanning the keyboard. If you're going to embed this technique in a 
script or some elisp code in Emacs, I'd take the time to carefully sort 
out exactly which characters requires escaping or quoting.


Does that make "dirs" useful for your purposes?

None of this is really Cygwin-specific, just more likely to turn up 
under Windows.

Randall Schulz


At 06:03 2003-02-19, Ixnay Amenay wrote:

>The output of the 'dirs' builtin does not escape space characters:
>
>bash> dirs
>~/program files ~/src/emacs
>bash>
>
>This breaks the M-x dirs function of both cygwin emacs and NT emacs.
>
>I believe this to be a bash bug: There is no way for emacs (or 
>anything else) to parse the output of dirs and disambiguate "space 
>used as delimiter" vs. "space in the directory name".


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list