diff options
author | Euro20179 <f> | 2021-03-02 12:47:22 -0800 |
---|---|---|
committer | Euro20179 <f> | 2021-03-02 12:47:22 -0800 |
commit | 31889fa4042f3d3cb1572a2758c0fa5b954514d3 (patch) | |
tree | 7b62055d347774a73523a61efec7552e252012e3 | |
parent | 51a278bb9936434ec942304d703988f48a840c04 (diff) | |
download | ytfzf-31889fa4042f3d3cb1572a2758c0fa5b954514d3.tar.gz |
option-parsing-longopts
-rwxr-xr-x | ytfzf | 103 |
1 files changed, 82 insertions, 21 deletions
@@ -45,26 +45,27 @@ 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 Show this help text\n"; -printf " -t Show thumbnails (requires ueberzug)\n"; -printf " Doesn't work with -H -D\n"; -printf " -D Use external menu(default dmenu) instead of fzf \n"; -printf " -H Choose from history \n"; -printf " -x Delete history\n"; -printf " -m <search-query> Audio only (for music)\n"; -printf " -d <search-query> Download to current directory\n"; -printf " -f <search-query> Show available formats before proceeding\n"; -printf " -a <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> To specify number of videos to select with -a or -r\n"; -printf " -l <search-query> Loop: prompt selector again after video ends\n"; -printf " -s <search-query> After the video ends make another search \n"; -printf " -L <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 <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 can be combined. Like\n" -printf " ytfzf -fDH to show history using external \n" -printf " menu and show formats\n" +printf " Option usage:\n" +printf " ytfzf -fDH to show history using external \n" +printf " menu and show formats\n" +printf " ytfzf -fD --choose-from-history same as above\n" printf "\n" printf " Defaults can be modified through ENV variables\n"; printf " Defaults:\n"; @@ -411,9 +412,68 @@ random_select=0 search_again=0 show_format=0 link_count=1 -# OPT -while getopts "LhDmdfxHarltsn:U:" opt; do + +#OPT +while getopts "LhDmdfxHarltsn:U:-:" opt; do 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; + ;; + + esac + ;; + #Short options h) helpinfo exit; ;; @@ -452,13 +512,14 @@ while getopts "LhDmdfxHarltsn:U:" opt; do # Not to be used by explicitly ;; *) - printf "Option not found!\n" + printf "${OPT-Option} not found!\n" usageinfo exit 2; ;; esac done shift $((OPTIND-1)) + [ "$*" = "-" ] && is_stdin=1 || is_stdin=0 search_query="$*" check_if_url "$search_query" |