From 135d72ac87f20a164c3e29de186dfa642d3b650b Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 20 Mar 2015 16:13:08 +0100 Subject: wibble --- bash-completion.sh | 10 +++++----- icevault | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bash-completion.sh b/bash-completion.sh index 536ca2d..34ed969 100644 --- a/bash-completion.sh +++ b/bash-completion.sh @@ -54,18 +54,18 @@ _icevault() { fi [ $(($OPTIND + 1)) -lt $cword ] && return - local colon_word= + local trim= if [ -z "$cur" -a $OPTIND -eq $cword ] || [ -z "$cur" -a $(($OPTIND + 1)) -eq $cword -a "${words[OPTIND]}" = fill ]; then cur="$(./icevault _geturi)"/ # get URI from webpage else cur=$(dequote "$cur") # trim words with : or = in $COMP_WORDBREAKS; see __ltrim_colon_completions if [[ "$cur" == *[:=]* && "$COMP_WORDBREAKS" == *:* && "$COMP_WORDBREAKS" == *=* ]]; then - colon_word=${cur%"${cur##*[:=]}"} + trim=${cur%"${cur##*[:=]}"} elif [[ "$cur" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then - colon_word=${cur%"${cur##*:}"} + trim=${cur%"${cur##*:}"} elif [[ "$cur" == *=* && "$COMP_WORDBREAKS" == *=* ]]; then - colon_word=${cur%"${cur##*=}"} + trim=${cur%"${cur##*=}"} fi fi @@ -74,7 +74,7 @@ _icevault() { compopt -o filenames -o noquote while read -r -d $'\0' uri; do # quote manually (so we don't quote the : and =) - uri=$( echo "${uri#$colon_word}" | sed "s/[][\\{}*?~<>;'\"|&()\!$\` \t]/\\\\&/g" ) + uri=$( echo "${uri#$trim}" | sed "s/[][\\{}*?~<>;'\"|&()\!$\` \t]/\\\\&/g" ) COMPREPLY+=( "$uri" ) done < <(./icevault -0 _complete "$cur") [ "${#COMPREPLY[@]}" -eq 1 -a "${COMPREPLY[0]: -1:1}" = / ] && compopt -o nospace diff --git a/icevault b/icevault index eb073cb..800f8a2 100755 --- a/icevault +++ b/icevault @@ -24,7 +24,7 @@ use Getopt::Long qw/:config posix_default no_ignore_case gnu_compat bundling auto_version/; use Encode qw/decode_utf8 encode_utf8/; use I18N::Langinfo (); -use List::Util qw/any first min none/; +use List::Util qw/all any first min none/; # Clean up PATH, and set TMPDIR to a ramdisk's mountpoint if possible @@ -285,15 +285,16 @@ sub complete($;$) { return @matches if $all or $#matches < 1; # find the longest common prefix to determine the depth level of completion - my $p = $matches[0]; - do { chop $p until /\A\Q$p\E/ } foreach @matches; + $matches[0] =~ /\A([A-Za-z0-9-]+):\/\/([^\P{Graph}:\/]+(?::\d+)?)\// or die; + ($s, $h) = ($1, $2); - if ($p =~ /\A[A-Za-z0-9-]+:\/\/[^\P{Graph}:\/]+(?::\d+)?\//) { - } elsif ($p =~ /\A[A-Za-z0-9-]+:\/\//) { + if (all { /\A\Q$s\E:\/\/\Q$h\E\// } @matches) { # common host: list all ids + } elsif (all { /\A\Q$s\E:\/\// } @matches) { # common scheme: list only hosts s#/[^\P{Print}\/]+\z#/# foreach @matches; - } elsif (defined $s) { + } else { # no common scheme: list only schemes s#://[^\P{Graph}\/]+/[^\P{Print}\/]+\z#://# foreach @matches; } + my %matches = map {( $_ => 1 )} @matches; return keys %matches; } -- cgit v1.2.3