diff options
author | Euro20179 <f> | 2021-03-02 14:42:06 -0800 |
---|---|---|
committer | Euro20179 <f> | 2021-03-02 14:42:06 -0800 |
commit | 4646fe312a86400cd60c401f126cccf8d9ef8cf7 (patch) | |
tree | b741ba334bc5ffd388c2fd45dda32c2728ffb279 | |
parent | 31889fa4042f3d3cb1572a2758c0fa5b954514d3 (diff) | |
download | ytfzf-4646fe312a86400cd60c401f126cccf8d9ef8cf7.tar.gz |
long optarg parse simplification
-rwxr-xr-x | ytfzf | 118 |
1 files changed, 51 insertions, 67 deletions
@@ -45,21 +45,21 @@ dep_ck "jq" "youtube-dl" "$YTFZF_PLAYER"; helpinfo () { printf "Usage: %bytfzf [OPTIONS] %b<search-query>%b\n" "\033[1;32m" "\033[1;33m" "\033[0m"; printf " OPTIONS:\n" -printf " -h, --help Show this help text\n"; -printf " -t, --thumbnails Show thumbnails (requires ueberzug)\n"; -printf " Doesn't work with -H -D\n"; -printf " -D, --ext-menu Use external menu(default dmenu) instead of fzf \n"; -printf " -H, --choose-from-history Choose from history \n"; -printf " -x, --clear-history Delete history\n"; -printf " -m, --audio-only <search-query> Audio only (for music)\n"; -printf " -d, --download <search-query> Download to current directory\n"; -printf " -f <search-query> Show available formats before proceeding\n"; -printf " -a, --auto-play <search-query> Auto play the first result, no selector\n"; -printf " -r <search-query> Auto play a random result, no selector\n"; -printf " -n, --link-count <link-count> To specify number of videos to select with -a or -r\n"; -printf " -l, --loop <search-query> Loop: prompt selector again after video ends\n"; -printf " -s <search-query> After the video ends make another search \n"; -printf " -L, --link-only <search-query> Prints the selected URL only, helpful for scripting\n"; +printf " -h, --help Show this help text\n"; +printf " -t, --thumbnails Show thumbnails (requires ueberzug)\n"; +printf " Doesn't work with -H -D\n"; +printf " -D, --ext-menu Use external menu(default dmenu) instead of fzf \n"; +printf " -H, --choose-from-history Choose from history \n"; +printf " -x, --clear-history Delete history\n"; +printf " -m, --audio-only <search-query> Audio only (for music)\n"; +printf " -d, --download <search-query> Download to current directory\n"; +printf " -f <search-query> Show available formats before proceeding\n"; +printf " -a, --auto-play <search-query> Auto play the first result, no selector\n"; +printf " -r --random-play <search-query> Auto play a random result, no selector\n"; +printf " -n, --link-count <link-count> To specify number of videos to select with -a or -r\n"; +printf " -l, --loop <search-query> Loop: prompt selector again after video ends\n"; +printf " -s <search-query> After the video ends make another search \n"; +printf " -L, --link-only <search-query> Prints the selected URL only, helpful for scripting\n"; printf " Use - instead of <search-query> for stdin\n"; printf "\n" printf " Option usage:\n" @@ -414,63 +414,43 @@ show_format=0 link_count=1 #OPT -while getopts "LhDmdfxHarltsn:U:-:" opt; do + +parse_opt () { + opt=$1 + OPTARG="${2-}" case ${opt} in #Long options -) case "${OPTARG}" in - help) - helpinfo - exit; - ;; - ext-menu) - is_ext_menu="1" - ;; - download) - YTFZF_PLAYER="youtube-dl" - YTFZF_PLAYER_FORMAT="youtube-dl -f" - ;; - choose-from-history) - get_history - ;; - clear-history) - [ -e "$history_file" ] && rm "$history_file" && touch "$history_file" && printf "History has been cleared\n" - exit - ;; - auto-select) - auto_select=1 - ;; - random-select) - random_select=1 - ;; - search) - search_again=1 - YTFZF_LOOP=1 - ;; - loop) - YTFZF_LOOP=1 - ;; - show-thumbnails|thumbnails) - show_thumbnails=1 - ;; - link|link-only) - show_link_only=1 - ;; - link-count=*) - link_count=${OPTARG#*=} - ;; - audio-only) - YTFZF_PREF="bestaudio" - ;; - auto-play) - auto_select=1 - ;; - *) - printf "--$OPTARG not found\n" - usageinfo - exit 2; - ;; + help) parse_opt "h" ;; + + ext-menu) parse_opt "D" ;; + + download) parse_opt "d" ;; + + choose-from-history) parse_opt "H" ;; + + clear-history) parse_opt "x" ;; + + random-select) parase_opt "r" ;; + + search) parse_opt "s" ;; + + loop) parse_opt "l" ;; + thumbnails) parse_opt "t" ;; + + link-only) parse_opt "L" ;; + + link-count=*) parse_opt "n" "${OPTARG#*=}" ;; + + audio-only) parse_opt "m" ;; + + auto-play) parse_opt "a" ;; + + random-auto-play) parse_opt "r" ;; + + *) parse_opt "UNKNOWN" ;; esac ;; #Short options @@ -517,6 +497,10 @@ while getopts "LhDmdfxHarltsn:U:-:" opt; do exit 2; ;; esac +} + +while getopts "LhDmdfxHarltsn:U:-:" opt; do + parse_opt "$opt" "$OPTARG" done shift $((OPTIND-1)) |