Skip to content

Commit 915b3fd

Browse files
committed
Better systemd. The old aliases are now functions, and they are much more useful. Added a template local@... systemd unit file, which is useful for autostarting things as root.
1 parent 387dd4e commit 915b3fd

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

.bashrc

+19-7
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ alias lr="ls -AR1 -I .git|awk '/:$/{gsub(/[^\/]+\//,\"--\",\$0);printf(\"%d file
8181
alias bell="printf '\a'" # either echo -ne '\007' or printf '\a'" or tput bel
8282
alias h="history"
8383
alias hc="history -c"
84-
alias sc="systemctl"
85-
alias jc="journalctl"
86-
alias scs="systemctl status"
87-
alias sc0="systemctl stop"
88-
alias sc1="systemctl start"
89-
alias scr="systemctl restart"
9084
alias psql="INPUTRC=/dev/fd/9 psql 9<<<'set editing-mode vi'";
9185
alias mysql='INPUTRC=/dev/fd/9 mysql 9<<<'\''set editing-mode vi'\'''
9286
# This is getting even uglier, but must have on remote machines
@@ -95,6 +89,25 @@ alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s
9589
alias gs="git status -sb";
9690
alias json="python -mjson.tool"
9791
alias tmux="tmux -2"
92+
93+
# Better systemd. We use $SCS to store the unit we're working on, so no need for typing or history athletics.
94+
# self-reload, because systemd can't do it on its own...
95+
sdr() { systemctl daemon-reload ; }
96+
# `sc` is like systemctl, but stores last param in $SCS.
97+
sc() { SCS="${@: -1}" ; systemctl "$@" ; }
98+
# STATUS, full lines
99+
scs() { SCS="${1:-${SCS}}" ; systemctl status -l "$SCS" ; }
100+
# STOP, but shows a status afterwards
101+
sc0() { SCS="${1:-${SCS}}" ; systemctl stop "$SCS" ; scs ; }
102+
# START, but shows a status afterwards, and tails the log
103+
sc1() { SCS="${1:-${SCS}}" ; sdr ; journalctl -n 0 -xfu "$SCS" & systemctl start "$SCS" ; scs ; fg ; }
104+
# RELOAD, but shows a status afterwards, and tails the log
105+
scr() { SCS="${1:-${SCS}}" ; sdr ; journalctl -n 0 -xfu "$SCS" & systemctl reload-or-restart "$SCS" ; scs ; fg ; }
106+
# LOG in pager, extended info, jump to end
107+
jc() { SCS="${1:-${SCS}}" ; journalctl -xeu "$SCS" ; }
108+
# LOG "tail -f". Tries to fill the screen.
109+
jcf() { SCS="${1:-${SCS}}" ; journalctl -n "${LINES:-45}" -xefu "$SCS" ; }
110+
98111
# Only if not on busybox
99112
[ -L $(type -p grep) ] || alias grep="grep --color"
100113
[ -L $(type -p less) ] || alias less="less -X" # No alt screen
@@ -111,7 +124,6 @@ fi
111124
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion # OS X
112125
if type _completion_loader 2>/dev/null >/dev/null; then _completion_loader systemctl; _completion_loader journalctl; fi
113126
complete -F _systemctl sc
114-
complete -F _journalctl jc
115127
complete -F _ssh sssh
116128

117129
# Poor man's history expansion (which bash doesn't do on TAB)

other/systemd.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cat >/etc/systemd/system/local@.service <<"EOF"
2+
3+
[Unit]
4+
Description=Systemd unit for /root/start-%i.sh
5+
After=network-online.target
6+
# FIX: prevent systemd giving up if service exits (also fixes problems with too quick manual restarts)
7+
StartLimitInterval=0
8+
9+
[Service]
10+
# FIX: because older systemd din't allow %i in the first word
11+
ExecStart=/usr/bin/time /root/start-%i.sh
12+
Restart=always
13+
RestartSec=5
14+
15+
[Install]
16+
WantedBy=multi-user.target
17+
18+
EOF
19+
20+
systemctl daemon-reload
21+
22+
#systemctl start local@...
23+
#systemctl enable local@...

