Skip to content

Commit

Permalink
Add filesearch subcommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
kou1okada committed Oct 1, 2019
1 parent 1c8bc48 commit 4d438de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -61,6 +61,7 @@ Usage
| `mark-showmanual` | Print the list of manually installed packages. |
| `call [<internal_function> [<args> ...]]` | Call internal function in apt-cyg. |
| `time [<internal_function> [<args> ...]]` | Report time consumed to call internal function in apt-cyg. |
| `filesearch [<pattern>]` | File search like apt-file search. |

### Options

Expand Down
25 changes: 25 additions & 0 deletions apt-cyg
Expand Up @@ -251,6 +251,7 @@ function usage()
time [<internal_function> [<args> ...]] :
Report time consumed
to call internal function in apt-cyg.
filesearch [<pattern>] : File search like apt-file search.
Options:
--ag : use the silver searcher
(currently work only at packageof subcommand)
Expand Down Expand Up @@ -1767,6 +1768,30 @@ function apt-cyg-time () # [<internal_function> [<args> ...]]
time "$@"
}

function apt-cyg-filesearch () # [<pattern>]
# File search like apt-file search
{
local arch cachedir cachefile cachequery colmns line package packages url
arch="$(current_cygarch)"
cachedir="/tmp/.apt-cyg.cache/filesearch"
cachequery="$cachedir/$(sha256sum <<<"$1"|awk '$0=$1')"
mkdir -p "$cachedir"

[ ! -e "$cachequery" ] && cygcheck -p "$1" >"$cachequery"
readarray -t packages < "$cachequery"
packages=( "${packages[@]:1}" )
for line in "${packages[@]}"; do
columns=( $line )
url="https://cygwin.com/packages/$arch/${columns[0]%%-[0-9]*}/${columns[0]}"
cachefile="$cachedir/$(mirror_to_mirrordir "$url")"
[ ! -e "$cachefile" ] && wget -qO"$cachefile" "$url"
echo -n "${columns[0]}"
awk '/<\/pre>/{f=0}/<pre>/{f=1}f' "$cachefile" \
| grep -E "$1" \
| awk '($1=$2=$3="")||1'
done
}

PACKAGEOF_CACHE="/tmp/.apt-cyg-packageof.cache.gz"
function update_packageof_cache ()
{
Expand Down

0 comments on commit 4d438de

Please sign in to comment.