Shell: integrated color support, improved pacman functions (more modular).

master
Ambrevar 2012-07-19 16:01:22 +01:00
parent 83bccfbcf7
commit 5d03e6507d
8 changed files with 155 additions and 131 deletions

View File

@ -6,6 +6,8 @@ dropbox-cli
emacs-mediawiki-bzr
emacs-yasnippet
gsharkdown
handbrake-cli-svn
handbrake-svn
movgrab
package-query
pacman-color

View File

@ -21,7 +21,6 @@ bzip2
bzr
calc
catdvi
ccrypt
cmus
consolekit
coreutils
@ -31,7 +30,6 @@ cryptsetup
ctags
cups
cyrus-sasl
dconf
device-mapper
d-feet
dhcpcd
@ -61,6 +59,7 @@ gcc-libs
gcolor2
gdb
gettext
gimp
git
glibc
gnuplot
@ -70,6 +69,8 @@ grub
gsasl
gsharkdown
gzip
handbrake-cli-svn
handbrake-svn
hdparm
heirloom-mailx
help2man
@ -87,7 +88,6 @@ ispell
jfsutils
laptop-mode-tools
less
libgnome-keyring
libtool
licenses
links
@ -99,7 +99,6 @@ lrzip
ltrace
luakit
lvm2
lxterminal
m4
make
man-db
@ -137,7 +136,6 @@ pwgen
pwsafe
pygtk
python2-udiskie
qingy
ranger
reiserfsprogs
rtorrent
@ -177,7 +175,6 @@ vicious
vim
vlock
w3m
waf
weechat
wget
which
@ -199,7 +196,6 @@ xorg-xprop
xorg-xrandr
xorg-xrdb
xsel
xterm
yaourt
zathura
zathura-djvu

View File

@ -20,6 +20,7 @@ autoconf
automake
avahi
awesome
babl
bash
bash-completion
bc
@ -32,7 +33,6 @@ cairo
cairomm
calc
catdvi
ccrypt
cdparanoia
cloog
cmus
@ -53,14 +53,12 @@ db
dbus
dbus-core
dbus-glib
dconf
desktop-file-utils
device-mapper
d-feet
dhcpcd
dialog
diffutils
directfb
dirmngr
djvulibre
dnssec-anchors
@ -113,11 +111,13 @@ gd
gdb
gdbm
gdk-pixbuf2
gegl
geoclue
gettext
ghostscript
giblib
giflib
gimp
girara-common
girara-gtk2
git
@ -138,6 +138,7 @@ groff
grub
gsasl
gsettings-desktop-schemas
gsfonts
gsl
gsm
gstreamer0.10
@ -230,7 +231,6 @@ libgl
libglade
libglapi
libgme
libgnome-keyring
libgpg-error
libgsf
libgssglue
@ -247,6 +247,7 @@ libltdl
libmad
libmediainfo
libmms
libmng
libmodplug
libmp4v2
libmpc
@ -290,6 +291,7 @@ libvdpau
libvorbis
libvpx
libwebkit
libwmf
libx11
libxau
libxaw
@ -337,7 +339,6 @@ luafilesystem
luajit
luakit
lvm2
lxterminal
lzo2
m4
make
@ -425,7 +426,6 @@ python-configobj
python-dbus-common
python-notify
python-pycurl
qingy
randrproto
ranger
raptor
@ -487,10 +487,7 @@ videoproto
vim
vim-runtime
vlock
vte
vte-common
w3m
waf
weechat
wget
which
@ -503,7 +500,6 @@ wpa_supplicant
wv
wxgtk
x264
xbitmaps
xcb-proto
xcb-util
xcb-util-image
@ -527,7 +523,6 @@ xorg-fonts-encodings
xorg-fonts-misc
xorg-font-util
xorg-font-utils
xorg-luit
xorg-mkfontdir
xorg-mkfontscale
xorg-server
@ -545,7 +540,6 @@ xorg-xrdb
xorg-xset
xproto
xsel
xterm
xvidcore
xz
yajl

View File

@ -29,7 +29,9 @@ isShell()
SHELLDIR="$HOME/.shell.d"
source "${SHELLDIR}/main_rc" # Should be sourced first.
source "${SHELLDIR}/options_bash"
source "${SHELLDIR}/options_bash" # Should be sourced first.
source "${SHELLDIR}/colors_rc" # Should be sourced first.
source "${SHELLDIR}/funs_rc"
source "${SHELLDIR}/funs_bash"
source "${SHELLDIR}/alias_rc"

