Re: [systemd-devel] [PATCH] zsh-completion: fix completion of --user services

2015-06-17 Thread Eric Cook
On 06/17/2015 12:34 PM, Lennart Poettering wrote:
> On Mon, 18.05.15 18:45, Eric Cook (l...@gmx.com) wrote:
> 
>> By the time __systemctl is called, --user/--system are shifted out of
>> `words' by _arguments. This patch queries the array sooner. 
>>
>> In the case that both --user and --system are on the line when compsys runs,
>> _sys_service_mgr is set to the latter. Which is seemingly how systemctl 
>> behaves.
>>
>> If neither are on the line, --system is set; for system services to be 
>> completed.
> 
> Is this still an issue? If so, could you post this patch as a PR on
> github for review?
> 
> Lennart
> 
It was submitted on github and merged a while ago. So no, but thank you for 
checking up on it.
https://github.com/systemd/systemd/commit/68c4f6d406a2bdac6957a67a077f182b0287cc3b
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] zsh-completion: a more style/tag aware _systemctl

2015-05-29 Thread Eric Cook
using _wanted instead of calling compadd directly. this allows the user to 
customize
possible matches.

An example being, grouping units by type:
autoload -Uz compinit; compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' group-name ''
zstyle ':completion:*' format 'Completing %d'
zstyle -e ':completion:*:*:systemctl-(((re|)en|dis)able|(*re|)start|reload*):*' 
\
tag-order 'local type; for type in service template target socket;
reply+=( systemd-units:-${type}:${type} ); reply=( "$reply 
systemd-units:-misc:misc" )'
zstyle ':completion:*:systemd-units-template' ignored-patterns '^*@'
zstyle ':completion:*:systemd-units-target' ignored-patterns '^*.target'
zstyle ':completion:*:systemd-units-socket' ignored-patterns '^*.socket'
zstyle ':completion:*:systemd-units-service' ignored-patterns '^*.service'
zstyle ':completion:*:systemd-units-misc' ignored-patterns 
'*(@|.(service|socket|target))'

also,  
http://lists.freedesktop.org/archives/systemd-devel/2015-May/032012.html

---
 shell-completion/zsh/_systemctl.in | 60 +++---
 1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index db9bdb6..e11671f 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -65,7 +65,7 @@
   if (( CURRENT == 1 )); then
 _describe -t commands 'systemctl command' _systemctl_cmds || compadd "$@"
   else
-local curcontext="$curcontext"
+local curcontext="$curcontext" expl
 
 cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}"
 # Deal with any aliases
@@ -172,7 +172,8 @@ for fun in is-active is-failed is-enabled status show cat 
mask preset help list-
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
 _systemctl_really_all_units
-compadd "$@" -a - _sys_really_all_units
+_wanted systemd-units expl unit \
+  compadd "$@" -a - _sys_really_all_units
   }
 done
 
@@ -180,34 +181,39 @@ done
 (( $+functions[_systemctl_disable] )) || _systemctl_disable()
 {
 local _sys_unit_state; _systemctl_unit_state
-compadd "$@" - ${(k)_sys_unit_state[(R)enabled]}
+_wanted systemd-units expl 'enabled unit' \
+  compadd "$@" - ${(k)_sys_unit_state[(R)enabled]}
 }
 
 (( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
 {
 local _sys_unit_state; _systemctl_unit_state
-compadd "$@" - ${(k)_sys_unit_state[(R)(enabled|disabled)]} 
$(_systemctl_get_template_names)
+_wanted systemd-units expl 'enabled/disabled unit' \
+  compadd "$@" - ${(k)_sys_unit_state[(R)(enabled|disabled)]} 
$(_systemctl_get_template_names)
 }
 
 # Completion functions for DISABLED_UNITS
 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
 {
   local _sys_unit_state; _systemctl_unit_state
-  compadd "$@" - ${(k)_sys_unit_state[(R)disabled]} 
$(_systemctl_get_template_names)
+  _wanted systemd-units expl 'disabled unit' \
+compadd "$@" - ${(k)_sys_unit_state[(R)disabled]} 
$(_systemctl_get_template_names)
 }
 
 # Completion functions for FAILED_UNITS
 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
 {
   local _sys_failed_units; _systemctl_failed_units
-  compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
+  _wanted systemd-units expl 'failed unit' \
+compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
 }
 
 # Completion functions for STARTABLE_UNITS
 (( $+functions[_systemctl_start] )) || _systemctl_start()
 {
local _sys_startable_units; _systemctl_startable_units
-   compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
+   _wanted systemd-units expl 'startable unit' \
+ compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
 }
 
 # Completion functions for STOPPABLE_UNITS
@@ -215,8 +221,9 @@ for fun in stop kill try-restart condrestart ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
 local _sys_active_units; _systemctl_active_units
-compadd "$@" - $( _filter_units_by_property CanStop yes \
-  ${_sys_active_units[*]} )
+_wanted systemd-units expl 'stoppable unit' \
+  compadd "$@" - $( _filter_units_by_property CanStop yes \
+${_sys_active_units[*]} )
   }
 done
 
@@ -224,8 +231,9 @@ done
 (( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
 {
   _systemctl_all_units
-  compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
-${_sys_all_units[*]} )
+  _wanted systemd-units expl 'isolatable unit' \
+compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
+  ${_sys_all_units[*]} )
 }
 
 # Completion functions for RELOADABLE_UNITS
@@ -233,8 +241,9 @@ for fun in reload reload-or-try-restart force-reload ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
 local _sys_active_units; _systemctl_active_units
-compadd "$@" - $( _filter_units_by_property CanReload yes \
-  ${_sys_active_units[*]} )
+

[systemd-devel] [PATCH] zsh-completion: fix completion of --user services

2015-05-18 Thread Eric Cook
By the time __systemctl is called, --user/--system are shifted out of
`words' by _arguments. This patch queries the array sooner. 