tmux-inject-bash.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
HISTCONTROL=ignoreboth
2-
set -o vi;unset -f command_not_found_handle;unset HISTFILE;HISTTIMEFORMAT="%F %T ";PS1='\[\033[00;'$([[ `id -u` -eq 0 ]]&&echo -n 31||echo -n 34)'m\]\u\[\033[00m\]@\[\033[00;32m\]\h \[\033[00;33m\]\w \[\033[00;36m\][\j]\[\033[00m\]\$ ';export PROMPT_COMMAND="printf '\a'";export EDITOR=vim;export PAGER=less;export LC_ALL="en_US.UTF-8";export LANG="en_US.UTF-8";export CLICOLOR=1;export LSCOLORS=ExFxCxDxBxegedabagacad;export LS_COLORS="di=1;34:ln=1;35:so=1;32:pi=1;33:ex=1;31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43";export QUOTING_STYLE=shell-escape;export VIMINIT=":set nobackup noswapfile encoding=utf8 viminfo=";alias vim="vim -n -i NONE";export LESSHISTFILE=/dev/null;alias s="screen -xR";alias l="ls -lrt";alias la="ls -lrtA -I*";alias ll="ls -lhSr";alias lr="ls -AR1 -I .git|awk '/:$/{gsub(/[^\/]+\//,\"--\",\$0);printf(\"%d files\n%s \t\",p-2,\$0);p=0}{p++}END{print p \" files\"}'|less -FX";alias h="history";alias hc="history -c";alias sc="systemctl";alias jc="journalctl";alias scs="systemctl status";alias sc0="systemctl stop";alias sc1="systemctl start";alias scr="systemctl restart";alias psql="INPUTRC=/dev/fd/9 psql 9<<<'set editing-mode vi'";alias mysql="INPUTRC=/dev/fd/9 mysql 9<<<'set editing-mode vi'";alias tig='TIGRC_USER=/dev/fd/9 tig 9<<<"set main-options = --all${IFS}set main-view = line-number:no,interval=5 id:yes date:relative author:abbreviated commit-title:yes,graph,refs,overflow=no"';alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(cyan)<%an>%Creset' --abbrev-commit --date=relative --all --date-order";alias gs="git status -sb";[ -L $(type -p grep) ] || alias grep="grep --color";[ -L $(type -p less) ] || alias less="less -X";[ -f /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion;[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion;if type _completion_loader 2>/dev/null >/dev/null; then _completion_loader systemctl; _completion_loader journalctl; fi;complete -F _systemctl sc;complete -F _journalctl jc;shopt -s globstar cdspell dirspell checkwinsize;bind 'TAB:menu-complete';bind '"\e[Z": menu-complete-backward';bind 'set menu-complete-display-prefix on';bind 'set show-all-if-ambiguous on';bind 'set completion-ignore-case on';bind 'set match-hidden-files off';bind 'set colored-stats on';bind 'set visible-stats on';bind 'set completion-prefix-display-length 1';bind 'set skip-completed-text on';bind 'set history-preserve-point on';bind 'space:magic-space';bind -m vi '"\200":previous-history';bind -m vi '"\201":next-history';bind -m vi '"\202":end-of-line';bind -m vi 'k:"\200\202"';bind -m vi 'j:"\201\202"';bind -m vi '"\e[A":"\200\202"';bind -m vi '"\e[B":"\201\202"';bind -m vi-insert '"\e[A":history-search-backward';bind -m vi-insert '"\e[B":history-search-forward';bind -m vi-insert "\C-l":clear-screen;compopt -o bashdefault cd;type -p screen >/dev/null && screen -ls; echo $SSH_AUTH_SOCK
2+
set -o vi;unset -f command_not_found_handle;unset HISTFILE;HISTTIMEFORMAT="%F %T ";PS1='\[\033[00;'$([[ `id -u` -eq 0 ]]&&echo -n 31||echo -n 34)'m\]\u\[\033[00m\]@\[\033[00;32m\]\h \[\033[00;33m\]\w \[\033[00;36m\][\j]\[\033[00m\]\$ ';export PROMPT_COMMAND="printf '\a'";export EDITOR=vim;export PAGER=less;export LC_ALL="en_US.UTF-8";export LANG="en_US.UTF-8";export CLICOLOR=1;export LSCOLORS=ExFxCxDxBxegedabagacad;export LS_COLORS="di=1;34:ln=1;35:so=1;32:pi=1;33:ex=1;31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43";export QUOTING_STYLE=shell-escape;export VIMINIT=":set nobackup noswapfile encoding=utf8 viminfo=";alias vim="vim -n -i NONE";export LESSHISTFILE=/dev/null;alias s="screen -xR";alias l="ls -lrt";alias la="ls -lrtA -I*";alias ll="ls -lhSr";alias lr="ls -AR1 -I .git|awk '/:$/{gsub(/[^\/]+\//,\"--\",\$0);printf(\"%d files\n%s \t\",p-2,\$0);p=0}{p++}END{print p \" files\"}'|less -FX";alias h="history";alias hc="history -c";alias mysql="INPUTRC=/dev/fd/9 mysql 9<<<'set editing-mode vi'";alias tig='TIGRC_USER=/dev/fd/9 tig 9<<<"set main-options = --all${IFS}set main-view = line-number:no,interval=5 id:yes date:relative author:abbreviated commit-title:yes,graph,refs,overflow=no"';alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(cyan)<%an>%Creset' --abbrev-commit --date=relative --all --date-order";alias gs="git status -sb";sdr() { systemctl daemon-reload ; };sc() { SCS="${@: -1}" ; systemctl "$@" ; };scs() { SCS="${1:-${SCS}}" ; systemctl status -l "$SCS" ; };sc0() { SCS="${1:-${SCS}}" ; systemctl stop "$SCS" ; scs ; };sc1() { SCS="${1:-${SCS}}" ; sdr ; journalctl -n 0 -xfu "$SCS" & systemctl start "$SCS" ; scs ; fg ; };scr() { SCS="${1:-${SCS}}" ; sdr ; journalctl -n 0 -xfu "$SCS" & systemctl reload-or-restart "$SCS" ; scs ; fg ; };jc() { SCS="${1:-${SCS}}" ; journalctl -xeu "$SCS" ; };jcf() { SCS="${1:-${SCS}}" ; journalctl -n "${LINES:-45}" -xefu "$SCS" ; };alias psql="INPUTRC=/dev/fd/9 psql 9<<<'set editing-mode vi'";[ -L $(type -p grep) ] || alias grep="grep --color";[ -L $(type -p less) ] || alias less="less -X";[ -f /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion;[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion;if type _completion_loader 2>/dev/null >/dev/null; then _completion_loader systemctl; _completion_loader journalctl; fi;complete -F _systemctl sc;shopt -s globstar cdspell dirspell checkwinsize;bind 'TAB:menu-complete';bind '"\e[Z": menu-complete-backward';bind 'set menu-complete-display-prefix on';bind 'set show-all-if-ambiguous on';bind 'set completion-ignore-case on';bind 'set match-hidden-files off';bind 'set colored-stats on';bind 'set visible-stats on';bind 'set completion-prefix-display-length 1';bind 'set skip-completed-text on';bind 'set history-preserve-point on';bind 'space:magic-space';bind -m vi '"\200":previous-history';bind -m vi '"\201":next-history';bind -m vi '"\202":end-of-line';bind -m vi 'k:"\200\202"';bind -m vi 'j:"\201\202"';bind -m vi '"\e[A":"\200\202"';bind -m vi '"\e[B":"\201\202"';bind -m vi-insert '"\e[A":history-search-backward';bind -m vi-insert '"\e[B":history-search-forward';bind -m vi-insert "\C-l":clear-screen;compopt -o bashdefault cd;type -p screen >/dev/null && screen -ls; echo $SSH_AUTH_SOCK

0 commit comments

Comments
 (0)