mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-12 18:51:56 +00:00
bash completion with lazy load
This commit is contained in:
parent
5bfc97a72c
commit
ec7e11c8bf
7 changed files with 192 additions and 45 deletions
|
@ -21,6 +21,7 @@ if(BUILD_ENABLE_DEBUG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SYSCONFDIR "/etc" CACHE STRING "system config dir")
|
set(SYSCONFDIR "/etc" CACHE STRING "system config dir")
|
||||||
|
set(DATADIR "${CMAKE_INSTALL_PREFIX}/share" CACHE STRING "shared data dir")
|
||||||
|
|
||||||
find_package(PkgConfig)
|
find_package(PkgConfig)
|
||||||
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
|
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
|
INSTALL(
|
||||||
########### install files ###############
|
|
||||||
|
|
||||||
install(
|
|
||||||
PROGRAMS miracle-gst gstplayer uibc-viewer
|
PROGRAMS miracle-gst gstplayer uibc-viewer
|
||||||
DESTINATION bin
|
DESTINATION bin
|
||||||
)
|
)
|
||||||
|
@ -10,3 +7,8 @@ INSTALL(
|
||||||
FILES org.freedesktop.miracle.conf
|
FILES org.freedesktop.miracle.conf
|
||||||
DESTINATION ${SYSCONFDIR}/dbus-1/system.d
|
DESTINATION ${SYSCONFDIR}/dbus-1/system.d
|
||||||
)
|
)
|
||||||
|
|
||||||
|
INSTALL(
|
||||||
|
FILES miracle-wifid miracle-sinkctl miracle-wifictl
|
||||||
|
DESTINATION ${DATADIR}/bash-completion/completions
|
||||||
|
)
|
||||||
|
|
|
@ -5,5 +5,5 @@ dbuspolicydir=$(sysconfdir)/dbus-1/system.d
|
||||||
dbuspolicy_DATA = org.freedesktop.miracle.conf
|
dbuspolicy_DATA = org.freedesktop.miracle.conf
|
||||||
|
|
||||||
bashcompletiondir=${datadir}/bash-completion/completions
|
bashcompletiondir=${datadir}/bash-completion/completions
|
||||||
bashcompletion_DATA=miraclecast-completion
|
bashcompletion_DATA=miracle-wifid miracle-sinkctl miracle-wifictl
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,8 @@ install_data(
|
||||||
install_data('miracle-gst', 'gstplayer', 'uibc-viewer',
|
install_data('miracle-gst', 'gstplayer', 'uibc-viewer',
|
||||||
install_dir: get_option('bindir'),
|
install_dir: get_option('bindir'),
|
||||||
install_mode: 'rwxr-xr-x')
|
install_mode: 'rwxr-xr-x')
|
||||||
|
|
||||||
|
install_data(
|
||||||
|
'miracle-wifid', 'miracle-sinkctl', 'miracle-wifictl',
|
||||||
|
install_dir: join_paths(get_option('datadir'), 'bash-completions', 'completions')
|
||||||
|
)
|
||||||
|
|
85
res/miracle-sinkctl
Executable file
85
res/miracle-sinkctl
Executable file
|
@ -0,0 +1,85 @@
|
||||||
|
#
|
||||||
|
# Autocompletion for miraclecast commands
|
||||||
|
#
|
||||||
|
# Maintainer: Alberto Fanjul <albertofanjul@gmail.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
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
|
85
res/miracle-wifictl
Executable file
85
res/miracle-wifictl
Executable file
|
@ -0,0 +1,85 @@
|
||||||
|
#
|
||||||
|
# Autocompletion for miracle-wifictl
|
||||||
|
#
|
||||||
|
# Maintainer: Alberto Fanjul <albertofanjul@gmail.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
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
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Autocompletion for miraclecast commands
|
# Autocompletion for miracle-wifid
|
||||||
#
|
#
|
||||||
# Maintainer: Alberto Fanjul <albertofanjul@gmail.com>
|
# Maintainer: Alberto Fanjul <albertofanjul@gmail.com>
|
||||||
#
|
#
|
||||||
|
@ -13,6 +11,10 @@ function _miracle-wifid() {
|
||||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||||
|
|
||||||
case "$prev" in
|
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)
|
--log-level)
|
||||||
COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur"))
|
COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
|
@ -26,43 +28,6 @@ function _miracle-wifid() {
|
||||||
COMPREPLY=($(compgen -W "$(_parse_help miracle-wifid) $(_parse_short_help miracle-wifid)" -- "$cur"))
|
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 ()
|
_parse_short_help ()
|
||||||
{
|
{
|
||||||
|
@ -124,3 +89,7 @@ __parse_short_options ()
|
||||||
printf '%s\n' "${option/=*/=}"
|
printf '%s\n' "${option/=*/=}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
complete -F _miracle-wifid miracle-wifid
|
||||||
|
|
||||||
|
|
||||||
|
# ex: filetype=sh
|
Loading…
Reference in a new issue