View File

@ -4,74 +4,74 @@
##==============================================================================
## Reset
Color_Off='\[\e[0m\]' # Text Reset
Color_Off='\e[0m' # Text Reset
## Regular Colors
Black='\[\e[0;30m\]' # Black
Red='\[\e[0;31m\]' # Red
Green='\[\e[0;32m\]' # Green
Yellow='\[\e[0;33m\]' # Yellow
Blue='\[\e[0;34m\]' # Blue
Purple='\[\e[0;35m\]' # Purple
Cyan='\[\e[0;36m\]' # Cyan
White='\[\e[0;37m\]' # White
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
## Bold
BBlack='\[\e[1;30m\]' # Black
BRed='\[\e[1;31m\]' # Red
BGreen='\[\e[1;32m\]' # Green
BYellow='\[\e[1;33m\]' # Yellow
BBlue='\[\e[1;34m\]' # Blue
BPurple='\[\e[1;35m\]' # Purple
BCyan='\[\e[1;36m\]' # Cyan
BWhite='\[\e[1;37m\]' # White
BBlack='\e[1;30m' # Black
BRed='\e[1;31m' # Red
BGreen='\e[1;32m' # Green
BYellow='\e[1;33m' # Yellow
BBlue='\e[1;34m' # Blue
BPurple='\e[1;35m' # Purple
BCyan='\e[1;36m' # Cyan
BWhite='\e[1;37m' # White
## Underline
UBlack='\[\e[4;30m\]' # Black
URed='\[\e[4;31m\]' # Red
UGreen='\[\e[4;32m\]' # Green
UYellow='\[\e[4;33m\]' # Yellow
UBlue='\[\e[4;34m\]' # Blue
UPurple='\[\e[4;35m\]' # Purple
UCyan='\[\e[4;36m\]' # Cyan
UWhite='\[\e[4;37m\]' # White
UBlack='\e[4;30m' # Black
URed='\e[4;31m' # Red
UGreen='\e[4;32m' # Green
UYellow='\e[4;33m' # Yellow
UBlue='\e[4;34m' # Blue
UPurple='\e[4;35m' # Purple
UCyan='\e[4;36m' # Cyan
UWhite='\e[4;37m' # White
## Background
On_Black='\[\e[40m\]' # Black
On_Red='\[\e[41m\]' # Red
On_Green='\[\e[42m\]' # Green
On_Yellow='\[\e[43m\]' # Yellow
On_Blue='\[\e[44m\]' # Blue
On_Purple='\[\e[45m\]' # Purple
On_Cyan='\[\e[46m\]' # Cyan
On_White='\[\e[47m\]' # White
On_Black='\e[40m' # Black
On_Red='\e[41m' # Red
On_Green='\e[42m' # Green
On_Yellow='\e[43m' # Yellow
On_Blue='\e[44m' # Blue
On_Purple='\e[45m' # Purple
On_Cyan='\e[46m' # Cyan
On_White='\e[47m' # White
## High Intensty
IBlack='\[\e[0;90m\]' # Black
IRed='\[\e[0;91m\]' # Red
IGreen='\[\e[0;92m\]' # Green
IYellow='\[\e[0;93m\]' # Yellow
IBlue='\[\e[0;94m\]' # Blue
IPurple='\[\e[0;95m\]' # Purple
ICyan='\[\e[0;96m\]' # Cyan
IWhite='\[\e[0;97m\]' # White
IBlack='\e[0;90m' # Black
IRed='\e[0;91m' # Red
IGreen='\e[0;92m' # Green
IYellow='\e[0;93m' # Yellow
IBlue='\e[0;94m' # Blue
IPurple='\e[0;95m' # Purple
ICyan='\e[0;96m' # Cyan
IWhite='\e[0;97m' # White
## Bold High Intensty
BIBlack='\[\e[1;90m\]' # Black
BIRed='\[\e[1;91m\]' # Red
BIGreen='\[\e[1;92m\]' # Green
BIYellow='\[\e[1;93m\]' # Yellow
BIBlue='\[\e[1;94m\]' # Blue
BIPurple='\[\e[1;95m\]' # Purple
BICyan='\[\e[1;96m\]' # Cyan
BIWhite='\[\e[1;97m\]' # White
BIBlack='\e[1;90m' # Black
BIRed='\e[1;91m' # Red
BIGreen='\e[1;92m' # Green
BIYellow='\e[1;93m' # Yellow
BIBlue='\e[1;94m' # Blue
BIPurple='\e[1;95m' # Purple
BICyan='\e[1;96m' # Cyan
BIWhite='\e[1;97m' # White
## High Intensty backgrounds
On_IBlack='\[\e[0;100m\]' # Black
On_IRed='\[\e[0;101m\]' # Red
On_IGreen='\[\e[0;102m\]' # Green
On_IYellow='\[\e[0;103m\]' # Yellow
On_IBlue='\[\e[0;104m\]' # Blue
On_IPurple='\[\e[10;95m\]' # Purple
On_ICyan='\[\e[0;106m\]' # Cyan
On_IWhite='\[\e[0;107m\]' # White
On_IBlack='\e[0;100m' # Black
On_IRed='\e[0;101m' # Red
On_IGreen='\e[0;102m' # Green
On_IYellow='\e[0;103m' # Yellow
On_IBlue='\e[0;104m' # Blue
On_IPurple='\e[10;95m' # Purple
On_ICyan='\e[0;106m' # Cyan
On_IWhite='\e[0;107m' # White

