Shell: printhelp fixes plus some more.
parent
a9ffe6c4d3
commit
1e1c69600e
|
@ -42,13 +42,14 @@ pacman-files()
|
||||||
{
|
{
|
||||||
_printhelp()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat <<EOF
|
||||||
echo -e " $1 [-n] PACKAGES"
|
Usage: $1 [OPTIONS] PACKAGES
|
||||||
echo
|
|
||||||
echo "Usage:"
|
Display size of files in PACKAGES.
|
||||||
echo -e " default:\tDisplay size of files in PACKAGES."
|
|
||||||
echo -e " -h:\t\tDisplay this help."
|
-h: Display this help.
|
||||||
echo -e " -n:\t\tSort by size."
|
-n: Sort by size.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
local OPTION_SORT="cat"
|
local OPTION_SORT="cat"
|
||||||
|
@ -99,15 +100,16 @@ pacman-diff()
|
||||||
{
|
{
|
||||||
_printhelp()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat <<EOF
|
||||||
echo -e " $1 [-m|-e] [-q] FILE"
|
Usage: $1 [-m|-e] [-q] FILE
|
||||||
echo
|
|
||||||
echo "Usage:"
|
Display packages included in FILE but not installed.
|
||||||
echo -e " default:\tDisplay packages included in FILE but not installed."
|
|
||||||
echo -e " -e:\t\tCompare FILE to explicitly installed packages."
|
-e: Compare FILE to explicitly installed packages.
|
||||||
echo -e " -h:\t\tDisplay this help."
|
-h: Display this help.
|
||||||
echo -e " -m:\t\tCompare FILE to foreign installed packages."
|
-m: Compare FILE to foreign installed packages.
|
||||||
echo -e " -q:\t\tDisplay installed packages not included in FILE."
|
-q: Display installed packages not included in FILE.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
local OPTION_EXPLICIT=""
|
local OPTION_EXPLICIT=""
|
||||||
|
@ -158,15 +160,17 @@ pacman-size()
|
||||||
{
|
{
|
||||||
_printhelp()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat <<EOF
|
||||||
echo -e " $1 [-a|-h|-n|-q] PACKAGES"
|
Usage: $1 [OPTIONS] PACKAGES
|
||||||
echo -e " Arguments MUST be set before package list."
|
|
||||||
echo
|
Display package size. Output contains no double and is alphabetically sorted. A
|
||||||
echo "Usage:"
|
grand total is printed at the end. It will only work for repos packages by
|
||||||
echo -e " default:\tDisplay package size. Output contains no double and is alphabetically sorted. A grand total is printed at the end. It will only work for repos packages by default."
|
default.
|
||||||
echo -e " -h:\t\tShow this help."
|
|
||||||
echo -e " -n:\t\tOutput is sorted by size."
|
-h: Show this help.
|
||||||
echo -e " -q:\t\tUses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos."
|
-n: Output is sorted by size.
|
||||||
|
-q: Uses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
local CMD="pacman -Si"
|
local CMD="pacman -Si"
|
||||||
|
@ -233,16 +237,18 @@ pacman-deps()
|
||||||
{
|
{
|
||||||
_printhelp()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
|
||||||
echo -e " $1 [-a|-h|-q] [-r] PACKAGES"
|
cat <<EOF
|
||||||
echo -e " Arguments MUST be set before package list."
|
Usage: $1 [-a|-h|-q] [-r] PACKAGES
|
||||||
echo
|
|
||||||
echo "Usage:"
|
Display package dependencies. Output contains no double and is alphabetically
|
||||||
echo -e " default:\tDisplay package dependencies. Output contains no double and is alphabetically sorted. It will only work for repos packages by default."
|
sorted. It will only work for repos packages by default.
|
||||||
echo -e " -a:\t\tUses Yaourt queries instead of repos database. It slows down query but allow displaying size of any packages not available in repos."
|
|
||||||
echo -e " -h:\t\tShow this help."
|
-a: Uses Yaourt queries instead of repos database. It slows down query but allow displaying size of any packages not available in repos.
|
||||||
echo -e " -r:\t\tCall function recursively."
|
-h: Show this help.
|
||||||
echo -e " -q:\t\tUses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos."
|
-r: Call function recursively.
|
||||||
|
-q: Uses installed packages database instead of repos database. It speeds up queries and allows displaying size of local packages not available in repos.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
local CMD="pacman -Si"
|
local CMD="pacman -Si"
|
||||||
|
@ -355,19 +361,20 @@ abs-fetch ()
|
||||||
{
|
{
|
||||||
_printhelp ()
|
_printhelp ()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat <<EOF
|
||||||
echo -e " $1 [-hfy] PACKAGES"
|
Usage: $1 [-hfy] PACKAGES
|
||||||
echo
|
|
||||||
echo "Usage:"
|
Fetch PKGBUILDs from ABS-tree.
|
||||||
echo -e " default:\tFetch PKGBUILDs from ABS-tree"
|
|
||||||
echo -e " -f:\t\tOverwrite folder if it exists."
|
-f:\t\tOverwrite folder if it exists.
|
||||||
echo -e " -h:\t\tDisplay this help."
|
-h:\t\tDisplay this help.
|
||||||
echo -e " -y:\t\tUse 'yaourt' to fetch data."
|
-y:\t\tUse 'yaourt' to fetch data.
|
||||||
echo
|
|
||||||
echo 'Noteworthy parameters:'
|
Noteworthy parameters:
|
||||||
echo '* $(pacman-official)'
|
\$(pacman-official)
|
||||||
echo '* $(pacman -Qmq)'
|
\$(pacman -Qmq)
|
||||||
echo '* $(pacman -Qq)'
|
\$(pacman -Qq)
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
local DL_AGENT=0
|
local DL_AGENT=0
|
||||||
|
|
105
.shell.d/funs_rc
105
.shell.d/funs_rc
|
@ -231,20 +231,18 @@ sanitize()
|
||||||
|
|
||||||
asciify()
|
asciify()
|
||||||
{
|
{
|
||||||
asciify_help()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo
|
cat <<EOF
|
||||||
echo "Usage:"
|
Usage: $1 FILES
|
||||||
echo -e "\t$1 FILES"
|
|
||||||
echo
|
Convert non-ASCII characters to their ASCII equivalent.
|
||||||
echo "Synopsis:"
|
EOF
|
||||||
echo -e "\tConvert non-ASCII characters to their ASCII equivalent."
|
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
echo "Missing arguments."
|
echo "Missing arguments."
|
||||||
asciify_help $0
|
_printhelp $0
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -305,22 +303,23 @@ asciify()
|
||||||
|
|
||||||
blind-append()
|
blind-append()
|
||||||
{
|
{
|
||||||
blind_help()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo
|
cat <<EOF
|
||||||
echo "Usage:"
|
Usage: $1 FILE [STRING]
|
||||||
echo -e "\t$1 FILE [STRING]"
|
|
||||||
echo
|
Append to all STRING found in FILE a secret phrase being prompted. If STRING is
|
||||||
echo "Synopsis:"
|
omitted, secret phrase will be appended to the end of the file. If FILE does
|
||||||
echo -e "\tAppend to all STRING found in FILE a secret phrase being prompted."
|
not exist, it will be created and secret phrase will be inserted. STRING will be
|
||||||
echo -e "\tIf STRING is omitted, secret phrase will be appended to the end of the file."
|
ignored.
|
||||||
echo -e "\tIf FILE does not exist, it will be created and secret phrase will be inserted. STRING will be ignored."
|
|
||||||
echo
|
This requires 'read -s'. It will not work for Bourne Shell.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
||||||
echo "Wrong number of arguments."
|
echo "Wrong number of arguments."
|
||||||
blind_help $0
|
_printhelp $0
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -363,6 +362,7 @@ termcolors256()
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Will not work for Bourne Shell.
|
||||||
termcolors()
|
termcolors()
|
||||||
{
|
{
|
||||||
# The test text. Must be 3 letters.
|
# The test text. Must be 3 letters.
|
||||||
|
@ -396,43 +396,47 @@ termsupport()
|
||||||
done | sort -nk2
|
done | sort -nk2
|
||||||
}
|
}
|
||||||
|
|
||||||
## Highlight themes viewer for 256-colors terminals.
|
|
||||||
if [ -n "$(command -v highlight)" ] ; then
|
if [ -n "$(command -v highlight)" ] ; then
|
||||||
hlt-viewer ()
|
hlt-viewer ()
|
||||||
{
|
{
|
||||||
print_help()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat<<EOF
|
||||||
echo -e " $1"
|
Usage: $1
|
||||||
echo
|
|
||||||
echo "This script displays a preview for every highlight's theme."
|
Highlight themes viewer for 256-colors terminals.
|
||||||
echo "Press ENTER to display next preview. Press anything else then ENTER to quit."
|
|
||||||
|
highlight is a tool for listing printing. This script displays a preview for
|
||||||
|
every highlight's theme. Press ENTER to display next preview. Press anything
|
||||||
|
else then ENTER to quit.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
print_help "$0"
|
_printhelp "$0"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local SAMPLE="$(cat <<EOF
|
||||||
local LIST=$(highlight -w | grep -v "\s\|^$")
|
void function(char* pointer, int &ref)
|
||||||
local SAMPLE="void function(char* pointer, int &ref)
|
|
||||||
{
|
{
|
||||||
int integer=3;
|
int integer=3;
|
||||||
char* string=\"Hello!\";
|
char* string="Hello!";
|
||||||
|
|
||||||
// Line comment
|
// Line comment
|
||||||
for ( i=0; i<10; i++)
|
for ( i=0; i<10; i++)
|
||||||
{
|
{
|
||||||
printf(\"Sum: %d\\\n\", i*( integer+14 ) );
|
printf("Sum: %d\n", i*( integer+14 ) );
|
||||||
}
|
}
|
||||||
}"
|
}
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
|
||||||
unset DUMMY
|
unset DUMMY
|
||||||
for i in $(highlight -w | grep -v "\s\|^$"); do
|
for i in $(highlight -w | grep -v "\s\|^$"); do
|
||||||
echo "******************** $i ********************"
|
echo "******************** $i ********************"
|
||||||
highlight -S c -O xterm256 <(echo $SAMPLE) -s "$i"
|
highlight -S c -O xterm256 <(echo "$SAMPLE") -s "$i"
|
||||||
read -s DUMMY
|
read DUMMY
|
||||||
if [ -n "$DUMMY" ]; then
|
if [ -n "$DUMMY" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -519,21 +523,21 @@ pdfresize ()
|
||||||
gs -q -o $2 -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.4 $1
|
gs -q -o $2 -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.4 $1
|
||||||
}
|
}
|
||||||
|
|
||||||
## Create an archive from a single or multiples files/folders.
|
|
||||||
archive ()
|
archive ()
|
||||||
{
|
{
|
||||||
printhelp()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat <<EOF
|
||||||
echo -e " $1 [-m METHOD] [-v] FILES|FOLDERS"
|
Usage: $1 [-m METHOD] [-v] FILES|FOLDERS
|
||||||
echo
|
|
||||||
echo "Usage:"
|
Create an archive from a single or multiples files/folders.
|
||||||
echo -e " default:\tCreate an archive of specified FILES and/or FOLDERS."
|
|
||||||
echo -e " -h:\t\tDisplay this help."
|
-h: Display this help.
|
||||||
echo -e " -m:\t\tChoose compression method."
|
-m: Choose compression method.
|
||||||
echo -e " gz\t\tgzip (default)."
|
* gz: gzip (default).
|
||||||
echo -e " xz\t\tLZMA."
|
* xz: LZMA.
|
||||||
echo -e " -v:\t\tExclude VCS data. (GNU tar only)."
|
-v: Exclude VCS data. (GNU tar only).
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
local OPTION_VCS=""
|
local OPTION_VCS=""
|
||||||
|
@ -542,7 +546,7 @@ archive ()
|
||||||
while getopts ":hm:v" opt; do
|
while getopts ":hm:v" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h)
|
h)
|
||||||
printhelp "$0"
|
_printhelp "$0"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
m)
|
m)
|
||||||
|
@ -552,7 +556,7 @@ archive ()
|
||||||
OPTION_VCS="--exclude-vcs"
|
OPTION_VCS="--exclude-vcs"
|
||||||
;;
|
;;
|
||||||
?)
|
?)
|
||||||
printhelp "$0"
|
_printhelp "$0"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
:)
|
:)
|
||||||
|
@ -668,6 +672,7 @@ vcsclean()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local CHOICE
|
local CHOICE
|
||||||
|
unset CHOICE
|
||||||
echo "This will clean current folder from all VCS control files."
|
echo "This will clean current folder from all VCS control files."
|
||||||
echo -n "Proceed ? [y/N] "
|
echo -n "Proceed ? [y/N] "
|
||||||
while [ -z "$CHOICE" ];
|
while [ -z "$CHOICE" ];
|
||||||
|
|
|
@ -125,14 +125,17 @@ tc_transcode()
|
||||||
{
|
{
|
||||||
_printhelp()
|
_printhelp()
|
||||||
{
|
{
|
||||||
echo "Synopsis:"
|
cat <<EOF
|
||||||
echo -e " $1 [-f|-h|-s] FILES"
|
Usage: $1 [OPTIONS] FILES|FOLDERS
|
||||||
echo
|
|
||||||
echo "Usage:"
|
Transcode FILES or files found in FOLDERS to .mkv with x264 and ogg. Output
|
||||||
echo -e " default:\tTranscode FILES to .mkv with x264 and ogg. Output files are the same as the original, with time appended. You can customize encoding with the TC_* variables."
|
files are the same as the original, with time appended. You can customize
|
||||||
echo -e " -f:\t\tOverwrite existing file if any."
|
encoding with the TC_* variables.
|
||||||
echo -e " -h:\t\tDisplay this help."
|
|
||||||
echo -e " -s:\t\tSample of ten minutes."
|
-f: Overwrite existing file if any.
|
||||||
|
-h: Display this help.
|
||||||
|
-s: Sample of ten minutes.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
## What to do if file exists:
|
## What to do if file exists:
|
||||||
|
@ -176,10 +179,12 @@ tc_transcode()
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## The IFS trick will let us use an array of file that can have spaces. Real arrays are much better at it, but in this case the trick is not excessive, and works on all sh shells.
|
||||||
local OLDIFS
|
local OLDIFS
|
||||||
OLDIFS=$IFS
|
OLDIFS=$IFS
|
||||||
|
|
||||||
## Zsh compatibility
|
## Zsh compatibility. We need it otherwise word splitting of parameter like
|
||||||
|
## TC_SAMPLE will not work.
|
||||||
local STATUS
|
local STATUS
|
||||||
STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
||||||
[ "$STATUS" = "off" ] && set -o shwordsplit
|
[ "$STATUS" = "off" ] && set -o shwordsplit
|
||||||
|
|
Loading…
Reference in New Issue