Shell: minor fixes for functions.

master
Ambrevar 2012-12-05 19:18:06 +01:00
parent 98fb36ddd0
commit 6b816b6022
1 changed files with 15 additions and 16 deletions

View File

@ -1,7 +1,7 @@
## -*- mode:sh -*- # ## -*- mode:sh -*- #
################################################################################ ################################################################################
## Shell -- Functions. ## Shell -- Functions.
## Date 2012-08-11 ## Date 2012-12-05
################################################################################ ################################################################################
## Colored man pager. ## Colored man pager.
@ -93,7 +93,7 @@ dirsize ()
} }
## Network operations ## Network operations
if [ -e "/usr/bin/nmap" ]; then if [ -n "$(command -v nmap)" ]; then
network-map() network-map()
{ {
echo "$1" echo "$1"
@ -197,8 +197,8 @@ charset_scan ()
} }
## Confert all 'bad' encoding to UTF-8/LF. ## Confert all 'bad' encoding to UTF-8/LF.
# ##
## It will fail for encoding other than ISO-8859-1 and cp1252. ## WARNING: It will fail for encoding other than ISO-8859-1 and cp1252.
charset_2utf8 () charset_2utf8 ()
{ {
local CODING local CODING
@ -259,7 +259,7 @@ webcam ()
## Vim-only: search the vim reference manual for a keyword. ## Vim-only: search the vim reference manual for a keyword.
## Usage: :h <keyword> ## Usage: :h <keyword>
if [ -e "/usr/bin/vim" ]; then if [ -n "$(command -v vim)" ]; then
:h() :h()
{ {
vim --cmd ":silent help $@" --cmd "only"; vim --cmd ":silent help $@" --cmd "only";
@ -451,7 +451,7 @@ termsupport()
} }
## Highlight themes viewer for 256-colors terminals. ## Highlight themes viewer for 256-colors terminals.
if [ -f "/usr/bin/highlight" ] ; then if [ -n "$(command -v highlight)" ] ; then
hlt-viewer () hlt-viewer ()
{ {
print_help() print_help()
@ -495,7 +495,7 @@ if [ -f "/usr/bin/highlight" ] ; then
fi fi
## Extractor -- Useless when using 'atool'. ## Extractor -- Useless when using 'atool'.
if [ ! -e "/usr/bin/atool" ]; then if [ ! -n "$(command -v atool)" ]; then
extract () extract ()
{ {
if [ -f $1 ] ; then if [ -f $1 ] ; then
@ -522,7 +522,7 @@ if [ ! -e "/usr/bin/atool" ]; then
} }
fi fi
# Warning: use this function with caution. It may drastically improve # WARNING: use this function with caution. It may drastically improve
# compression of some PDF files, but in some case, the output filesize will be # compression of some PDF files, but in some case, the output filesize will be
# greater! You should not use it over PDF files embedding pictures as well. # greater! You should not use it over PDF files embedding pictures as well.
pdfcompress () pdfcompress ()
@ -743,11 +743,10 @@ lsofstat()
done done
} }
## Format C ## Format C using 'indent'. Alternative to indent: astyle, uncrustify.
## Consider indent, astyle, uncrustify.
formatc() formatc()
{ {
if [ ! -e /usr/bin/indent ]; then if [ -n "$(command -v indent)" ]; then
echo "Please install 'indent'" echo "Please install 'indent'"
return return
fi fi
@ -845,9 +844,9 @@ bindatasearch()
local SOURCE=$(od -tx8 "$1" | awk '($1="")1 gsub ( /\s/,"") { printf ("%s", $0) }') local SOURCE=$(od -tx8 "$1" | awk '($1="")1 gsub ( /\s/,"") { printf ("%s", $0) }')
## This special, not well-known syntax allows us to execute a set of ## This special, not well-known syntax allows us to execute a set of
## functions of the result of find. Since everything MUST be between simple ## functions upon the result of find. Since everything MUST be between
## quotes, we cannot use external variables directly. So we pass the $SOURCE ## simple quotes, we cannot use external variables directly. So we pass the
## variable as argument. The underscore at the end allow the use of ## $SOURCE variable as argument. The underscore at the end allows the use of
## arguments. ## arguments.
find "$WORKDIR" -type f -exec bash -c ' find "$WORKDIR" -type f -exec bash -c '
FILEDUMP=$(od -tx8 "$1" | awk '"'"'($1="")1 gsub ( /\s/,"") { printf ("%s", $0) }'"'"') FILEDUMP=$(od -tx8 "$1" | awk '"'"'($1="")1 gsub ( /\s/,"") { printf ("%s", $0) }'"'"')
@ -882,7 +881,7 @@ xmultioff ()
## Pacman Functions ## Pacman Functions
##============================================================================== ##==============================================================================
[ -f "/usr/bin/pacman" ] && . "${SHELL_DIR}/funs_pacman" [ -n "$(command -v pacman)" ] && . "${SHELL_DIR}/funs_pacman"
##============================================================================== ##==============================================================================
## FreeBSD Functions ## FreeBSD Functions
@ -897,7 +896,7 @@ xmultioff ()
## TeXlive ## TeXlive
if [ -d "/usr/local/texlive" ]; then if [ -d "/usr/local/texlive" ]; then
## Warning: it is important to set umask properly, otherwise users might ## WARNING: it is important to set umask properly, otherwise users might
## not have authorization to use the packages. ## not have authorization to use the packages.
## TODO: It is dirty to invoke a subshell several times. ## TODO: It is dirty to invoke a subshell several times.