From 9a04e70e7776c4c17f31561eacdc94f530199df8 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Tue, 18 Aug 2020 12:49:31 +0100 Subject: [PATCH] systemd: default launch systemd apps in app.slice Unless specified, units will launch in `app.slice` under the assumption that they are foreground user applications. Update i3 configuration to remove redundant app.slice definition. Conform to unit naming of app-{name}-{random}.service as documented in https://github.com/systemd/systemd/blob/master/docs/DESKTOP_ENVIRONMENTS.md#pre-defined-systemd-units Signed-off-by: Joe Groocock --- i3/config | 22 +++++++++++----------- scripts/systemd-run-i3 | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/i3/config b/i3/config index 8c6d328..5a417e0 100644 --- a/i3/config +++ b/i3/config @@ -132,15 +132,15 @@ popup_during_fullscreen smart bindsym $mod+Shift+j reload bindsym --release $mod+x exec xkill bindsym $mod+c exec notify-send "Try again" "You meant \\\$mod+b" -bindsym $mod+b exec systemd-run-i3 -s app -c firefox -bindsym $mod+Return exec systemd-run-i3 -s app -n alacritty -bindsym $mod+Ctrl+Return exec systemd-run-i3 -s app -n alacritty --class floating -bindsym $mod+Shift+Return exec systemd-run-i3 -s app -n alacritty --working-directory "$(xcwd)" -bindsym $mod+Ctrl+Shift+Return exec systemd-run-i3 -s app -n alacritty --class floating --working-directory "$(xcwd)" -bindsym $mod+v exec systemd-run-i3 -s app -n alacritty -e sh -c "($SHELL -c $EDITOR || :) && $SHELL" -bindsym $mod+Ctrl+v exec systemd-run-i3 -s app -n alacritty --class floating -e sh -c "($SHELL -c $EDITOR || : ) && $SHELL" +bindsym $mod+b exec systemd-run-i3 -n firefox +bindsym $mod+Return exec systemd-run-i3 -n alacritty +bindsym $mod+Ctrl+Return exec systemd-run-i3 -n alacritty --class floating +bindsym $mod+Shift+Return exec systemd-run-i3 -n alacritty --working-directory "$(xcwd)" +bindsym $mod+Ctrl+Shift+Return exec systemd-run-i3 -n alacritty --class floating --working-directory "$(xcwd)" +bindsym $mod+v exec systemd-run-i3 -n alacritty -e sh -c "($SHELL -c $EDITOR || :) && $SHELL" +bindsym $mod+Ctrl+v exec systemd-run-i3 -n alacritty --class floating -e sh -c "($SHELL -c $EDITOR || : ) && $SHELL" bindsym $mod+l exec dm-tool switch-to-greeter -bindsym $mod+space exec "pkill rofi; rofi -show run -sidebar-mode -terminal i3-sensible-terminal -normal-window -run-command 'systemd-run-i3 -s app -n {cmd}'" +bindsym $mod+space exec "pkill rofi; rofi -show run -sidebar-mode -terminal i3-sensible-terminal -normal-window -run-command 'systemd-run-i3 -n {cmd}'" bindsym $mod+Shift+p exec rofi-pass --root $(grep path ~/.config/gopass/config.yml | sed -E 's|^.*fs\+file://||g' | tr '\n' ':') | sed 's/:$//g' bindsym $mod+Shift+e exec "pkill rofi; rofi -show emoji -modi emoji -normal-window" bindsym $mod+Shift+i exec rofi-fontawesome @@ -148,11 +148,11 @@ bindsym --release Print exec screenshot bindsym --release $mod+Print exec screenshot --clip bindsym --release Shift+Print exec screenshot --active bindsym --release $mod+Shift+Print exec screenshot --active --clip -bindsym $mod+Shift+x exec systemd-run-i3 -s app -n i3-sensible-terminal --class floating-term --hold -e /bin/echo "$(xprop -id $(xdotool getactivewindow))" +bindsym $mod+Shift+x exec systemd-run-i3 -n i3-sensible-terminal --class floating-term --hold -e /bin/echo "$(xprop -id $(xdotool getactivewindow))" bindsym $mod+$alt+space exec systemd-run-i3 -s background -n ~/.config/i3/cycleaudio.py && pkill -RTMIN+10 i3blocks -bindsym $mod+numbersign exec systemd-run-i3 -s app -n i3-sensible-terminal --hold -e sh -c 'xclip -o | gpg --decrypt 2>&1' +bindsym $mod+numbersign exec systemd-run-i3 -n i3-sensible-terminal --hold -e sh -c 'xclip -o | gpg --decrypt 2>&1' bindsym $mod+r exec bash -c 'pwgen -snc 32 1 | tee >(xargs notify-send Generated\ password\:) | xclip -i -r' -bindsym $mod+g exec systemd-run-i3 -s app -n notify-send -c transfer "$(gist -PRpc)" +bindsym $mod+g exec systemd-run-i3 -n notify-send -c transfer "$(gist -PRpc)" bindsym --release $mod+i exec systemd-run-i3 -s background -n sh -c 'sleep 0.5 && xdotool getactivewindow type --delay 250 "$(xclip -o -selection clipboard)"' # Media player controls diff --git a/scripts/systemd-run-i3 b/scripts/systemd-run-i3 index 169b1a8..3d9d214 100755 --- a/scripts/systemd-run-i3 +++ b/scripts/systemd-run-i3 @@ -1,12 +1,11 @@ #!/bin/bash -e -rand=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 16) +rand=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 8) args=() -while getopts "u:s:e:d:cnw" opt +while getopts "s:e:d:cnw" opt do case "$opt" in - u) args+=("--unit=$OPTARG-$rand");; - s) args+=("--slice=$OPTARG");; + s) slice="$OPTARG";; e) args+=("--setenv=$OPTARG");; d) args+=("--working-directory=$OPTARG");; c) args+=("--scope");; @@ -17,4 +16,13 @@ do case "$opt" in done shift $((OPTIND-1)) -exec systemd-run --user --collect --unit="$1-$rand" ${args[@]} -- "$@" +if [ -z "$slice" ]; then + slice=app +fi + +exec systemd-run \ + --user \ + --collect \ + --slice="$slice" \ + --unit="$slice-$1-$rand" \ + ${args[@]} -- "$@"