Added support for long options on certain scripts, optimized some scripts
This commit is contained in:
parent
43dfb82042
commit
6ac4c2a66d
106
dlaudio.sh
106
dlaudio.sh
@ -1,6 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Download audio using youtube-dl, passing
|
||||
# a specific set of options specified by the user
|
||||
#
|
||||
# Copyright (C) 2018 Eric Torres
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
@ -20,68 +23,137 @@ Usage: dlaudio [options] [URLs]
|
||||
|
||||
Options:
|
||||
-b, --batch-dl provide the links from a text file
|
||||
-f, --format the format to use (default: flac)"
|
||||
-f, --format the format to use (default: flac)
|
||||
-h, --help print this help page
|
||||
-n, --filename the name of the downloaded file (without the extension)
|
||||
EOF
|
||||
}
|
||||
|
||||
TEMP=$(getopt -o "b:f:hn:::" --long "batch-dl:,filename:,format:,help::" -n "dlaudio" -- "${@}")
|
||||
|
||||
declare -a opts
|
||||
batchfile=
|
||||
filename=
|
||||
format=
|
||||
|
||||
eval set -- "${TEMP}"
|
||||
unset TEMP
|
||||
# error messages
|
||||
readonly nobatchfile_error="Error: no batch file entered"
|
||||
readonly nofilename_error="Error: no filename entered"
|
||||
readonly noformat_error="Error: no format entered"
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
"-b"|"--batch-dl")
|
||||
case "${2}" in
|
||||
batchfile="${2}"
|
||||
case "${batchfile}" in
|
||||
"")
|
||||
batchfile="${2}"
|
||||
echo "${nobatchfile_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
echo "Not a file: ${batchfile}"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "No batch file entered" >&2
|
||||
exit 1
|
||||
[[ ! -f "${batchfile}" ]] && echo "Not a file: ${batchfile}" >&2 && exit 1
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
continue
|
||||
;;
|
||||
--batchfile=*)
|
||||
batchfile="${2#*=}"
|
||||
case "${batchfile}" in
|
||||
"")
|
||||
echo "${nobatchfile_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
echo "Not a file: ${batchfile}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
[[ ! -f "${batchfile}" ]] && echo "Not a file: ${batchfile}" && exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
"-f"|"--format")
|
||||
case "${2}" in
|
||||
format="${2}"
|
||||
case "${format}" in
|
||||
"")
|
||||
echo "No format entered" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
format="${2}"
|
||||
-*)
|
||||
echo "Not a format: ${format}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
continue
|
||||
;;
|
||||
--format=*)
|
||||
format="${1#*=}"
|
||||
case "${format}" in
|
||||
"")
|
||||
echo "${noformat_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
echo "Not a format: ${format}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
"-h"|"--help")
|
||||
# print help page and exit
|
||||
printHelp
|
||||
exit
|
||||
;;
|
||||
"-n"|"--filename")
|
||||
case "${2}" in
|
||||
filename="${2}"
|
||||
case "${filename}" in
|
||||
"")
|
||||
echo "No filename entered" >&2
|
||||
echo "${nofilename_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
filename="${2}"
|
||||
-*)
|
||||
echo "Not a filename: ${filename}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
continue
|
||||
;;
|
||||
--filename=*)
|
||||
filename="${2#*=}"
|
||||
case "${filename}" in
|
||||
"")
|
||||
echo "${nofilename_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
echo "Not a filename: ${filename}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
"--")
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
echo "Error, not an option: ${1}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
break
|
||||
esac
|
||||
done
|
||||
|
||||
@ -94,13 +166,13 @@ opts+=("--extract-audio")
|
||||
opts+=("--audio-format=${format:-flac}")
|
||||
|
||||
# set filename to either what the user set or its original title
|
||||
if [[ -n "${filename}" ]]; then
|
||||
if [[ "${filename}" ]]; then
|
||||
opts+=("--output=${HOME}/Music/${filename}.%(ext)s")
|
||||
else
|
||||
opts+=("--output=${HOME}/Music/%(title)s.%(ext)s")
|
||||
fi
|
||||
|
||||
if [[ -n "${batchfile}" ]]; then
|
||||
if [[ "${batchfile}" ]]; then
|
||||
youtube-dl "${opts[@]}" --batch-file="${batchfile}"
|
||||
else
|
||||
youtube-dl "${opts[@]}" "${@}"
|
||||
|
28
fqo.sh
28
fqo.sh
@ -3,14 +3,34 @@
|
||||
|
||||
printHelp() {
|
||||
cat << EOF
|
||||
fqo - fuzzy find a file and then check which package owns it
|
||||
Usage: fqo [patterns]
|
||||
fqo - fuzzy find a file and then check which package owns it
|
||||
Usage: fqo [-h|--help] [patterns]
|
||||
|
||||
Options:
|
||||
-h show this help page
|
||||
Options:
|
||||
-h show this help page
|
||||
EOF
|
||||
}
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
"-h"|"--help")
|
||||
printHelp
|
||||
exit
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
echo "Not an option: ${1}" >&2 && exit 1
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
break;
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z "${*}" ]] && echo "No patterns specified" && exit 1
|
||||
|
||||
locate --all --ignore-case --null -- "${@}" | fzf --read0 --exit-0 --select-1 | pacman -Qo -
|
||||
|
@ -1,4 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# Obtain a weather forecast
|
||||
|
||||
echo "${@}" | xargs --no-run-if-empty -I {} curl wttr.in/{}
|
||||
printHelp() {
|
||||
cat << EOF
|
||||
Retrieve the weather of a give location
|
||||
|
||||
Usage: getweather [-h|--help] [location]
|
||||
|
||||
Options:
|
||||
-h show this help page
|
||||
EOF
|
||||
}
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
"-h"|"--help")
|
||||
printHelp
|
||||
exit
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
echo "Not an option: ${1}" >&2 && exit 1
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
break;
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z "${@}" ]] && echo "Please enter a location" >&2 && exit 1
|
||||
|
||||
xargs --no-run-if-empty -I {} curl wttr.in/{} <<< "${@}"
|
||||
|
4
lsgroups
Executable file
4
lsgroups
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# List all groups in the system
|
||||
|
||||
sort <(awk -F ':' '{print $1}' < /etc/group)
|
Loading…
x
Reference in New Issue
Block a user