LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Tags used in this thread
Popular LQ Tags , , ,

Reply
 
Thread Tools
Old 05-18-2009, 02:32 AM   #1
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 276
Thanked: 16
My little script for pkg search


[Log in to get rid of this advertisement]
The first one is to search the package name with certain patterns:
pkgls:
Code:
#!/bin/zsh
# file name: pkgls

usage="Usage: pkgls [options] <exp>
ls the package name with pattern <exp>

pkgls use grep to filter the names. See man grep for more info about options
and expressions. pkgls already set --color=auto --no-filename for grep."

[[ $ARGC -eq 0 || $1 == '--help' ]] && {echo $usage; exit 2}

packages_path='/var/log/packages'

cd ${packages_path} 2>/dev/null || {echo ${packages_path}' not accessible'; exit 1}
echo -e '\e[0;32;1mmtime:           package name:\e[0m'
ls -hcogG1 --time-style=long-iso --sort=time | \
sed -e '1d' -e 's/ \{1,\}/ /g' | cut -f4- -d' ' | \
grep --color=auto --no-filename $@ -
The second one is search a file name belongs to which package:
pkgrep
Code:
#!/bin/zsh
# file name: pkgrep

packages_path='/var/log/packages'
ls='/bin/ls'

cd ${packages_path} 2>/dev/null || {echo ${packages_path}' not accessible'; exit 1}
grep --color=auto --with-filename $@ *

#echo
#echo 'in script:'
#echo
#(cd /var/log/scripts && grep --color=tty $@ *)
pkgless
Code:
#!/bin/zsh
# file name: pkgview

usage="Usage: pkgview [options] <exp>
view the info and content of package matching pattern <exp>

pkgview use grep to filter the names and view(part of vim) for viewing the info
so you don't have write permittion to the files. See man grep for more info
about options and expressions."

[[ $ARGC -eq 0 || $1 == '--help' ]] && {echo $usage; exit 2}

packages_path='/var/log/packages'
ls='/bin/ls'

cd ${packages_path} 2>/dev/null || {echo ${packages_path}' not accessible'; exit 1}

file_names=($($ls | grep --color=auto --no-filename $* - ))
[[ $file_names == '' ]] && {echo 'no package found'; exit 2}
view -p ${file_names}
These are very easy and small scripts.The main feature is that you can take the advantage of grep directly!~ I found them useful in some cases so I put them here. Attachment is the screen shot.
Attached Images
File Type: png 抓图8.png (205.7 KB, 58 views)

Last edited by grissiom; 06-18-2009 at 09:23 AM..
grissiom is offline  
Tag This Post , , ,
Reply With Quote
Thanked by:
Old 06-18-2009, 02:40 AM   #2
Andy Alkaline
Member
 
Registered: Jun 2004
Location: Minnesota
Distribution: Slackware 12.2
Posts: 78
Thanked: 2
pkgsearch

Very handy, thanks.

I made a modification so both scripts would be merged into one.

Code:
#!/bin/sh
# file name: pkgsearch
# Based on pkgls and pkgrep by grissiom
# http://www.linuxquestions.org/user/grissiom-406049/
# June 17, 2009

pkgls() {

# file name: pkgls

(cd ${packages_path} 2>/dev/null || echo ${packages_path}' not accessible' || exit 1
echo -e '\e[0;32;1mmtime:           package name:\e[0m'
ls -hcogG1 --time-style=long-iso --sort=time --color=always | \
sed -e 's/[rwxs-]\{10\} *[0-9]* *[0-9.KMG]* *//'  | \
grep --color=always $@ )
	}

pkgrep() {

# file name: pkgrep

(cd ${packages_path} 2>/dev/null || echo ${packages_path}' not accessible' || exit 1
grep --color=always $@ *)

#echo
#echo 'in script:'
#echo
#(cd /var/log/scripts && grep --color=tty $@ *)
	}


packages_path='/var/log/packages'


while getopts ":lg" Option
do

case $Option in
    l     ) shift;pkgls $@;;
    g     ) shift;pkgrep $@;;
    *     ) echo "Unimplemented option chosen.";;   # DEFAULT
  esac
done

shift $(($OPTIND - 1))
Andy Alkaline is offline     Reply With Quote
Old 06-18-2009, 06:44 AM   #3
Noddegamra
LQ Newbie
 
Registered: Feb 2009
Location: California
Distribution: Slackware
Posts: 20
Thanked: 0
A while ago a whipped up a quick script that was basically just "ls /var/log/packages | grep $1," but I think I like yours more. Particularly pkgrep.

Thanks. :-)
Noddegamra is offline     Reply With Quote
Old 06-18-2009, 07:51 AM   #4
sleekslack
LQ Newbie
 
Registered: Mar 2008
Location: Bangkok, Thailand
Distribution: Slackware 13.0
Posts: 29
Thanked: 0
Nice. I like it. Remind me of something like pkg_info in FreeBSD
sleekslack is offline     Reply With Quote
Old 06-18-2009, 09:20 AM   #5
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 276
Thanked: 16

Original Poster
I'm very happy you like those little stuff I also made some local changes and add a pkgless script. Here are theyI will update the first post as well)

pkgls:
Code:
#!/bin/zsh
# file name: pkgls

usage="Usage: pkgls [options] <exp>
ls the package name with pattern <exp>

pkgls use grep to filter the names. See man grep for more info about options
and expressions. pkgls already set --color=auto --no-filename for grep."

[[ $ARGC -eq 0 || $1 == '--help' ]] && {echo $usage; exit 2}

packages_path='/var/log/packages'

cd ${packages_path} 2>/dev/null || {echo ${packages_path}' not accessible'; exit 1}
echo -e '\e[0;32;1mmtime:           package name:\e[0m'
ls -hcogG1 --time-style=long-iso --sort=time | \
sed -e '1d' -e 's/ \{1,\}/ /g' | cut -f4- -d' ' | \
grep --color=auto --no-filename $@ -
pkgrep
Code:
#!/bin/zsh
# file name: pkgrep

packages_path='/var/log/packages'
ls='/bin/ls'

cd ${packages_path} 2>/dev/null || {echo ${packages_path}' not accessible'; exit 1}
grep --color=auto --with-filename $@ *

#echo
#echo 'in script:'
#echo
#(cd /var/log/scripts && grep --color=tty $@ *)
pkgless
Code:
#!/bin/zsh
# file name: pkgview

usage="Usage: pkgview [options] <exp>
view the info and content of package matching pattern <exp>

pkgview use grep to filter the names and view(part of vim) for viewing the info
so you don't have write permittion to the files. See man grep for more info
about options and expressions."

[[ $ARGC -eq 0 || $1 == '--help' ]] && {echo $usage; exit 2}

packages_path='/var/log/packages'
ls='/bin/ls'

cd ${packages_path} 2>/dev/null || {echo ${packages_path}' not accessible'; exit 1}

file_names=($($ls | grep --color=auto --no-filename $* - ))
[[ $file_names == '' ]] && {echo 'no package found'; exit 2}
view -p ${file_names}
grissiom is offline     Reply With Quote
Old 06-18-2009, 09:22 AM   #6
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 276
Thanked: 16

Original Poster
And thanks Andy Alkaline. I will consider combine them into a single script in the future
grissiom is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Package xmuu was not found in the pkg-config search path shachter Linux - Software 1 10-03-2008 04:39 AM
Gnome Apt, Debian pkg search, synaptic, apt-get each is best for what? streams &dragonflies Ubuntu 1 07-14-2008 03:41 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 11:37 PM
pkg search tool linuxtesting2 Solaris / OpenSolaris 7 03-17-2006 01:43 AM
pkg-config search path? ironfistchamp Linux - Newbie 2 02-12-2006 09:00 AM


All times are GMT -5. The time now is 05:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration