diff --git a/dlaudio.sh b/dlaudio.sh index d9a5c98..b4fe0db 100755 --- a/dlaudio.sh +++ b/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[@]}" "${@}" diff --git a/fqo.sh b/fqo.sh index 44687d2..cfb1bbb 100755 --- a/fqo.sh +++ b/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 - diff --git a/getweather.sh b/getweather.sh index 43b4321..a499c57 100755 --- a/getweather.sh +++ b/getweather.sh @@ -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/{} <<< "${@}" diff --git a/lsgroups b/lsgroups new file mode 100755 index 0000000..a19ad98 --- /dev/null +++ b/lsgroups @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# List all groups in the system + +sort <(awk -F ':' '{print $1}' < /etc/group) diff --git a/lsusers b/lsusers new file mode 100755 index 0000000..5a712bc --- /dev/null +++ b/lsusers @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# List all users on the system + +sort -u <(awk -F ':' '{print $1}' < /etc/passwd)