Skip to content

Instantly share code, notes, and snippets.

@balki
Created October 18, 2022 16:43
Show Gist options
  • Save balki/f07deef358400427788fa58740a8ef22 to your computer and use it in GitHub Desktop.
Save balki/f07deef358400427788fa58740a8ef22 to your computer and use it in GitHub Desktop.
Get Systemd directive help
#!/usr/bin/bash
# Usage:
# systemd-search.sh WorkingDirectory
word=$1
get_doc() {
exec {awkfd}<<AWKS
/^ ((${word}=(, [A-Z])?)|(([^ ]+=, )+${word}=))/ , /^[^ ]/ {
if(headerLineDone) {
if (/^ [^ ]+=/)
exit
} else {
if (/^ /)
headerLineDone = 1
}
print;
}
AWKS
awk -f /dev/fd/$awkfd | grep -v "^[^ ]" | sed 's/^ //'
exec {awkfd}>&-
}
COLUMNS=1000 man systemd.directives 2>/dev/null |
awk /^UNIT/,/^OPT/ |
grep -A1 -- " $word" |
sed -n 2p |
tr ',' '\n' |
sed 's/ //g' |
sed 's/.5.//g' |
while read -r manf
do
echo "<=== $manf ===>"
man "$manf" 2>/dev/null | get_doc
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment