LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 05-18-2009, 01:32 AM   #1
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 423

Rep: Reputation: 45
My little script for pkg search


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 08:23 AM.
 
Old 06-18-2009, 01:40 AM   #2
Andy Alkaline
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian-wheezy-amd64, LFS 7.1
Posts: 352

Rep: Reputation: 33
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))
 
Old 06-18-2009, 05:44 AM   #3
Noddegamra
LQ Newbie
 
Registered: Feb 2009
Location: California
Distribution: Slackware
Posts: 20

Rep: Reputation: 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. :-)
 
Old 06-18-2009, 06:51 AM   #4
sleekslack
Member
 
Registered: Mar 2008
Location: Bangkok, Thailand
Distribution: Slackware64 13.37
Posts: 34

Rep: Reputation: 16
Nice. I like it. Remind me of something like pkg_info in FreeBSD
 
Old 06-18-2009, 08:20 AM   #5
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 423

Original Poster
Rep: Reputation: 45
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}
 
Old 06-18-2009, 08:22 AM   #6
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 423

Original Poster
Rep: Reputation: 45
And thanks Andy Alkaline. I will consider combine them into a single script in the future
 
  


Reply

Tags
bash, management, package, scripts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:39 AM
Gnome Apt, Debian pkg search, synaptic, apt-get each is best for what? streams &dragonflies Ubuntu 1 07-14-2008 02:41 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
pkg search tool linuxtesting2 Solaris / OpenSolaris 7 03-17-2006 12:43 AM
pkg-config search path? ironfistchamp Linux - Newbie 2 02-12-2006 08:00 AM


All times are GMT -5. The time now is 11:24 AM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration