diff --git a/CMakeLists.txt b/CMakeLists.txt index 75f21f6..a073be0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ if(BUILD_ENABLE_DEBUG) endif() set(SYSCONFDIR "/etc" CACHE STRING "system config dir") +set(DATADIR "${CMAKE_INSTALL_PREFIX}/share" CACHE STRING "shared data dir") find_package(PkgConfig) pkg_check_modules (GLIB2 REQUIRED glib-2.0) diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index b28fa2b..e67277e 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -1,7 +1,4 @@ - -########### install files ############### - -install( +INSTALL( PROGRAMS miracle-gst gstplayer uibc-viewer DESTINATION bin ) @@ -10,3 +7,8 @@ INSTALL( FILES org.freedesktop.miracle.conf DESTINATION ${SYSCONFDIR}/dbus-1/system.d ) + +INSTALL( + FILES miracle-wifid miracle-sinkctl miracle-wifictl + DESTINATION ${DATADIR}/bash-completion/completions + ) diff --git a/res/Makefile.am b/res/Makefile.am index 9e73673..b11d0b3 100644 --- a/res/Makefile.am +++ b/res/Makefile.am @@ -5,5 +5,5 @@ dbuspolicydir=$(sysconfdir)/dbus-1/system.d dbuspolicy_DATA = org.freedesktop.miracle.conf bashcompletiondir=${datadir}/bash-completion/completions -bashcompletion_DATA=miraclecast-completion +bashcompletion_DATA=miracle-wifid miracle-sinkctl miracle-wifictl diff --git a/res/meson.build b/res/meson.build index 1b331ad..037a759 100644 --- a/res/meson.build +++ b/res/meson.build @@ -6,3 +6,8 @@ install_data( install_data('miracle-gst', 'gstplayer', 'uibc-viewer', install_dir: get_option('bindir'), install_mode: 'rwxr-xr-x') + +install_data( + 'miracle-wifid', 'miracle-sinkctl', 'miracle-wifictl', + install_dir: join_paths(get_option('datadir'), 'bash-completions', 'completions') +) diff --git a/res/miracle-sinkctl b/res/miracle-sinkctl new file mode 100755 index 0000000..a14c0bb --- /dev/null +++ b/res/miracle-sinkctl @@ -0,0 +1,85 @@ +# +# Autocompletion for miraclecast commands +# +# Maintainer: Alberto Fanjul +# + +function _miracle-sinkctl() { + local cur prev + + _get_comp_words_by_ref cur + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --log-level) + COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur")) + return 0 + ;; + esac + + COMPREPLY=($(compgen -W "$(_parse_help miracle-sinkctl) $(_parse_short_help miracle-sinkctl)" -- "$cur")) +} + +_parse_short_help () +{ + eval local cmd=$( quote "$1" ); + local line; + { + case $cmd in + -) + cat + ;; + *) + LC_ALL=C "$( dequote "$cmd" )" ${2:---help} 2>&1 + ;; + esac + } | while read -r line; do + [[ $line == *([[:blank:]])-* ]] || continue; + while [[ $line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do + line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}; + done; + __parse_short_options "${line// or /, }"; + done +} + +__parse_short_options () +{ + local option option2 i IFS=' +,/|'; + option=; + local -a array; + read -a array <<< "$1"; + for i in "${array[@]}"; + do + case "$i" in + ---*) + break + ;; + --?*) + break + ;; + -?*) + option=$i; + break + ;; + *) + break + ;; + esac; + done; + [[ -n $option ]] || return; + IFS=' +'; + if [[ $option =~ (\[((no|dont)-?)\]). ]]; then + option2=${option/"${BASH_REMATCH[1]}"/}; + option2=${option2%%[<{().[]*}; + printf '%s\n' "${option2/=*/=}"; + option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"}; + fi; + option=${option%%[<{().[]*}; + printf '%s\n' "${option/=*/=}" +} + +complete -F _miracle-sinkctl miracle-sinkctl + +# ex: filetype=sh diff --git a/res/miracle-wifictl b/res/miracle-wifictl new file mode 100755 index 0000000..07fc4ae --- /dev/null +++ b/res/miracle-wifictl @@ -0,0 +1,85 @@ +# +# Autocompletion for miracle-wifictl +# +# Maintainer: Alberto Fanjul +# + +function _miracle-wifictl() { + local cur prev + + _get_comp_words_by_ref cur + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --log-level) + COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur")) + return 0 + ;; + esac + + COMPREPLY=($(compgen -W "$(_parse_help miracle-wifictl) $(_parse_short_help miracle-wifictl)" -- "$cur")) +} + +_parse_short_help () +{ + eval local cmd=$( quote "$1" ); + local line; + { + case $cmd in + -) + cat + ;; + *) + LC_ALL=C "$( dequote "$cmd" )" ${2:---help} 2>&1 + ;; + esac + } | while read -r line; do + [[ $line == *([[:blank:]])-* ]] || continue; + while [[ $line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do + line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}; + done; + __parse_short_options "${line// or /, }"; + done +} + +__parse_short_options () +{ + local option option2 i IFS=' +,/|'; + option=; + local -a array; + read -a array <<< "$1"; + for i in "${array[@]}"; + do + case "$i" in + ---*) + break + ;; + --?*) + break + ;; + -?*) + option=$i; + break + ;; + *) + break + ;; + esac; + done; + [[ -n $option ]] || return; + IFS=' +'; + if [[ $option =~ (\[((no|dont)-?)\]). ]]; then + option2=${option/"${BASH_REMATCH[1]}"/}; + option2=${option2%%[<{().[]*}; + printf '%s\n' "${option2/=*/=}"; + option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"}; + fi; + option=${option%%[<{().[]*}; + printf '%s\n' "${option/=*/=}" +} + +complete -F _miracle-wifictl miracle-wifictl + +# ex: filetype=sh diff --git a/res/miraclecast-completion b/res/miracle-wifid similarity index 69% rename from res/miraclecast-completion rename to res/miracle-wifid index 1d82b32..1f320bd 100755 --- a/res/miraclecast-completion +++ b/res/miracle-wifid @@ -1,7 +1,5 @@ -#!/bin/bash - # -# Autocompletion for miraclecast commands +# Autocompletion for miracle-wifid # # Maintainer: Alberto Fanjul # @@ -13,6 +11,10 @@ function _miracle-wifid() { prev=${COMP_WORDS[COMP_CWORD-1]} case "$prev" in + --config-methods) + COMPREPLY=($(compgen -W 'pbc pin usba ethernet label display ext_nfc_token int_nfc_token nfc_interface push_button keypad virtual_display physical_display virtual_push_button physical_push_button' -- "$cur")) + return 0 + ;; --log-level) COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur")) return 0 @@ -26,43 +28,6 @@ function _miracle-wifid() { COMPREPLY=($(compgen -W "$(_parse_help miracle-wifid) $(_parse_short_help miracle-wifid)" -- "$cur")) } -complete -F _miracle-wifid miracle-wifid - -function _miracle-sinkctl() { - local cur prev - - _get_comp_words_by_ref cur - prev=${COMP_WORDS[COMP_CWORD-1]} - - case "$prev" in - --log-level) - COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur")) - return 0 - ;; - esac - - COMPREPLY=($(compgen -W "$(_parse_help miracle-sinkctl) $(_parse_short_help miracle-sinkctl)" -- "$cur")) -} - -complete -F _miracle-sinkctl miracle-sinkctl - -function _miracle-wifictl() { - local cur prev - - _get_comp_words_by_ref cur - prev=${COMP_WORDS[COMP_CWORD-1]} - - case "$prev" in - --log-level) - COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur")) - return 0 - ;; - esac - - COMPREPLY=($(compgen -W "$(_parse_help miracle-wifictl) $(_parse_short_help miracle-wifictl)" -- "$cur")) -} - -complete -F _miracle-wifictl miracle-wifictl _parse_short_help () { @@ -124,3 +89,7 @@ __parse_short_options () printf '%s\n' "${option/=*/=}" } +complete -F _miracle-wifid miracle-wifid + + +# ex: filetype=sh