Created
November 16, 2019 15:19
-
-
Save shunf4/0b98c457a942f6542af3e1b2871c2ce7 to your computer and use it in GitHub Desktop.
Shortcut for systemd-related operations(systemctl) on services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sc() { | |
| if [ -z "$1" ] || [ -z "$2" ]; then | |
| return | |
| fi | |
| case $2 in | |
| jf) sudo journalctl -fu $1;; | |
| j*) sudo journalctl -u $1;; | |
| ens) sudo systemctl enable $1 ; sudo systemctl start $1;; | |
| en*) sudo systemctl enable $1;; | |
| d*) sudo systemctl disable $1;; | |
| e) [ -f /etc/systemd/system/$1 ] && sudo vim /etc/systemd/system/$1 || sudo vim /etc/systemd/system/$1.service;; | |
| r) sudo systemctl daemon-reload; sudo systemctl reload $1 || sudo systemctl restart $1; sudo systemctl status $1;; | |
| sto*) sudo systemctl stop $1;; | |
| st*) sudo systemctl start $1;; | |
| s) sudo systemctl status $1;; | |
| esac | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _sc() { | |
| local cur prev svc_dirs tmp1 tmp2 | |
| cur="${COMP_WORDS[COMP_CWORD]}" | |
| prev="${COMP_WORDS[COMP_CWORD-1]}" | |
| if [ $COMP_CWORD != "1" ]; then | |
| return | |
| fi | |
| #svc_dirs=(/etc/systemd/system/* /lib/systemd/system/* /usr/lib/systemd/system/*) | |
| svc_dirs=(/etc/systemd/system/*) | |
| #echo "${svc_dirs[@]##*/}" | |
| tmp1=("${svc_dirs[@]##*/}") | |
| tmp2=( $(compgen -W "${tmp1[*]}" -- ${cur}) ) | |
| #echo $tmp2 | |
| COMPREPLY=( "${tmp2[@]// /\ }" ) | |
| #COMPREPLY=( "${COMPREPLY[@]/%/ }" ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment