#!/bin/bash # Small wrapper for systemctl which provides some shortcuts. # Copyright (C) 2015-2019 Simon Ruderich # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . set -eu args=( ) found= for arg; do # This heuristic replaces the first occurrence of a shortcut with its # expansion. This is not perfect (e.g. `systemctl status s` would result # in `systemctl status status`) but works even when options are used and # doesn't require us to duplicate systemctl's parsing of command line # arguments. if [[ -z $found ]]; then found=1 case "$arg" in c) arg=cat ;; d) arg=disable ;; e) arg=enable ;; k) arg=kill ;; m) arg=mask ;; r) arg=restart ;; rl) arg=reload ;; s) arg=status ;; sa) arg=start ;; so) arg=stop ;; u) arg=unmask ;; # No match, try it again for the next parameter. *) found= ;; esac fi args+=( "$arg" ) done set +u # empty $args causes an error, I think this is a bug in bash exec systemctl "${args[@]}" 2>&1