In the case that both --user and --system are on the line when compsys runs,
_sys_service_mgr is set to the latter. Which is seemingly how systemctl behaves.

If neither are on the line, --system is set; for system services to be 
completed.
---
 shell-completion/zsh/_systemctl.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 1dc6406..bd5eece 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -93,9 +93,7 @@
 
 __systemctl()
 {
-  local -a _modes
-  _modes=("--user" "--system")
-  systemctl ${words:*_modes} --full --no-legend --no-pager "$@"
+  systemctl $_sys_service_mgr --full --no-legend --no-pager "$@"
 }
 
 
@@ -355,6 +353,8 @@ _job_modes() {
 _values -s , "${_modes[@]}"
 }
 
+local -a _modes; _modes=("--user" "--system")
+local _sys_service_mgr=${${words:*_modes}[(R)(${(j.|.)_modes})]:---system}
 _arguments -s \
 {-h,--help}'[Show help]' \
 '--version[Show package version]' \
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v2 5/6] zsh-completion: removing more pointless forks

2015-05-18 Thread Eric Cook
I seem to have forgot about _systemctl_active_units().

---
 shell-completion/zsh/_systemctl.in | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index a4db563..d3e7ee2 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -105,7 +105,7 @@ _systemctl_all_units()
   if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
 ! _retrieve_cache SYS_ALL_UNITS;
   then
-_sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do 
echo -E - " $a"; done; }) )
+_sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} )
 _store_cache SYS_ALL_UNITS _sys_all_units
   fi
 }
@@ -118,7 +118,7 @@ _systemctl_really_all_units()
   if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid 
SYS_REALLY_ALL_UNITS ) &&
 ! _retrieve_cache SYS_REALLY_ALL_UNITS;
   then
-all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do 
echo -E - " $a"; done; }) )
+all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} )
 _systemctl_all_units
 really_all_units=($_sys_all_units $all_unit_files)
 _sys_really_all_units=(${(u)really_all_units})
@@ -146,7 +146,7 @@ _filter_units_by_property() {
 _systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl 
list-unit-files)"}##*@.[^[:space:]]##}%%@.*}\@ }
 
 
-_systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units  
| { while read -r a b; do echo -E - " $a"; done; }) )}
+_systemctl_active_units()  {_sys_active_units=(  ${${(f)"$(__systemctl 
list-units)"}%% *} )}
 
 _systemctl_startable_units(){
 _sys_startable_units=( $( _filter_units_by_property ActiveState inactive $(
@@ -259,22 +259,22 @@ done
 # Completion functions for JOBS
 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
 {
-  compadd "$@" - $(__systemctl list-jobs \
-| cut -d' ' -f1  2>/dev/null ) || _message "no jobs found"
+  compadd "$@" - ${${(f)"$(__systemctl list-jobs)"}%% *} ||
+_message "no jobs found"
 }
 
 # Completion functions for SNAPSHOTS
 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
 {
-  compadd "$@" - $(__systemctl list-units --type snapshot --all \
-| cut -d' ' -f1  2>/dev/null ) || _message "no snapshots found"
+  compadd "$@" - ${${(f)"$(__systemctl list-units --type snapshot --all)"}%% 
*} ||
+_message "no snapshots found"
 }
 
 # Completion functions for TARGETS
 (( $+functions[_systemctl_set-default] )) || _systemctl_set-default()
 {
-  compadd "$@" - $(__systemctl list-unit-files --type target --all \
-| cut -d' ' -f1  2>/dev/null ) || _message "no targets found"
+  compadd "$@" - ${${(f)"$(__systemctl list-unit-files --type target 
--all)"}%% *} ||
+_message "no targets found"
 }
 
 # Completion functions for ENVS
@@ -287,8 +287,7 @@ for fun in set-environment unset-environment ; do
   suf='-S='
 fi
 
-compadd "$@" ${suf} - $(systemctl show-environment \
-  | while read line; do echo " ${line%%\=}";done )
+compadd "$@" ${suf} - ${${(f)"$(systemctl show-environment)"}%%=*}
   }
 done
 
@@ -315,7 +314,7 @@ _systemctl_caching_policy()
   oldcache=( "$1"(mh+1) )
   (( $#oldcache )) && return 0
 
-  _sysunits=($(__systemctl --all | cut -d' ' -f1))
+  _sysunits=(${${(f)"$(__systemctl --all)"}%% *})
 
   if (( $#_sysunits )); then
 for unit in $_sysunits; do
@@ -342,10 +341,9 @@ _unit_properties() {
   if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid 
SYS_ALL_PROPERTIES ) &&
 ! _retrieve_cache SYS_ALL_PROPERTIES;
   then
-_sys_all_properties=( $( {__systemctl show --all;
-   @rootlibexecdir@/systemd --dump-configuration-items; } | {
-   while IFS='=' read -r a b; do [ -n "$b" ] && echo "$a"; done
-}) )
+_sys_all_properties=( ${${(M)${(f)"$(__systemctl show --all;
+@rootlibexecdir@/systemd 
--dump-configuration-items)"}##[[:alnum:]]##=*}%%=*}
+)
 _store_cache SYS_ALL_PROPRTIES _sys_all_properties
   fi
   _values -s , "${_sys_all_properties[@]}"
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 1/6] zsh-completion: actually run _filter_units_by_property when creating the arrays _sys_(re|)startable_units

2015-05-17 Thread Eric Cook
---
 shell-completion/zsh/_systemctl.in | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index cce9dea..8764e07 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -149,20 +149,20 @@ _systemctl_get_template_names() { __systemctl 
list-unit-files | { while read -r
 _systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units  
| { while read -r a b; do echo -E - " $a"; done; }) )}
 
 _systemctl_startable_units(){
-_sys_startable_units=(_filter_units_by_property ActiveState inactive $(
+_sys_startable_units=( $( _filter_units_by_property ActiveState inactive $(
   _filter_units_by_property CanStart yes $(
   __systemctl $mode list-unit-files --state 
enabled,disabled,static | \
{ while read -r a b; do [[ $a =~ @\. ]] || echo 
-E - " $a"; done; }
   __systemctl $mode list-units --state inactive,failed 
| \
-   { while read -r a b; do echo -E - " $a"; done; 
} )))
+   { while read -r a b; do echo -E - " $a"; done; 
} )) ) )
 }
 
 _systemctl_restartable_units(){
-_sys_restartable_units=(_filter_units_by_property CanStart yes $(
+_sys_restartable_units=( $(_filter_units_by_property CanStart yes $(
   __systemctl $mode list-unit-files --state 
enabled,disabled,static | \
{ while read -r a b; do [[ $a =~ @\. ]] || echo 
-E - " $a"; done; }
   __systemctl $mode list-units | \
-   { while read -r a b; do echo -E - " $a"; done; 
} ))
+   { while read -r a b; do echo -E - " $a"; done; 
} )) )
 }
 
 _systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units 
--failed | { while read -r a b; do echo -E - " $a"; done; }) )}
@@ -170,6 +170,7 @@ _systemctl_enabled_units() {_sys_enabled_units=( 
$(__systemctl list-unit-files
 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; 
}) )}
 _systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) 
)}
 
+local fun
 # Completion functions for ALL_UNITS
 for fun in is-active is-failed is-enabled status show cat mask preset help 
list-dependencies edit ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 3/6] zsh-completion: less forking in _systemctl_get_template_names()

2015-05-17 Thread Eric Cook
---
 shell-completion/zsh/_systemctl.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index f30fb84..5a39cfb 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -143,7 +143,7 @@ _filter_units_by_property() {
   done
 }
 
-_systemctl_get_template_names() { __systemctl list-unit-files | { while read 
-r a b; do  [[ $a =~ @\. ]] && echo -E - " ${a%%@.*}@"; done; } }
+_systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl 
list-unit-files)"}##*@.[^[:space:]]##}%%@.*}\@ }
 
 
 _systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units  
| { while read -r a b; do echo -E - " $a"; done; }) )}
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 4/6] zsh-completion: less forking in _systemctl_failed_units() and make the array `_sys_failed_units' local to the completer.

2015-05-17 Thread Eric Cook
---
 shell-completion/zsh/_systemctl.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 5a39cfb..a4db563 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -165,7 +165,7 @@ _systemctl_restartable_units(){
{ while read -r a b; do echo -E - " $a"; done; 
} )) )
 }
 
-_systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units 
--failed | { while read -r a b; do echo -E - " $a"; done; }) )}
+_systemctl_failed_units()  {_sys_failed_units=( ${${(f)"$(__systemctl 
list-units --failed)"}%% *} ) }
 _systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( 
$(__systemctl list-unit-files) ) }
 
 local fun
@@ -201,7 +201,7 @@ done
 # Completion functions for FAILED_UNITS
 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
 {
-  _systemctl_failed_units
+  local _sys_failed_units; _systemctl_failed_units
   compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
 }
 
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 2/6] zsh-completion: actually complete template names for subcommands enable, reenable and disable.

2015-05-17 Thread Eric Cook
compadd's -a option treats non-option arguments as arrays. So
$(_systemctl_get_template_names) expands to some words that aren't
legal array names. Even if there were, they would be empty; thus adding
nothing.

deduplicated a few functions too.
---
 shell-completion/zsh/_systemctl.in | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 8764e07..f30fb84 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -166,9 +166,7 @@ _systemctl_restartable_units(){
 }
 
 _systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units 
--failed | { while read -r a b; do echo -E - " $a"; done; }) )}
-_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; 
}) )}
-_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; 
}) )}
-_systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) 
)}
+_systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( 
$(__systemctl list-unit-files) ) }
 
 local fun
 # Completion functions for ALL_UNITS
@@ -183,22 +181,21 @@ done
 # Completion functions for ENABLED_UNITS
 (( $+functions[_systemctl_disable] )) || _systemctl_disable()
 {
-_systemctl_enabled_units
-compadd "$@" -a - _sys_enabled_units
+local _sys_unit_state; _systemctl_unit_state
+compadd "$@" - ${(k)_sys_unit_state[(R)enabled]}
 }
 
 (( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
 {
-_systemctl_enabled_units
-_systemctl_disabled_units
-compadd "$@" -a - _sys_enabled_units _sys_disabled_units 
$(_systemctl_get_template_names)
+local _sys_unit_state; _systemctl_unit_state
+compadd "$@" - ${(k)_sys_unit_state[(R)(enabled|disabled)]} 
$(_systemctl_get_template_names)
 }
 
 # Completion functions for DISABLED_UNITS
 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
 {
-  _systemctl_disabled_units
-  compadd "$@" -a - _sys_disabled_units $(_systemctl_get_template_names)
+  local _sys_unit_state; _systemctl_unit_state
+  compadd "$@" - ${(k)_sys_unit_state[(R)disabled]} 
$(_systemctl_get_template_names)
 }
 
 # Completion functions for FAILED_UNITS
@@ -255,8 +252,8 @@ done
 # Completion functions for MASKED_UNITS
 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
 {
-  _systemctl_masked_units
-  compadd "$@" -a - _sys_masked_units || _message "no masked units found"
+  local _sys_unit_state; _systemctl_unit_state
+  compadd "$@" - ${(k)_sys_unit_state[(R)masked]} || _message "no masked units 
found"
 }
 
 # Completion functions for JOBS
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 5/6] zsh-completion: removing more pointless forks

2015-05-17 Thread Eric Cook
---
 shell-completion/zsh/_systemctl.in | 28 +---
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index a4db563..d2ebab0 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -105,7 +105,7 @@ _systemctl_all_units()
   if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
 ! _retrieve_cache SYS_ALL_UNITS;
   then
-_sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do 
echo -E - " $a"; done; }) )
+_sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} )
 _store_cache SYS_ALL_UNITS _sys_all_units
   fi
 }
@@ -118,7 +118,7 @@ _systemctl_really_all_units()
   if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid 
SYS_REALLY_ALL_UNITS ) &&
 ! _retrieve_cache SYS_REALLY_ALL_UNITS;
   then
-all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do 
echo -E - " $a"; done; }) )
+all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} )
 _systemctl_all_units
 really_all_units=($_sys_all_units $all_unit_files)
 _sys_really_all_units=(${(u)really_all_units})
@@ -259,22 +259,22 @@ done
 # Completion functions for JOBS
 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
 {
-  compadd "$@" - $(__systemctl list-jobs \
-| cut -d' ' -f1  2>/dev/null ) || _message "no jobs found"
+  compadd "$@" - ${${(f)"$(__systemctl list-jobs)"}%% *} ||
+_message "no jobs found"
 }
 
 # Completion functions for SNAPSHOTS
 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
 {
-  compadd "$@" - $(__systemctl list-units --type snapshot --all \
-| cut -d' ' -f1  2>/dev/null ) || _message "no snapshots found"
+  compadd "$@" - ${${(f)"$(__systemctl list-units --type snapshot --all)"}%% 
*} ||
+_message "no snapshots found"
 }
 
 # Completion functions for TARGETS
 (( $+functions[_systemctl_set-default] )) || _systemctl_set-default()
 {
-  compadd "$@" - $(__systemctl list-unit-files --type target --all \
-| cut -d' ' -f1  2>/dev/null ) || _message "no targets found"
+  compadd "$@" - ${${(f)"$(__systemctl list-unit-files --type target 
--all)"}%% *} ||
+_message "no targets found"
 }
 
 # Completion functions for ENVS
@@ -287,8 +287,7 @@ for fun in set-environment unset-environment ; do
   suf='-S='
 fi
 
-compadd "$@" ${suf} - $(systemctl show-environment \
-  | while read line; do echo " ${line%%\=}";done )
+compadd "$@" ${suf} - ${${(f)"$(systemctl show-environment)"}%%=*}
   }
 done
 
@@ -315,7 +314,7 @@ _systemctl_caching_policy()
   oldcache=( "$1"(mh+1) )
   (( $#oldcache )) && return 0
 
-  _sysunits=($(__systemctl --all | cut -d' ' -f1))
+  _sysunits=(${${(f)"$(__systemctl --all)"}%% *})
 
   if (( $#_sysunits )); then
 for unit in $_sysunits; do
@@ -342,10 +341,9 @@ _unit_properties() {
   if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid 
SYS_ALL_PROPERTIES ) &&
 ! _retrieve_cache SYS_ALL_PROPERTIES;
   then
-_sys_all_properties=( $( {__systemctl show --all;
-   @rootlibexecdir@/systemd --dump-configuration-items; } | {
-   while IFS='=' read -r a b; do [ -n "$b" ] && echo "$a"; done
-}) )
+_sys_all_properties=( ${${(M)${(f)"$(__systemctl show --all;
+@rootlibexecdir@/systemd 
--dump-configuration-items)"}##[[:alnum:]]##=*}%%=*}
+)
 _store_cache SYS_ALL_PROPRTIES _sys_all_properties
   fi
   _values -s , "${_sys_all_properties[@]}"
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 6/6] zsh-completion: make the arrays _sys_active_units, _sys_startable_units and _sys_restartable_units local to the completer.

2015-05-17 Thread Eric Cook
---
 shell-completion/zsh/_systemctl.in | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index d2ebab0..9b7f962 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -208,7 +208,7 @@ done
 # Completion functions for STARTABLE_UNITS
 (( $+functions[_systemctl_start] )) || _systemctl_start()
 {
-   _systemctl_startable_units
+   local _sys_startable_units; _systemctl_startable_units
compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
 }
 
@@ -216,7 +216,7 @@ done
 for fun in stop kill try-restart condrestart ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
-_systemctl_active_units
+local _sys_active_units; _systemctl_active_units
 compadd "$@" - $( _filter_units_by_property CanStop yes \
   ${_sys_active_units[*]} )
   }
@@ -234,7 +234,7 @@ done
 for fun in reload reload-or-try-restart force-reload ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
-_systemctl_active_units
+local _sys_active_units; _systemctl_active_units
 compadd "$@" - $( _filter_units_by_property CanReload yes \
   ${_sys_active_units[*]} )
   }
@@ -244,7 +244,7 @@ done
 for fun in restart reload-or-restart ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
-_systemctl_restartable_units
+local _sys_restartable_units; _systemctl_restartable_units
 compadd "$@" - ${_sys_restartable_units[*]} 
$(_systemctl_get_template_names)
   }
 done
-- 
2.1.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] shell-completion(zsh): journalctl's -b changes

2014-09-27 Thread Eric Cook
removed pointless index sort of bootids.
use `compadd -a' to add each array, instead of expanding possibly hundreds of 
words needlessly.
optional completion of -b

