dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
Michal Schmidt bbee01
From 74eeab044e506a39786f484b160d9f64d48ad243 Mon Sep 17 00:00:00 2001
Michal Schmidt bbee01
From: Dave Reisner <d@falconindy.com>
Michal Schmidt bbee01
Date: Tue, 11 Oct 2011 20:56:53 -0400
Michal Schmidt bbee01
Subject: [PATCH 5/5] systemctl-completion: always invoke with --no-legend
Michal Schmidt bbee01
Michal Schmidt bbee01
In the case of completion for the 'restart' verb, passing the invalid
Michal Schmidt bbee01
unit name (the colums header) causes completion to cease functioning
Michal Schmidt bbee01
entirely, with the error:
Michal Schmidt bbee01
Michal Schmidt bbee01
  Failed to issue method call: Unit name UNIT is not valid.
Michal Schmidt bbee01
Michal Schmidt bbee01
This adds a small wrapper function for systemctl which can have common
Michal Schmidt bbee01
options added to it.
Michal Schmidt bbee01
---
Michal Schmidt bbee01
 src/systemctl-bash-completion.sh |   20 ++++++++++++--------
Michal Schmidt bbee01
 1 files changed, 12 insertions(+), 8 deletions(-)
Michal Schmidt bbee01
Michal Schmidt bbee01
diff --git a/src/systemctl-bash-completion.sh b/src/systemctl-bash-completion.sh
Michal Schmidt bbee01
index 6369a6c..6ebb792 100644
Michal Schmidt bbee01
--- a/src/systemctl-bash-completion.sh
Michal Schmidt bbee01
+++ b/src/systemctl-bash-completion.sh
Michal Schmidt bbee01
@@ -15,6 +15,10 @@
Michal Schmidt bbee01
 # You should have received a copy of the GNU General Public License
Michal Schmidt bbee01
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
Michal Schmidt bbee01
 
Michal Schmidt bbee01
+__systemctl() {
Michal Schmidt bbee01
+        systemctl --no-legend "$@"
Michal Schmidt bbee01
+}
Michal Schmidt bbee01
+
Michal Schmidt bbee01
 __contains_word () {
Michal Schmidt bbee01
         local word=$1; shift
Michal Schmidt bbee01
         for w in $*; do [[ $w = $word ]] && return 0; done
Michal Schmidt bbee01
@@ -24,7 +28,7 @@ __contains_word () {
Michal Schmidt bbee01
 __filter_units_by_property () {
Michal Schmidt bbee01
         local property=$1 value=$2 ; shift ; shift
Michal Schmidt bbee01
         local -a units=( $* )
Michal Schmidt bbee01
-        local -a props=( $(systemctl show --property "$property" -- ${units[*]} | grep -v ^$) )
Michal Schmidt bbee01
+        local -a props=( $(__systemctl show --property "$property" -- ${units[*]} | grep -v ^$) )
Michal Schmidt bbee01
         for ((i=0; $i < ${#units[*]}; i++)); do
Michal Schmidt bbee01
                 if [[ "${props[i]}" = "$property=$value" ]]; then
Michal Schmidt bbee01
                         echo "${units[i]}"
Michal Schmidt bbee01
@@ -32,10 +36,10 @@ __filter_units_by_property () {
Michal Schmidt bbee01
         done
Michal Schmidt bbee01
 }
Michal Schmidt bbee01
 
Michal Schmidt bbee01
-__get_all_units      () { systemctl list-units --full --all | awk '                 {print $1}' ; }
Michal Schmidt bbee01
-__get_active_units   () { systemctl list-units --full       | awk '                 {print $1}' ; }
Michal Schmidt bbee01
-__get_inactive_units () { systemctl list-units --full --all | awk '$3 == "inactive" {print $1}' ; }
Michal Schmidt bbee01
-__get_failed_units   () { systemctl list-units --full       | awk '$3 == "failed"   {print $1}' ; }
Michal Schmidt bbee01
+__get_all_units      () { __systemctl list-units --full --all | awk '                 {print $1}' ; }
Michal Schmidt bbee01
+__get_active_units   () { __systemctl list-units --full       | awk '                 {print $1}' ; }
Michal Schmidt bbee01
+__get_inactive_units () { __systemctl list-units --full --all | awk '$3 == "inactive" {print $1}' ; }
Michal Schmidt bbee01
+__get_failed_units   () { __systemctl list-units --full       | awk '$3 == "failed"   {print $1}' ; }
Michal Schmidt bbee01
 
Michal Schmidt bbee01
 _systemctl () {
Michal Schmidt bbee01
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
Michal Schmidt bbee01
@@ -134,13 +138,13 @@ _systemctl () {
Michal Schmidt bbee01
                 comps=''
Michal Schmidt bbee01
 
Michal Schmidt bbee01
         elif __contains_word "$verb" ${VERBS[JOBS]}; then
Michal Schmidt bbee01
-                comps=$( systemctl list-jobs | awk '{print $1}' )
Michal Schmidt bbee01
+                comps=$( __systemctl list-jobs | awk '{print $1}' )
Michal Schmidt bbee01
 
Michal Schmidt bbee01
         elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
Michal Schmidt bbee01
-                comps=$( systemctl list-units --type snapshot --full --all | awk '{print $1}' )
Michal Schmidt bbee01
+                comps=$( __systemctl list-units --type snapshot --full --all | awk '{print $1}' )
Michal Schmidt bbee01
 
Michal Schmidt bbee01
         elif __contains_word "$verb" ${VERBS[ENVS]}; then
Michal Schmidt bbee01
-                comps=$( systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' )
Michal Schmidt bbee01
+                comps=$( __systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' )
Michal Schmidt bbee01
                 compopt -o nospace
Michal Schmidt bbee01
         fi
Michal Schmidt bbee01
 
Michal Schmidt bbee01
-- 
Michal Schmidt bbee01
1.7.4.4
Michal Schmidt bbee01