X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=shell%2Fbin%2Fsc;fp=shell%2Fbin%2Fsc;h=506e90adc99ee29db12ae38aee44cecff4a7f89a;hb=29fe133e2b4ca2a25342fa9a4c3e661bc38895f2;hp=0000000000000000000000000000000000000000;hpb=3e17e82d591782b4750382b00c5bf6ee96eddedf;p=config%2Fdotfiles.git diff --git a/shell/bin/sc b/shell/bin/sc new file mode 100755 index 0000000..506e90a --- /dev/null +++ b/shell/bin/sc @@ -0,0 +1,53 @@ +#!/bin/bash + +# Small wrapper for systemctl which provides some shortcuts. + +# Copyright (C) 2015 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[@]}"