* PATCH: Support file url in _urls @ 1999-10-07 11:42 Oliver Kiddle 1999-10-07 11:47 ` Zefram 1999-10-07 13:21 ` Tanaka Akira 0 siblings, 2 replies; 5+ messages in thread From: Oliver Kiddle @ 1999-10-07 11:42 UTC (permalink / raw) To: Zsh workers Following is a patch to _urls to allow it to support the file url: file://<tab> will complete from .zsh/urls as for http/ftp file:/<tab> will complete files from root file:<tab> inserts the current directory. I find this behaviour (which is done in the compctl example) extremely useful. There is one slight problem: if the current directory is root then the compadd -S '/' ~+ line will add two slashes - one for the current directory '/' and one for the suffix. I can't think of a simple way off the top of my head to chop any trailing slash off the end of ~+. What is the bookmark url scheme? Is it something specific to Netscape or Lynx because if so, handling of it should move to _lynx/_netscape. Or, maybe we need to provide a way of specifying which url schemes are supported. Lynx supports a finger url for example. I'm not entirely convinced by the system of taking urls from a directory structure. At the least I think there should be an alternative. For example, if $compconfig[urls_path] doesn't exist, the basic host names should complete after (http|file|ftp)://. I would also like a compconfig option which says that the local host is a web server, named X, doc root in Y and users own web pages in directory Z within their home so files on a local web server are completed. One thing which I would like to implement is to restrict file types used with urls. This would probably depend upon the browser (Netscape handles graphics, Lynx doesn't etc) but the parameters to _url are passed to both _files and compadd so I'm restricted in what I can do here. Shouldn't _webbrowser be ditched and the first line of _urls be changed to the #compdef - it would be cleaner in my opinion. The only problem is that the -f option would be lost for those commands. We could always negate its meaning though. Any comments? Oliver Kiddle *** Completion/User/_urls.bak Thu Oct 7 12:03:33 1999 --- Completion/User/_urls Thu Oct 7 12:33:20 1999 *************** *** 46,58 **** scheme="${PREFIX%%:*}" compset -P "[-+.a-z0-9]#:" else ! compadd "$@" -S '' http:// ftp:// bookmark: return fi case "$scheme" in ! http) compset -P // || { compadd "$@" -S '' //; return };; ! ftp) compset -P // || { compadd "$@" -S '' //; return };; esac if [[ "$scheme" = bookmark && --- 46,68 ---- scheme="${PREFIX%%:*}" compset -P "[-+.a-z0-9]#:" else ! compadd "$@" -S '' http:// ftp:// bookmark: file: return fi case "$scheme" in ! http|ftp) compset -P // || { compadd "$@" -S '' //; return };; ! file) ! if [[ -prefix // ]]; then ! compset -P // ! elif [ -prefix / ]; then ! _files "$@" ! return ! elif [ ! "$PREFIX" ]; then ! compadd -S '/' ~+ ! return ! fi ! ;; esac if [[ "$scheme" = bookmark && ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: Support file url in _urls 1999-10-07 11:42 PATCH: Support file url in _urls Oliver Kiddle @ 1999-10-07 11:47 ` Zefram 1999-10-07 13:21 ` Tanaka Akira 1 sibling, 0 replies; 5+ messages in thread From: Zefram @ 1999-10-07 11:47 UTC (permalink / raw) To: Oliver Kiddle; +Cc: zsh-workers Oliver Kiddle wrote: > I can't think of a simple way off >the top of my head to chop any trailing slash off the end of ~+. ${PWD%/} -zefram ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: Support file url in _urls 1999-10-07 11:42 PATCH: Support file url in _urls Oliver Kiddle 1999-10-07 11:47 ` Zefram @ 1999-10-07 13:21 ` Tanaka Akira 1999-10-07 13:26 ` Adam Spiers 1 sibling, 1 reply; 5+ messages in thread From: Tanaka Akira @ 1999-10-07 13:21 UTC (permalink / raw) To: Zsh workers In article <37FC873C.F3257422@u.genie.co.uk>, Oliver Kiddle <opk@u.genie.co.uk> writes: > What is the bookmark url scheme? Is it something specific to Netscape or > Lynx because if so, handling of it should move to _lynx/_netscape. Or, > maybe we need to provide a way of specifying which url schemes are supported. > Lynx supports a finger url for example. Try zsh% mkdir -p ~/.zsh/urls/bookmark/list zsh% echo http://www.zsh.org/mla/ > ~/.zsh/urls/bookmark/list/zsh zsh% lynx bookmark:list/zsh<TAB> -> zsh% lynx http://www.zsh.org/mla/ This is zsh level bookmark implementation and not browser specific. > I'm not entirely convinced by the system of taking urls from a directory > structure. At the least I think there should be an alternative. For > example, if $compconfig[urls_path] doesn't exist, the basic host names > should complete after (http|file|ftp)://. I would also like a compconfig > option which says that the local host is a web server, named X, doc root > in Y and users own web pages in directory Z within their home so files on > a local web server are completed. Sounds good. > Shouldn't _webbrowser be ditched and the first line of _urls be changed > to the #compdef - it would be cleaner in my opinion. The only problem is > that the -f option would be lost for those commands. We could always > negate its meaning though. I think _urls should complete only URLs by default. And its default behaviour may be useful for web grabbers such as wget, htget, GET, HEAD, curl, etc. There is _wget for wget, though. -- Tanaka Akira ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: Support file url in _urls 1999-10-07 13:21 ` Tanaka Akira @ 1999-10-07 13:26 ` Adam Spiers [not found] ` <14332.42410.2764.422238@kevins> 0 siblings, 1 reply; 5+ messages in thread From: Adam Spiers @ 1999-10-07 13:26 UTC (permalink / raw) To: Zsh workers Tanaka Akira (akr@jaist.ac.jp) wrote: > In article <37FC873C.F3257422@u.genie.co.uk>, > Oliver Kiddle <opk@u.genie.co.uk> writes: > > > What is the bookmark url scheme? Is it something specific to Netscape or > > Lynx because if so, handling of it should move to _lynx/_netscape. Or, > > maybe we need to provide a way of specifying which url schemes are supported. > > Lynx supports a finger url for example. > > Try > > zsh% mkdir -p ~/.zsh/urls/bookmark/list > zsh% echo http://www.zsh.org/mla/ > ~/.zsh/urls/bookmark/list/zsh > zsh% lynx bookmark:list/zsh<TAB> > -> > zsh% lynx http://www.zsh.org/mla/ > > This is zsh level bookmark implementation and not browser specific. Incidentally, I've recently written a Perl module which parses Netscape bookmark files, and a program which harnesses this to generate the ~/.zsh/urls hierarchy. It will be more freely available when I get around to CPANifying the module, but for now if anyone's interested in it, drop me a mail. ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <14332.42410.2764.422238@kevins>]
* PATCH: automatically generate ~/.zsh/urls for use with _urls [not found] ` <14332.42410.2764.422238@kevins> @ 1999-11-09 2:13 ` Adam Spiers 0 siblings, 0 replies; 5+ messages in thread From: Adam Spiers @ 1999-11-09 2:13 UTC (permalink / raw) To: Kevin Sullivan; +Cc: zsh workers mailing list Kevin Sullivan (kevins@mediaone.net) wrote: > Adam Spiers writes: > > Incidentally, I've recently written a Perl module which parses > > Netscape bookmark files, and a program which harnesses this to > > generate the ~/.zsh/urls hierarchy. It will be more freely available > > when I get around to CPANifying the module, but for now if anyone's > > interested in it, drop me a mail. > > I am certainly very interested... Apologies for the delay on this. I've finally CPANified the module (about to upload it to PAUSE now, but you can get it from http://www.new.ox.ac.uk/~adam/computing/URI-Bookmarks/ in the mean-time). This patch addes the program which creates the ~/.zsh/urls hierarchy. I hope that license is OK; if not I'll change it to something that is. Index: Misc/make-zsh-urls =================================================================== +++ Misc/make-zsh-urls Tue Nov 9 02:03:33 1999 @@ -0,0 +1,157 @@ +#!/usr/bin/perl -w +# +# $Id: make-zsh-urls,v 1.4 1999/11/09 02:02:29 localadams Exp $ + +use strict; + +=head1 NAME + +make-zsh-urls -- create F<~/.zsh/urls> hierarchy + +=head1 SYNOPSIS + +% make-zsh-urls [B<OPTION>] ... + +=head1 DESCRIPTION + +make-zsh-urls creates a hierarchy of files and directories under +F<~/.zsh/urls> for use by the _urls completion function in the new +completion system of zsh 3.1.6 and higher. + +It needs the B<URI::Bookmarks> suite of modules to run, which are +available from CPAN, the Comprehensive Perl Archive Network. +See B<http://www.perl.com/cpan> or L<CPAN> for more information. + +The following options are available: + +B<--output-dir>, B<-o> Specify the output directory for the + hierarchy. Defaults to F<~/.zsh/urls>. + +B<--input-file>, B<-i> Specify the input bookmarks file. + Defaults to F<~/.netscape/bookmarks.html>. + +B<--root-node>, B<-r> Specify which folder contains the + bookmarks which the hierarchy will be + created from. Defaults to the root + of the bookmark collection tree. + +=cut + +use Getopt::Long; +use URI::Bookmarks::Netscape; +use URI; + +my ($out_dir, $input_file, $root_name, $help); +GetOptions('output-dir|o=s' => \$out_dir, + 'input-file|i=s' => \$input_file, + 'root-node|r=s' => \$root_name, + 'help|h' => \$help) + or usage(); + +usage() if $help; + +$out_dir ||= "$ENV{HOME}/.zsh/urls"; +$input_file ||= "$ENV{HOME}/.netscape/bookmarks.html"; + +my $bookmarks = + new URI::Bookmarks(file => $input_file); + +my $root = $bookmarks->tree_root(); +if ($root_name) { + my @root_nodes = $bookmarks->name_to_nodes($root_name); + if (@root_nodes == 0) { + die "Couldn't find any nodes with name `$root_name'; aborting.\n"; + } + else { + if (@root_nodes > 1) { + warn "Found more than one node with name `$root_name'; " . + "taking first occurrence.\n"; + } + $root = $root_nodes[0]; + } +} + +my @bookmark_path = (); +$root->walk_down({callback => \&pre_callback, + callbackback => \&post_callback}); + +sub pre_callback { + my ($node, $options) = @_; + + my $depth = $options->{_depth} || 0; + my $name = $node->name; + my $type = $node->type; + + if ($type eq 'bookmark') { + my $url = $node->attribute->{'HREF'}; + + # Type A + my $full = $url; + $full =~ s@^(https?|ftp|gopher)://@"\L$1/"@ei; + $full =~ s@file:@@i; + my ($path, $file) = $full =~ m@(.+)/(.*)@; + # This is horribly inefficient but I'm too lazy to reimplement mkdir -p + # Why isn't there a CPAN module for it? + system '/bin/mkdir', '-p', "$out_dir/$path" unless -d "$out_dir/$path"; + system 'touch', "$out_dir/$path" unless $full eq "$path/"; + + # Type B + $name =~ s@/@-@g; + my $bookmark_file = "$out_dir/bookmark/" . + (join '/', @bookmark_path) . + "/$name"; + open(BOOKMARK, ">$bookmark_file") or die "open >$bookmark_file: $!"; + print BOOKMARK $url, "\n"; + close(BOOKMARK) or die $!; + } + elsif ($type eq 'folder' && $depth > 0) { + print +(' ' x ($depth - 1)), "Processing folder `$name' ...\n"; + push @bookmark_path, $name; + + # Type B + system '/bin/mkdir', + '-p', + "$out_dir/bookmark/" . + (join '/', @bookmark_path); + } + + return 1; +} + +sub post_callback { + my ($node, $options) = @_; + + my $type = $node->type; + + if ($type eq 'folder') { + my $name = pop @bookmark_path; + } +} + +sub usage { + print <<EOF; +Usage: make-zsh-urls [OPTION] ... + --help, -h Display this help. + --output-dir, -o Specify the output directory for the hierarchy. + Defaults to ~/.zsh/urls. + --input-file, -i Specify the input bookmarks file. + Defaults to ~/.netscape/bookmarks.html. + --root-node, -r Specify which folder contains the bookmarks which + the hierarchy will be created from. Defaults to + the root of the bookmark collection tree. +EOF + exit 0; +} + + +=head1 AUTHOR + + Adam Spiers <adam@spiers.net> + +=head1 COPYRIGHT + + Copyright (c) 1999 Adam Spiers <adam@spiers.net>. All rights + reserved. This program is free software; you can redistribute it and/or + modify it under the same terms as Perl or zsh. + +=cut ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1999-11-09 2:13 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1999-10-07 11:42 PATCH: Support file url in _urls Oliver Kiddle 1999-10-07 11:47 ` Zefram 1999-10-07 13:21 ` Tanaka Akira 1999-10-07 13:26 ` Adam Spiers [not found] ` <14332.42410.2764.422238@kevins> 1999-11-09 2:13 ` PATCH: automatically generate ~/.zsh/urls for use with _urls Adam Spiers
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).