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.