View File

@ -426,9 +426,46 @@ lsofstat()
## Pacman Functions
##==============================================================================
## Compare installed packages with list.
## TODO: completion does not work as is. It requires pacman arguments like -S or -Q.
## There should be a way to use it.
# if isShell "zsh" ; then
# compdef _pacman pacman-deps
# elif isShell "bash"; then
# complete -o default -o nospace -F _pacman pacman-deps
# fi
## This function gets the pacman variabless when necessary.
## Note: some functions uses pacman localized output. It should work in any case.
## Note: you should always call _pacman_unset_vars in the end.
_pacman_set_vars()
{
if [ ! -f "/usr/bin/pacman" ]; then
echo "Could not get pacman's variables."
return 1
fi
local pacman_var_list="$(pacman -Qi tzdata | cut -f1 -d':')"
if [ "$pacman_var_list" = "" ];then
echo "Could not get pacman's variables."
return 2
fi
pacman_name="$(echo "$pacman_var_list" | sed -n '1p')"
pacman_deps="$(echo "$pacman_var_list" | sed -n '7p')"
pacman_optdeps="$(echo "$pacman_var_list" | sed -n '8p')"
pacman_size="$(echo "$pacman_var_list" | sed -n '12p')"
}
_pacman_unset_vars()
{
unset pacman_name
unset pacman_deps
unset pacman_optdeps
unset pacman_size
}
## Get detailed file size list for a specified package.
if [ -f "/usr/bin/pacman" ]; then
pacman-size()
pacman-files()
{
if [ $# -ne 1 ];then
echo "Wrong number of arguments."
@ -446,9 +483,10 @@ if [ -f "/usr/bin/pacman" ]; then
echo -e "${RESULT}" | grep -v "^$" | sort -h
# English locale only.
echo -n "Total: "
pacman -Qi $1 | grep "Size" | sed 's/^[^[:digit:]]*//'
_pacman_set_vars
pacman -Qi $1 | grep "$pacman_size" | sed 's/^[^[:digit:]]*//'
_pacman_unset_vars
}
fi
@ -519,32 +557,49 @@ if [ -f "/usr/bin/pacman" ]; then
return 1
fi
## TODO: Use pacman-official diff parameters.
diff <(pacman -Qq${OPTION_FOREIGN}${OPTION_EXPLICIT} | sort) <(cat "$*" | sort) | grep "${OPTION_LOCAL}" | cut -f2 -d" "
}
fi
## Print a detailed view of package deps size and total size.
## Print of specified package and a grand total.
if [ -f "/usr/bin/pacman" ]; then
pacman-size()
{
## Arguments
if [ $# -lt 1 ];then
echo "Please provide packages."
return
fi
CMD="pacman -Qi"
TOTAL_SIZE=0
_pacman_set_vars
for i ; do
## TODO: better awk command?
SIZE=$(eval "${CMD} $i" 2>&1 | grep "^$pacman_size" | cut -f2 -d':' | sed -e 's/\..*\| //g')
if [ ! "${SIZE}" = "" ];then
printf "%6s KiB %s\n" ${SIZE} $i
TOTAL_SIZE=$(($TOTAL_SIZE+$SIZE))
fi
done
echo -e "${BIRed}Total size${CReset}: $(echo ${TOTAL_SIZE}) KiB"
_pacman_unset_vars
}
fi
## Print deps list.
if [ -f "/usr/bin/pacman" ]; then
pacman-deps()
{
## Arguments
if [ $# -ne 1 ];then
echo "Requires only one single argument."
if [ $# -lt 1 ];then
echo "Please provide packages."
return
fi
## Bold High Intensty colors
BIBlack='\e[1;90m' # Black
BIRed='\e[1;91m' # Red
BIGreen='\e[1;92m' # Green
BIYellow='\e[1;93m' # Yellow
BIBlue='\e[1;94m' # Blue
BIPurple='\e[1;95m' # Purple
BICyan='\e[1;96m' # Cyan
BIWhite='\e[1;97m' # White
CReset='\e[0m' # Text Reset
ARROW="${BIBlue}==>${CReset}"
CMD="pacman -Qi"
APP_OUTPUT=$(eval "${CMD} $1" 2>&1)
@ -559,40 +614,12 @@ if [ -f "/usr/bin/pacman" ]; then
fi
fi
## List of dependencies. Note that it is stored as an ARRAY!
DEPLIST=($( echo "$APP_OUTPUT" | grep "Depends"| sed -e 's/Depends On.*: //g' | sed -e 's/[>=<][^ ]*//g'))
DEPLIST_INFO="$(eval "$CMD ${DEPLIST[*]}" 2>&1)"
SKIPPED_DEPS="$(echo "$DEPLIST_INFO" | awk '/^error:/ {print $3}')"
SIZE_ARRAY="$(echo "$DEPLIST_INFO" | awk '/^Installed Size/ {print $4}' | sed -e 's/\.[[:digit:]]*//g')"
echo -e "${ARROW} ${BIGreen}Deps size for ${BIYellow}$1${CReset}"
echo "$DEPLIST_INFO" | awk '/^Name/ {pkg=$3} /^Installed Size/ {print $4 " " $5,pkg}' | sort -n
TOTAL_SIZE=0
for i in $(echo "$SIZE_ARRAY"); do
TOTAL_SIZE=$(($TOTAL_SIZE+$i))
_pacman_set_vars
for i ; do
## TODO: better awk command.
echo $( eval "${CMD} $i" 2>&1 | grep "^$pacman_deps"| cut -f2 -d':' | sed -e 's/[>=<][^ ]*//g')
done
echo -e "${ARROW} ${BIGreen}Summary${CReset}"
echo "$APP_OUTPUT"
echo -e "${BIRed}Deps size${CReset} : $(echo "${TOTAL_SIZE}") KiB"
TOTAL_SIZE=$(($TOTAL_SIZE+$(echo "$APP_OUTPUT" | awk '/^Installed Size/ {print $4}'| sed -e 's/\.[[:digit:]]*//g')))
echo -e "${BIRed}Total size${CReset} : $(echo "${TOTAL_SIZE}") KiB"
if [ ! -z "$SKIPPED_DEPS" ]; then
echo -e "$ARROW${BIPurple} Warning!${CReset} Errors were ecountered on"
echo -e "$SKIPPED_DEPS"
fi
_pacman_unset_vars
}
## TODO: completion does not work as is. It requires pacman arguments like -S or -Q.
## There should be a way to use it.
# if isShell "zsh" ; then
# compdef _pacman pacman-deps
# elif isShell "bash"; then
# complete -o default -o nospace -F _pacman pacman-deps
# fi
fi

4
.zshrc
View File

@ -30,7 +30,9 @@ isShell()
SHELLDIR="$HOME/.shell.d"
source "${SHELLDIR}/main_rc" # Should be sourced first.
source "${SHELLDIR}/options_zsh"
source "${SHELLDIR}/options_zsh" # Should be sourced first.
source "${SHELLDIR}/colors_rc" # Should be sourced first.
source "${SHELLDIR}/funs_rc"
source "${SHELLDIR}/alias_rc"
source "${SHELLDIR}/keys_zsh"

3
README
View File

@ -133,6 +133,8 @@ awesome
bashmount
bc
calc
catdvi
ccrypt
cmus
cppcheck
doxygen
@ -154,7 +156,6 @@ inkscape
irssi
lrzip
luakit
lxterminal
mediainfo
mencoder
mkvtoolnix