mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
shell-completion: replace printf with echo
It is faster to use a bash built-in, then to invoke an external program. The problem of unit names starting with a dash is solved by prepending a space. Spaces are ignored anyway. For zsh, replace echo "$unit", which is vulnerable to dashes, with echo " $unit".
This commit is contained in:
parent
75add28aa1
commit
79c1638303
@ -36,25 +36,25 @@ __filter_units_by_property () {
|
|||||||
<(__systemctl $mode show --property "$property" -- "${units[@]}")
|
<(__systemctl $mode show --property "$property" -- "${units[@]}")
|
||||||
for ((i=0; $i < ${#units[*]}; i++)); do
|
for ((i=0; $i < ${#units[*]}; i++)); do
|
||||||
if [[ "${props[i]}" = "$property=$value" ]]; then
|
if [[ "${props[i]}" = "$property=$value" ]]; then
|
||||||
printf "%s\n" "${units[i]}"
|
echo " ${units[i]}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
__get_all_units () { __systemctl $1 list-units --all \
|
__get_all_units () { __systemctl $1 list-units --all \
|
||||||
| { while read -r a b; do printf "%s\n" "$a"; done; }; }
|
| { while read -r a b; do echo " $a"; done; }; }
|
||||||
__get_active_units () { __systemctl $1 list-units \
|
__get_active_units () { __systemctl $1 list-units \
|
||||||
| { while read -r a b; do printf "%s\n" "$a"; done; }; }
|
| { while read -r a b; do echo " $a"; done; }; }
|
||||||
__get_inactive_units () { __systemctl $1 list-units --all \
|
__get_inactive_units () { __systemctl $1 list-units --all \
|
||||||
| { while read -r a b c d; do [[ $c == "inactive" ]] && printf "%s\n" "$a"; done; }; }
|
| { while read -r a b c d; do [[ $c == "inactive" ]] && echo " $a"; done; }; }
|
||||||
__get_failed_units () { __systemctl $1 list-units \
|
__get_failed_units () { __systemctl $1 list-units \
|
||||||
| { while read -r a b c d; do [[ $c == "failed" ]] && printf "%s\n" "$a"; done; }; }
|
| { while read -r a b c d; do [[ $c == "failed" ]] && echo " $a"; done; }; }
|
||||||
__get_enabled_units () { __systemctl $1 list-unit-files \
|
__get_enabled_units () { __systemctl $1 list-unit-files \
|
||||||
| { while read -r a b c ; do [[ $b == "enabled" ]] && printf "%s\n" "$a"; done; }; }
|
| { while read -r a b c ; do [[ $b == "enabled" ]] && echo " $a"; done; }; }
|
||||||
__get_disabled_units () { __systemctl $1 list-unit-files \
|
__get_disabled_units () { __systemctl $1 list-unit-files \
|
||||||
| { while read -r a b c ; do [[ $b == "disabled" ]] && printf "%s\n" "$a"; done; }; }
|
| { while read -r a b c ; do [[ $b == "disabled" ]] && echo " $a"; done; }; }
|
||||||
__get_masked_units () { __systemctl $1 list-unit-files \
|
__get_masked_units () { __systemctl $1 list-unit-files \
|
||||||
| { while read -r a b c ; do [[ $b == "masked" ]] && printf "%s\n" "$a"; done; }; }
|
| { while read -r a b c ; do [[ $b == "masked" ]] && echo " $a"; done; }; }
|
||||||
|
|
||||||
_systemctl () {
|
_systemctl () {
|
||||||
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
|
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||||
@ -153,14 +153,14 @@ _systemctl () {
|
|||||||
comps=$( __filter_units_by_property $mode CanStart yes \
|
comps=$( __filter_units_by_property $mode CanStart yes \
|
||||||
$( __get_inactive_units $mode \
|
$( __get_inactive_units $mode \
|
||||||
| while read -r line; do \
|
| while read -r line; do \
|
||||||
[[ "$line" =~ \.(device|snapshot)$ ]] || printf "%s\n" "$line"; \
|
[[ "$line" =~ \.(device|snapshot)$ ]] || echo " $line"; \
|
||||||
done ))
|
done ))
|
||||||
|
|
||||||
elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
|
elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
|
||||||
comps=$( __filter_units_by_property $mode CanStart yes \
|
comps=$( __filter_units_by_property $mode CanStart yes \
|
||||||
$( __get_all_units $mode \
|
$( __get_all_units $mode \
|
||||||
| while read -r line; do \
|
| while read -r line; do \
|
||||||
[[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || printf "%s\n" "$line"; \
|
[[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || echo " $line"; \
|
||||||
done ))
|
done ))
|
||||||
|
|
||||||
elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
|
elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
|
||||||
@ -185,15 +185,15 @@ _systemctl () {
|
|||||||
comps=''
|
comps=''
|
||||||
|
|
||||||
elif __contains_word "$verb" ${VERBS[JOBS]}; then
|
elif __contains_word "$verb" ${VERBS[JOBS]}; then
|
||||||
comps=$( __systemctl $mode list-jobs | { while read -r a b; do printf "%s\n" "$a"; done; } )
|
comps=$( __systemctl $mode list-jobs | { while read -r a b; do echo " $a"; done; } )
|
||||||
|
|
||||||
elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
|
elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
|
||||||
comps=$( __systemctl $mode list-units --type snapshot --full --all \
|
comps=$( __systemctl $mode list-units --type snapshot --full --all \
|
||||||
| { while read -r a b; do printf "%s\n" "$a"; done; } )
|
| { while read -r a b; do echo " $a"; done; } )
|
||||||
|
|
||||||
elif __contains_word "$verb" ${VERBS[ENVS]}; then
|
elif __contains_word "$verb" ${VERBS[ENVS]}; then
|
||||||
comps=$( __systemctl $mode show-environment \
|
comps=$( __systemctl $mode show-environment \
|
||||||
| while read -r line; do printf "%s\n" "${line%%=*}=";done )
|
| while read -r line; do echo " ${line%%=*}=";done )
|
||||||
compopt -o nospace
|
compopt -o nospace
|
||||||
|
|
||||||
elif __contains_word "$verb" ${VERBS[FILE]}; then
|
elif __contains_word "$verb" ${VERBS[FILE]}; then
|
||||||
|
@ -416,7 +416,7 @@ _systemctl_all_units()
|
|||||||
if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
|
if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
|
||||||
! _retrieve_cache SYS_ALL_UNITS;
|
! _retrieve_cache SYS_ALL_UNITS;
|
||||||
then
|
then
|
||||||
_sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo "$a"; done; }) )
|
_sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo " $a"; done; }) )
|
||||||
_store_cache SYS_ALL_UNITS _sys_all_units
|
_store_cache SYS_ALL_UNITS _sys_all_units
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -429,7 +429,7 @@ _systemctl_really_all_units()
|
|||||||
if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
|
if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
|
||||||
! _retrieve_cache SYS_REALLY_ALL_UNITS;
|
! _retrieve_cache SYS_REALLY_ALL_UNITS;
|
||||||
then
|
then
|
||||||
all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo "$a"; done; }) )
|
all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo " $a"; done; }) )
|
||||||
_systemctl_all_units
|
_systemctl_all_units
|
||||||
really_all_units=($_sys_all_units $all_unit_files)
|
really_all_units=($_sys_all_units $all_unit_files)
|
||||||
_sys_really_all_units=(${(u)really_all_units})
|
_sys_really_all_units=(${(u)really_all_units})
|
||||||
@ -449,17 +449,17 @@ _filter_units_by_property() {
|
|||||||
unit=${units[i]}
|
unit=${units[i]}
|
||||||
prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
|
prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
|
||||||
if [[ "${prop}" = "$property=$value" ]]; then
|
if [[ "${prop}" = "$property=$value" ]]; then
|
||||||
echo "${unit}"
|
echo " ${unit}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read a b; do echo "$a"; done; }) )}
|
_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read a b; do echo " $a"; done; }) )}
|
||||||
_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all | { while read a b c d; do [[ $c == "inactive" ]] && echo "$a"; done; }) )}
|
_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all | { while read a b c d; do [[ $c == "inactive" ]] && echo " $a"; done; }) )}
|
||||||
_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read a b; do echo "$a"; done; }) )}
|
_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read a b; do echo " $a"; done; }) )}
|
||||||
_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "enabled" ]] && echo "$a"; done; }) )}
|
_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "enabled" ]] && echo " $a"; done; }) )}
|
||||||
_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read a b; do [[ $b == "disabled" ]] && echo "$a"; done; }) )}
|
_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read a b; do [[ $b == "disabled" ]] && echo " $a"; done; }) )}
|
||||||
_systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "masked" ]] && echo "$a"; done; }) )}
|
_systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "masked" ]] && echo " $a"; done; }) )}
|
||||||
|
|
||||||
# Completion functions for ALL_UNITS
|
# Completion functions for ALL_UNITS
|
||||||
for fun in is-active is-failed is-enabled status show mask preset ; do
|
for fun in is-active is-failed is-enabled status show mask preset ; do
|
||||||
@ -535,7 +535,7 @@ for fun in restart reload-or-restart ; do
|
|||||||
_systemctl_all_units
|
_systemctl_all_units
|
||||||
compadd "$@" - $( _filter_units_by_property CanStart yes \
|
compadd "$@" - $( _filter_units_by_property CanStart yes \
|
||||||
${_sys_all_units[*]} | while read line; do \
|
${_sys_all_units[*]} | while read line; do \
|
||||||
[[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || echo "$line"; \
|
[[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || echo " $line"; \
|
||||||
done )
|
done )
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
@ -572,7 +572,7 @@ for fun in set-environment unset-environment ; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
compadd "$@" ${suf} - $(systemctl show-environment \
|
compadd "$@" ${suf} - $(systemctl show-environment \
|
||||||
| while read line; do echo "${line%%\=}";done )
|
| while read line; do echo " ${line%%\=}";done )
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -638,9 +638,9 @@ _journal_fields() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_loginctl_all_sessions(){_sys_all_sessions=($(loginctl list-sessions | { while read a b; do echo "$a"; done; }) )}
|
_loginctl_all_sessions(){_sys_all_sessions=($(loginctl list-sessions | { while read a b; do echo " $a"; done; }) )}
|
||||||
_loginctl_all_users() {_sys_all_users=( $(loginctl list-users | { while read a b; do echo "$a"; done; }) )}
|
_loginctl_all_users() {_sys_all_users=( $(loginctl list-users | { while read a b; do echo " $a"; done; }) )}
|
||||||
_loginctl_all_seats() {_sys_all_seats=( $(loginctl list-seats | { while read a b; do echo "$a"; done; }) )}
|
_loginctl_all_seats() {_sys_all_seats=( $(loginctl list-seats | { while read a b; do echo " $a"; done; }) )}
|
||||||
|
|
||||||
# Completion functions for SESSIONS
|
# Completion functions for SESSIONS
|
||||||
for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
|
for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
|
||||||
|
Loading…
Reference in New Issue
Block a user