;;
--unit|-u)
comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
+ compopt -o filenames
;;
--user-unit)
comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
return 0
;;
esac
- COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
return 0
fi
_systemctl () {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
+ local cur_orig=$cur
local i verb comps mode
local -A OPTS=(
fi
done
+ # When trying to match a unit name with certain special characters in its name (i.e
+ # foo\x2dbar:01) they get escaped by bash along the way, thus causing any possible
+ # match to fail. Let's unescape such characters in the verb we're trying to
+ # autocomplete to avoid this, however, use the original verb (cur_orig)
+ # during the final match (COMPREPLY)
+ cur="$(echo $cur | xargs echo)"
+
if [[ -z $verb ]]; then
comps="${VERBS[*]}"
| { while read -r a b; do echo " $a"; done; } )
fi
- COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
+ COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") )
return 0
}