---
 shell-completion/zsh/_journalctl | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/shell-completion/zsh/_journalctl b/shell-completion/zsh/_journalctl
index 0d16a26..a469bbc 100644
--- a/shell-completion/zsh/_journalctl
+++ b/shell-completion/zsh/_journalctl
@@ -41,11 +41,11 @@ _journal_fields() {
 
 _journal_boots() {
   local -a _bootid _previousboots
-  _bootid=( ${(fao)"$(_call_program bootid "$service -F _BOOT_ID")"}  )
+  _bootid=( ${(f)"$(_call_program bootid "$service -F _BOOT_ID")"}  )
   _previousboots=( -{1..${#_bootid}} )
   _alternative : \
-"offsets:boot offsets:(${_previousboots[1,-2]})" \
-"bootid:boot ids:(${_bootid[@]})"
+"offsets:boot offsets:compadd -a '_previousboots[1,-2]'" \
+"bootid:boot ids:compadd -a _bootid"
 }
 
 _arguments -s \
@@ -63,7 +63,7 @@ _arguments -s \
 {-x,--catalog}'[Show explanatory texts with each log line]' \
 {-q,--quiet}"[Don't show privilege warning]" \
 {-m,--merge}'[Show entries from all available journals]' \
-{-b+,--boot=}'[Show data only from the specified boot or offset]:boot id 
or offset:_journal_boots' \
+{-b+,--boot=}'[Show data only from the specified boot or offset]::boot id 
or offset:_journal_boots' \
 '--list-boots[List boots ordered by time]' \
 {-k,--dmesg}'[Show only kernel messages from the current boot]' \
 {-u+,--unit=}'[Show data only from the specified 
unit]:units:_journal_fields _SYSTEMD_UNIT' \
-- 
2.1.1

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v2] shell-completion: prevent mangling unit names (bash)

2014-07-27 Thread Eric Cook
This fixes the issue noted by Zbigniew in most cases.
if a unit's name is enclosed in single quotes completion still
will not happen after the first `\'.
---
 shell-completion/bash/systemctl.in | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/shell-completion/bash/systemctl.in 
b/shell-completion/bash/systemctl.in
index 69ef04b..64b15df 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -158,20 +158,25 @@ _systemctl () {
 
 elif __contains_word "$verb" ${VERBS[ALL_UNITS]}; then
 comps=$( __get_all_units $mode )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[ENABLED_UNITS]}; then
 comps=$( __get_enabled_units $mode )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[DISABLED_UNITS]}; then
 comps=$( __get_disabled_units $mode )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[REENABLABLE_UNITS]}; then
 comps=$( __get_disabled_units $mode;
  __get_enabled_units $mode )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
 comps=$( __filter_units_by_property $mode CanStart yes \
   $( __get_startable_units $mode))
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
 comps=$( __filter_units_by_property $mode CanStart yes \
@@ -179,24 +184,30 @@ _systemctl () {
 | while read -r line; do \
 [[ "$line" =~ 
\.(device|snapshot|socket|timer)$ ]] || echo " $line"; \
 done ))
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
 comps=$( __filter_units_by_property $mode CanStop yes \
   $( __get_active_units $mode ) )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[RELOADABLE_UNITS]}; then
 comps=$( __filter_units_by_property $mode CanReload yes \
   $( __get_active_units $mode ) )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[ISOLATABLE_UNITS]}; then
 comps=$( __filter_units_by_property $mode AllowIsolate yes \
   $( __get_all_units $mode ) )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[FAILED_UNITS]}; then
 comps=$( __get_failed_units $mode )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[MASKED_UNITS]}; then
 comps=$( __get_masked_units $mode )
+compopt -o filenames
 
 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[NAME]}; then
 comps=''
@@ -221,7 +232,7 @@ _systemctl () {
 | { while read -r a b; do echo " $a"; done; } )
 fi
 
-COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
 return 0
 }
 
-- 
2.0.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] shell-completion: prevent mangling unit names (bash)

2014-07-26 Thread Eric Cook
On 07/26/2014 07:52 PM, Zbigniew Jędrzejewski-Szmek wrote:
> Unfortunately it works only partially. It seems that completions are generated
> properly, but bash doesn't seem to be able to continue after a backslash,
> so one has to copy in the remaining part by hand.
>
> Zbyszek
Hm... (I think)Once we add our own `\' to escape the unit name, the
compgen tests fails to match units. (lines 116, 121 and 225)
That can be avoided in a hack-ish way by escaping `cur' with
`cur=${cur//\\/}' but when completing the unit like 'dev- (with
the quote) the additional `\' are still inserted.

So... i'll look more into it, i may be over thinking it. :D
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] shell-completion: prevent mangling unit names (bash)

2014-07-26 Thread Eric Cook
This looks seems like it should work. I would appreciate it if you could trail 
run it.
My use of bash is limited and knowledge of it's completion system even more so.
---
 shell-completion/bash/systemctl.in | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/shell-completion/bash/systemctl.in 
b/shell-completion/bash/systemctl.in
index c5950cc..113694f 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -46,25 +46,25 @@ __filter_units_by_property () {
 <(__systemctl $mode show --property "$property" -- "${units[@]}")
 for ((i=0; $i < ${#units[*]}; i++)); do
 if [[ "${props[i]}" = "$property=$value" ]]; then
-echo " ${units[i]}"
+printf '%q\n' " ${units[i]}"
 fi
 done
 }
 
 __get_all_units  () { __systemctl $1 list-units --all \
-| { while read -r a b; do echo " $a"; done; }; }
+| { while read -r a b; do printf '%q\n' " $a"; done; }; }
 __get_active_units   () { __systemctl $1 list-units   \
-| { while read -r a b; do echo " $a"; done; }; }
+| { while read -r a b; do printf '%q\n' " $a"; done; }; }
 __get_startable_units () { __systemctl $1 list-units --all -t 
service,timer,socket,mount,automount,path,snapshot,swap \
-| { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] 
&& echo " $a"; done; }; }
+| { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] 
&& printf '%q\n' " $a"; done; }; }
 __get_failed_units   () { __systemctl $1 list-units   \
-| { while read -r a b c d; do [[ $c == "failed"   ]] && echo " $a"; 
done; }; }
+| { while read -r a b c d; do [[ $c == "failed"   ]] && printf '%q\n' 
" $a"; done; }; }
 __get_enabled_units  () { __systemctl $1 list-unit-files  \
-| { while read -r a b c  ; do [[ $b == "enabled"  ]] && echo " $a"; 
done; }; }
+| { while read -r a b c  ; do [[ $b == "enabled"  ]] && printf '%q\n' 
" $a"; done; }; }
 __get_disabled_units () { __systemctl $1 list-unit-files  \
-| { while read -r a b c  ; do [[ $b == "disabled" ]] && echo " $a"; 
done; }; }
+| { while read -r a b c  ; do [[ $b == "disabled" ]] && printf '%q\n' 
" $a"; done; }; }
 __get_masked_units   () { __systemctl $1 list-unit-files  \
-| { while read -r a b c  ; do [[ $b == "masked"   ]] && echo " $a"; 
done; }; }
+| { while read -r a b c  ; do [[ $b == "masked"   ]] && printf '%q\n' 
" $a"; done; }; }
 
 _systemctl () {
 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-- 
2.0.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] shell-completion: prevent mangling unit names

2014-07-26 Thread Eric Cook
Units with literal hex '\xFF' in their names has to be read
and printed properly.
dev-disk-byx2dlabel-root.device != dev-disk-by\x2dlabel-root.device
---
 shell-completion/zsh/_systemctl.in | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index d364d17..e681ec6 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -100,7 +100,7 @@ _systemctl_all_units()
   if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
 ! _retrieve_cache SYS_ALL_UNITS;
   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 -r a b; do 
echo -E - " $a"; done; }) )
 _store_cache SYS_ALL_UNITS _sys_all_units
   fi
 }
@@ -113,7 +113,7 @@ _systemctl_really_all_units()
   if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid 
SYS_REALLY_ALL_UNITS ) &&
 ! _retrieve_cache SYS_REALLY_ALL_UNITS;
   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 -r a b; do 
echo -E - " $a"; done; }) )
 _systemctl_all_units
 really_all_units=($_sys_all_units $all_unit_files)
 _sys_really_all_units=(${(u)really_all_units})
@@ -138,12 +138,12 @@ _filter_units_by_property() {
   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" || $c == "failed" ]] && 
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_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_active_units()  {_sys_active_units=(  $(__systemctl list-units  
| { while read -r a b; do echo -E - " $a"; done; }) )}
+_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units 
--all| { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] 
&& echo -E - " $a"; done; }) )}
+_systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units 
--failed | { while read -r a b; do echo -E - " $a"; done; }) )}
+_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; 
}) )}
+_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; 
}) )}
+_systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files 
| { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) 
)}
 
 # Completion functions for ALL_UNITS
 for fun in is-active is-failed is-enabled status show cat mask preset help 
list-dependencies ; do
@@ -219,8 +219,8 @@ for fun in restart reload-or-restart ; do
   {
 _systemctl_all_units
 compadd "$@" - $( _filter_units_by_property CanStart yes \
-  ${_sys_all_units[*]} | while read line; do \
-  [[ "$line" =~ \.device$ ]] || echo " $line"; \
+  ${_sys_all_units[*]} | while read -r line; do \
+  [[ "$line" =~ \.device$ ]] || echo -E - " $line"; \
   done )
   }
 done
-- 
2.0.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel